1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-05 09:17:41 +03:00

B #6505: Fix volatile disk backup (Ceph) (#3225)

* B #6505: follow-up fix for Ceph bk/restore (#3212)

Signed-off-by: Guillermo Ramos <gramos@opennebula.io>
Co-authored-by: Pavel Czerný <pczerny@opennebula.io>
This commit is contained in:
Guillemo Ramos 2024-09-20 12:04:15 +02:00 committed by GitHub
parent ffd0a09e7b
commit c8d28ad18f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 60 additions and 63 deletions

View File

@ -54,19 +54,10 @@ $LOAD_PATH << RUBY_LIB_LOCATION
require 'rexml/document'
require_relative '../lib/tm_action'
require_relative '../lib/ceph'
require_relative '../lib/kvm'
require_relative '../lib/datastore'
#-------------------------------------------------------------------------------
# Helper functions
#-------------------------------------------------------------------------------
def rbd_append(str, disk, name, opt)
opt_val = disk.elements[name].text
"#{str} #{opt} #{opt_val}" unless opt_val.empty?
rescue StandardError
str
end
#-------------------------------------------------------------------------------
# BACKUP tm_mad host:remote_dir DISK_ID:...:DISK_ID deploy_id bjid vmid dsid
#-------------------------------------------------------------------------------
@ -84,11 +75,11 @@ _dsid = ARGV[5]
rhost = dir[0]
rdir = dir[1]
xml_doc = REXML::Document.new(vm_xml)
vm = xml_doc.root
ds = TransferManager::Datastore.from_vm_backup_ds(:vm_xml => vm_xml)
action = TransferManager::Action.new(:action_name => 'prebackup',
:vm_id => vmid)
base_path = ENV['BACKUP_BASE_PATH']
bck_dir = if base_path
@ -97,27 +88,20 @@ bck_dir = if base_path
"#{rdir}/backup"
end
snap_cmd = ''
expo_cmd = ''
conv_cmd = ''
clup_cmd = ''
vm.elements.each 'TEMPLATE/DISK' do |d|
did = d.elements['DISK_ID'].text
next unless disks.include? did
ceph_disks = TransferManager::Ceph::Disk.from_vm(action.vm.template_xml)
ceph_disks.compact.each do |d|
did = d.id
next unless disks.include? did.to_s
src = d.elements['SOURCE'].text
clon = d.elements['CLONE'].text
rbd_src = if clon == 'NO'
src
else
"#{src}-#{vmid}-#{did}"
end
cmd = rbd_append('rbd', d, 'CEPH_USER', '--id')
cmd = rbd_append(cmd, d, 'CEPH_KEY', '--keyfile')
cmd = rbd_append(cmd, d, 'CEPH_CONF', '--conf')
rbd_src = d.rbd_image
cmd = d.rbd_cmd
# Full backup
draw = "#{bck_dir}/disk.#{did}.raw"
ddst = "#{bck_dir}/disk.#{did}.0"
@ -145,6 +129,11 @@ script = <<~EOS
echo "#{Base64.encode64(vm_xml)}" > #{bck_dir}/vm.xml
# --------------------------------
# Create Ceph snapshots for disks
# --------------------------------
#{snap_cmd}
# --------------------------
# export, convert & cleanup
# --------------------------
@ -155,10 +144,10 @@ script = <<~EOS
#{clup_cmd}
EOS
rc = TransferManager::Action.ssh('prebackup_live', :host => rhost,
:cmds => script,
:nostdout => false,
:nostderr => false)
rc = action.ssh(:host => rhost,
:cmds => script,
:nostdout => false,
:nostderr => false)
if rc.code != 0
STDERR.puts "Error preparing disk files: #{rc.stdout} #{rc.stderr}"

View File

