F #6053: In-place restore of VM backups (shared and ssh drivers)

This commit implements the in-place restore of VM backups. Selected VM disks will
be replaced with the specified backup:

* A new API call has been added to the XML-RPC API (`one.vm.restore`) with
  the following arguments:
    - VM ID to be restored, needs to be in **poweroff** state
    - IMAGE ID of the backup to restore
    - INCREMENT ID, only for incremental backups, the increment to use
      (defults to -1 to use the last increment available)
    - DISK ID of the disk to restore (defaults to -1 to restore all VM
      disks)

* Datastore drivers needs to implemente a new operation `ls`. This new
  operation takes the VM, image information of the backup and datastore
  information and returns the restore URL for the disks in the backup.

* This commit includes the implementation for qcow2 and ssh drivers,
  ceph will be implemented in a separated PR. The new driver action is
  `restore host:vm_dir vm_id img_id inc_id disk_id`

* The restore operation is performed in a new state `PROLOG_RESTORE`
  rendered as `RESTORE` and `rest` in short form. State in in RSuntone.

TODO:
  - Remove any existing VM snapshot (system/disk) in the VM. Note that
    snapshots are not included in a backup.

  - Ceph drivers

  - JAVA, GO Lang API bindings

  - Sunstone interface, new state and new operation. Review new state in
    RSuntone.

co-authored-by: Pavel Czerny <pczerny@opennebula.io>
This commit is contained in:
Ruben S. MonteroandPavel Czerny committed 2024-04-26 12:45:04 +02:00
1 parent 669cc6db5a
commit 3dfd53df1c
32 files changed
+1037 -60

No files matched your search

+84 -1
View File
@@ -22,6 +22,7 @@
#include "VirtualMachineDisk.h"
#include "VirtualMachinePool.h"
#include "LifeCycleManager.h"
#include "ImagePool.h"
using namespace std;
@@ -933,7 +934,7 @@ void TransferManager::epilog_transfer_command(
{
string save = disk->vector_value("SAVE");
int disk_id = disk->get_disk_id();
string tm_mad_system;
string tm_mad_system;
if ( one_util::toupper(save) == "YES" )
{
@@ -2235,6 +2236,88 @@ void TransferManager::trigger_resize(int vid)
});
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void TransferManager::trigger_prolog_restore(int vid, int img_id, int inc_id,
int disk_id)
{
trigger([this, vid, img_id, inc_id, disk_id]{
ostringstream oss;
ofstream xfr;
string xfr_name;
auto tm_md = get();
Nebula& nd = Nebula::instance();
unique_ptr<VirtualMachine> vm;
if (tm_md == nullptr)
{
goto error_driver;
}
vm = vmpool->get(vid);
if (!vm)
{
return;
}
if (!vm->hasHistory())
{
goto error_history;
}
xfr_name = vm->get_transfer_file() + ".prolog_restore";
xfr.open(xfr_name.c_str(), ios::out | ios::trunc);
if (xfr.fail() == true)
{
goto error_file;
}
//RESTORE tm_mad host:remote_dir vm_id img_id inc_id disk_id
xfr << "RESTORE" << " "
<< vm->get_tm_mad() << " "
<< vm->get_hostname() << ":" << vm->get_system_dir() << " "
<< vid << " "
<< img_id << " "
<< inc_id << " "
<< disk_id << " "
<< endl;
xfr.close();
{
transfer_msg_t msg(TransferManagerMessages::TRANSFER, "", vid, xfr_name);
tm_md->write(msg);
}
return;
error_driver:
oss << "prolog_restore, error getting TM driver.";
goto error_common;
error_history:
oss << "prolog_restore, the VM has no history";
goto error_common;
error_file:
oss << "prolog_restore, could not open file: " << xfr_name;
goto error_common;
error_common:
vm->log("TrM", Log::ERROR, oss);
nd.get_lcm()->trigger_disk_restore_failure(vm->get_oid());
return;
});
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
+8
View File
@@ -114,6 +114,10 @@ void TransferManager::_transfer(unique_ptr<transfer_msg_t> msg)
lcm->trigger_disk_resize_success(id);
break;
case VirtualMachine::PROLOG_RESTORE:
lcm->trigger_disk_restore_success(id);
break;
default:
goto error_state;
}
@@ -184,6 +188,10 @@ void TransferManager::_transfer(unique_ptr<transfer_msg_t> msg)
lcm->trigger_disk_resize_failure(id);
break;
case VirtualMachine::PROLOG_RESTORE:
lcm->trigger_disk_restore_failure(id);
break;
default:
goto error_state;
}