Skip to content

Commit

Permalink
F #6029: Force to re-use current datastore ID
Browse files Browse the repository at this point in the history
When doing incremental backups it MUST reuse the current datastore ID.
This commits forces this setting ignoring the API parameter in this case.

(cherry picked from commit 01c490a)
  • Loading branch information
rsmontero committed Feb 22, 2023
1 parent 7e09ceb commit f0c4091
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
6 changes: 1 addition & 5 deletions src/cli/onevm
Original file line number Diff line number Diff line change
Expand Up @@ -1573,11 +1573,7 @@ CommandParser::CmdParser.new(ARGV) do
OneVMHelper::YEARLY,
OneVMHelper::HOURLY,
OneVMHelper::END_TIME] do
if options[:datastore].nil?
STDERR.puts 'Datastore to save the backup is mandatory: '
STDERR.puts "\t -d datastore_id | name"
exit(-1)
end
options[:datastore] = -1 if options[:datastore].nil?

reset = options[:reset] == true

Expand Down
2 changes: 1 addition & 1 deletion src/oca/ruby/opennebula/virtual_machine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ def sched_action_update(sched_id, sched_template)
# @param ds_id [Integer] Id of the datastore to save the backup
# @return [Integer, OpenNebula::Error] ID of the resulting BACKUP image
# in case of success, Error otherwise.
def backup(ds_id, reset = false)
def backup(ds_id = -1, reset = false)
return @client.call(VM_METHODS[:backup], @pe_id, ds_id, reset)
end

Expand Down
29 changes: 28 additions & 1 deletion src/rm/RequestManagerVirtualMachine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3973,14 +3973,20 @@ void VirtualMachineBackup::request_execute(

Backups::Mode mode;
int li_id;
int bk_id = -1;

// ------------------------------------------------------------------------
// Get request parameters
// ------------------------------------------------------------------------
int vm_id = xmlrpc_c::value_int(paramList.getInt(1));
int backup_ds_id = xmlrpc_c::value_int(paramList.getInt(2));
int backup_ds_id = -1;
bool reset = false;

if ( paramList.size() > 2 )
{
backup_ds_id = xmlrpc_c::value_int(paramList.getInt(2));
}

if ( paramList.size() > 3 )
{
reset = xmlrpc_c::value_boolean(paramList.getBoolean(3));
Expand All @@ -3997,6 +4003,8 @@ void VirtualMachineBackup::request_execute(

mode = vm->backups().mode();
li_id = vm->backups().last_increment_id();

bk_id = vm->backups().incremental_backup_id();
}
else
{
Expand All @@ -4006,6 +4014,25 @@ void VirtualMachineBackup::request_execute(
return;
}

// Incremental backups use the current datastore if not resetting the chain
if ( mode == Backups::INCREMENT && !reset && li_id != -1 )
{
ImagePool* ipool = nd.get_ipool();

if (auto img = ipool->get_ro(bk_id))
{
backup_ds_id = img->get_ds_id();
}
else
{
att.resp_obj = PoolObjectSQL::IMAGE;
att.resp_id = bk_id;

failure_response(NO_EXISTS, att);
return;
}
}

if ( auto ds = dspool->get_ro(backup_ds_id) )
{
if (ds->get_type() != Datastore::BACKUP_DS)
Expand Down

0 comments on commit f0c4091

Please sign in to comment.