@ -54,6 +54,7 @@ $LOAD_PATH << RUBY_LIB_LOCATION
require 'rexml/document'
require_relative '../lib/tm_action'
require_relative '../lib/ceph'
require_relative '../lib/kvm'
require_relative '../lib/datastore'
@ -92,6 +93,9 @@ vm = xml_doc.root
ds = TransferManager::Datastore.from_vm_backup_ds(:vm_xml => vm_xml)
action = TransferManager::Action.new(:action_name => 'prebackup_live',
:vm_id => vmid)
base_path = ENV['BACKUP_BASE_PATH']
bck_dir = if base_path
@ -105,22 +109,13 @@ expo_cmd = ''
conv_cmd = ''
clup_cmd = ''
vm.elements.each 'TEMPLATE/DISK' do |d|
did = d.elements['DISK_ID'].text
next unless disks.include? did
ceph_disks = TransferManager::Ceph::Disk.from_vm(action.vm.template_xml)
ceph_disks.compact.each do |d|
did = d.id
next unless disks.include? did.to_s
src = d.elements['SOURCE'].text
clon = d.elements['CLONE'].text
rbd_src = if clon == 'NO'
src
else
"#{src}-#{vmid}-#{did}"
end
cmd = rbd_append('rbd', d, 'CEPH_USER', '--id')
cmd = rbd_append(cmd, d, 'CEPH_KEY', '--keyfile')
cmd = rbd_append(cmd, d, 'CEPH_CONF', '--conf')
rbd_src = d.rbd_image
cmd = d.rbd_cmd
draw = "#{bck_dir}/disk.#{did}.raw"
ddst = "#{bck_dir}/disk.#{did}.0"
@ -173,10 +168,10 @@ script = <<~EOS
#{clup_cmd}
EOS
rc = TransferManager::Action.ssh('prebackup_live', :host => rhost,
:cmds => script,
:nostdout => false,
:nostderr => false)
rc = action.ssh(:host => rhost,
:cmds => script,
:nostdout => false,
:nostderr => false)
if rc.code != 0
STDERR.puts "Error preparing disk files: #{rc.stdout} #{rc.stderr}"

View File

@ -351,7 +351,7 @@ module TransferManager
d.delete('SIZE')
# CDROM keeps original image_id
next if type == 'CDROM'
next if ['CDROM', 'RBD_CDROM'].include?(type)
d['IMAGE_ID'] = bck_disks[id][:image_id].to_s
end

View File

@ -35,17 +35,25 @@ module TransferManager
def initialize(vmid, disk_xml)
disk_xml = REXML::Document.new(disk_xml) if disk_xml.is_a?(String)
@id = disk_xml.elements['DISK_ID'].text.to_i
@vmid = vmid
@source = disk_xml.elements['SOURCE'].text
@clone = disk_xml.elements['CLONE'].text == 'YES'
@id = disk_xml.elements['DISK_ID'].text.to_i
@vmid = vmid
@type = disk_xml.elements['TYPE'].text
@pool = disk_xml.elements['POOL_NAME'].text
@rbd_image =
if @clone
"#{@source}-#{@vmid}-#{@id}"
else
@source
end
if volatile?
@source = nil
@clone = nil
@rbd_image = "#{@pool}/one-sys-#{vmid}-#{id}"
else
@source = disk_xml.elements['SOURCE'].text
@clone = disk_xml.elements['CLONE'].text == 'YES'
@rbd_image =
if @clone
"#{@source}-#{@vmid}-#{@id}"
else
@source
end
end
@rbd_cmd = 'rbd'
@rbd_cmd += Ceph.xml_opt(disk_xml, 'CEPH_USER', '--id')
@ -53,6 +61,10 @@ module TransferManager
@rbd_cmd += Ceph.xml_opt(disk_xml, 'CEPH_CONF', '--conf')
end
def volatile?
['fs', 'swap'].include?(@type)
end
# @return [String] Shell definitions for functionality related to this disk
def shdefs
<<~SCRIPT
@ -85,7 +97,7 @@ module TransferManager
## CLASS METHODS
# @param vm_xml [String, REXML::Document, REXML::Element]
# @return [Array(Disk)] indexed VM disks (disk id = position in array)
# @return [Array(Disk), nil] indexed VM disks (disk id = position in array)
def self.from_vm(vm_xml)
vm_xml = REXML::Document.new(vm_xml) if vm_xml.is_a?(String)
vm = vm_xml.root

View File

@ -1629,6 +1629,7 @@ void VirtualMachineDisks::backup_disk_ids(bool do_volatile, std::vector<int>& id
if ((type == "SWAP") ||
(type == "CDROM") ||
(type == "RBD_CDROM") ||
((type == "FS") && !do_volatile))
{
continue;