1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-04-01 06:50:25 +03:00

F #6063: Include backup job id in Image URL

The new URL format is:

- restic://<datastore_id>/<bj_id>/<id>:<snapshot_id>,.../<file_name>
- rsync://<datastore_id>/<bj_id>/<id>:<snapshot_id>,.../<file_name>

bj_id can be empty

This commits also adapts some drivers to the new BACKUP format.
This commit is contained in:
Ruben S. Montero 2023-08-31 12:39:10 +02:00
parent 8ae7512350
commit c14869eb84
No known key found for this signature in database
GPG Key ID: A0CEA6FA880A1D87
11 changed files with 66 additions and 41 deletions

View File

@ -62,34 +62,43 @@ SSH_OPTS = '-q -o ControlMaster=no -o ControlPath=none -o ForwardAgent=yes'
# Parse input data.
# restic://<datastore_id>/<id>:<snapshot_id>,.../<file_name>
# restic://<datastore_id>/<bj_id>/<id>:<snapshot_id>,.../<file_name>
restic_url = ARGV[0]
tokens = restic_url.delete_prefix('restic://').split('/')
ds_id = tokens[0].to_i
snaps = tokens[1].split(',').map {|s| s.split(':')[1] }
disk_path = tokens[2..-1].join('/')
bj_id = tokens[1]
snaps = tokens[2].split(',').map {|s| s.split(':')[1] }
disk_path = tokens[3..-1].join('/')
disk_index = Pathname.new(disk_path).basename.to_s.split('.')[1]
vm_id = disk_path.match('/(\d+)/backup/[^/]+$')[1].to_i
begin
#---------------------------------------------------------------------------
# Do a sanity check if Restic is available/enabled.
#---------------------------------------------------------------------------
raise StandardError, 'Restic unavailable, please use OpenNebula EE.' \
unless File.exist?("#{VAR_LOCATION}/remotes/datastore/restic/")
require "#{VAR_LOCATION}/remotes/datastore/restic/restic"
# Fetch datastore XML payload directly from the API.
#---------------------------------------------------------------------------
# Fetch datastore and VM XML payload directly from the API.
#---------------------------------------------------------------------------
backup_ds = OpenNebula::Datastore.new_with_id ds_id, OpenNebula::Client.new
rc = backup_ds.info(true)
raise StandardError, rc.message if OpenNebula.is_error?(backup_ds)
raise StandardError, rc.message if OpenNebula.is_error?(rc)
repo_id = if !bj_id.empty?
Restic.mk_repo_id(bj_id)
else
vm_id
end
#---------------------------------------------------------------------------
# Pull from Restic, then post-process qcow2 disks.
rds = Restic.new backup_ds.to_xml, :vm_id => vm_id,
#---------------------------------------------------------------------------
rds = Restic.new backup_ds.to_xml, :repo_id => repo_id,
:repo_type => :local,
:host_type => :hypervisor
rescue StandardError => e

View File

@ -61,9 +61,10 @@ daction64 = STDIN.read
_ds_id = ARGV[0]
# Image path in the form:
# rsync://100/0:6da1c7,1:06132a,2:03fc2a//var/lib/one//datastores/100/13/6da1c7/disk.0.0
# rsync://100/4/0:6da1c7,1:06132a,2:03fc2a/var/lib/one//datastores/100/13/6da1c7/disk.0.0
#
# datastore_id = 100
# backupjob id = 4 (can be empty)
# last snap = 03fc2a
# base path = /var/lib/one//datastores/100/13
@ -78,14 +79,14 @@ begin
parts = img.split('/')
diskid = parts[-1].match(/disk\.([0-9]+)/)
base_path = "/#{parts[2..-3].join('/')}/"
base_path = "/#{parts[3..-3].join('/')}/"
if !diskid
STDERR.puts "Wrong format for disk filename #{parts[2]}"
STDERR.puts "Wrong format for disk filename #{base_path}"
exit(-1)
end
last_snap = parts[1].split(',')[-1].split(':')[-1]
last_snap = parts[2].split(',')[-1].split(':')[-1]
cmd = "cat #{base_path}#{last_snap}/vm.xml"
rescue StandardError => e

View File

@ -62,12 +62,13 @@ SSH_OPTS = '-q -o ControlMaster=no -o ControlPath=none -o ForwardAgent=yes'
# Parse input data.
# rsync://100/0:8a3454,1:f6e63e//var/lib/one//datastores/100/6/8a3454/disk.0.0
# rsync://100/3/0:8a3454,1:f6e63e//var/lib/one/datastores/100/6/8a3454/disk.0.0
rsync_url = ARGV[0]
tokens = rsync_url.delete_prefix('rsync://').split('/')
ds_id = tokens[0].to_i
increments = tokens[1].split(',').map {|s| s.split(':') }
disk_path = tokens[2..-1].join('/')
_bj_id = tokens[1]
increments = tokens[2].split(',').map {|s| s.split(':') }
disk_path = "/#{tokens[3..-1].join('/')}"
disk_index = Pathname.new(disk_path).basename.to_s.split('.')[1]
vm_id = disk_path.match("/#{ds_id}/(\\d+)/[^/]+/[^/]+$")[1].to_i

View File

@ -55,15 +55,17 @@ require 'rexml/document'
require_relative '../lib/tm_action'
# BACKUP tm_mad host:remote_dir DISK_ID:...:DISK_ID deploy_id vmid dsid
#-------------------------------------------------------------------------------
# BACKUP tm_mad host:remote_dir DISK_ID:...:DISK_ID deploy_id bjid vmid dsid
#-------------------------------------------------------------------------------
_vm_xml = STDIN.read
dir = ARGV[0].split ':'
_disks = ARGV[1].split ':'
_deployid = ARGV[2]
_vmid = ARGV[3]
_dsid = ARGV[4]
_bjid = ARGV[3]
_vmid = ARGV[4]
_dsid = ARGV[5]
rhost = dir[0]
rdir = dir[1]

View File

@ -68,15 +68,16 @@ rescue StandardError
end
#-------------------------------------------------------------------------------
# BACKUP tm_mad host:remote_dir DISK_ID:...:DISK_ID deploy_id vmid dsid
# BACKUP tm_mad host:remote_dir DISK_ID:...:DISK_ID deploy_id bjid vmid dsid
#-------------------------------------------------------------------------------
vm_xml = STDIN.read
dir = ARGV[0].split ':'
disks = ARGV[1].split ':'
_deployid = ARGV[2]
vmid = ARGV[3]
_dsid = ARGV[4]
_bjid = ARGV[3]
vmid = ARGV[4]
_dsid = ARGV[5]
rhost = dir[0]
rdir = dir[1]

View File

@ -71,15 +71,16 @@ rescue StandardError
end
#-------------------------------------------------------------------------------
# BACKUP tm_mad host:remote_dir DISK_ID:...:DISK_ID deploy_id vmid dsid
# BACKUP tm_mad host:remote_dir DISK_ID:...:DISK_ID deploy_id bjid vmid dsid
#-------------------------------------------------------------------------------
vm_xml = STDIN.read
dir = ARGV[0].split ':'
disks = ARGV[1].split ':'
deploy_id = ARGV[2]
vmid = ARGV[3]
_dsid = ARGV[4]
_bjid = ARGV[3]
vmid = ARGV[4]
_dsid = ARGV[5]
rhost = dir[0]
rdir = dir[1]

View File

@ -238,10 +238,10 @@ module TransferManager
opts[:bimage].chain
end
@base_url = "#{opts[:proto]}://#{opts[:ds_id]}/#{chain}"
@bj_id = opts[:bimage].bj_id
@base_url = "#{opts[:proto]}://#{opts[:ds_id]}/#{@bj_id}/#{chain}"
return unless no_ip
NIC_LIST << ['IP', 'IP6', 'IP6_ULA', 'IP6_GLOBAL', 'MAC']
@ -270,6 +270,8 @@ module TransferManager
m = f.match(/disk\.([0-9]+)/)
next unless m
f.prepend('/') if f[0] != '/'
disk_id = m[1]
type = if disk_id == '0'
@ -284,7 +286,7 @@ module TransferManager
NAME = "#{name}"
TYPE = "#{type}"
PATH = "#{@base_url}/#{f}"
PATH = "#{@base_url}#{f}"
FROM_BACKUP_DS = "#{@ds_id}"
EOS

View File

@ -53,15 +53,18 @@ $LOAD_PATH << RUBY_LIB_LOCATION
require_relative '../lib/tm_action'
# BACKUP tm_mad host:remote_dir DISK_ID:...:DISK_ID deploy_id vmid dsid
#-------------------------------------------------------------------------------
# BACKUP tm_mad host:remote_dir DISK_ID:...:DISK_ID deploy_id bjid vmid dsid
#-------------------------------------------------------------------------------
_vm_xml = STDIN.read
dir = ARGV[0].split ':'
_disks = ARGV[1].split ':'
_deployid = ARGV[2]
_vmid = ARGV[3]
_dsid = ARGV[4]
_bjid = ARGV[3]
_vmid = ARGV[4]
_dsid = ARGV[5]
rhost = dir[0]
rdir = dir[1]

View File

@ -53,15 +53,18 @@ $LOAD_PATH << RUBY_LIB_LOCATION
require_relative '../lib/tm_action'
# BACKUP tm_mad host:remote_dir DISK_ID:...:DISK_ID deploy_id vmid dsid
#-------------------------------------------------------------------------------
# BACKUP tm_mad host:remote_dir DISK_ID:...:DISK_ID deploy_id bjid vmid dsid
#-------------------------------------------------------------------------------
_vm_xml = STDIN.read
dir = ARGV[0].split ':'
disks = ARGV[1]
_deploy_id = ARGV[2]
_vmid = ARGV[3]
_dsid = ARGV[4]
_bjid = ARGV[3]
_vmid = ARGV[4]
_dsid = ARGV[5]
rhost = dir[0]
rdir = dir[1]

View File

@ -57,15 +57,16 @@ require_relative '../lib/datastore'
require 'rexml/document'
#-------------------------------------------------------------------------------
# BACKUP tm_mad host:remote_dir DISK_ID:...:DISK_ID deploy_id vmid dsid
# BACKUP tm_mad host:remote_dir DISK_ID:...:DISK_ID deploy_id vmid bjid dsid
#-------------------------------------------------------------------------------
vm_xml = STDIN.read
dir = ARGV[0].split ':'
disks = ARGV[1]
_deployid = ARGV[2]
_vmid = ARGV[3]
_dsid = ARGV[4]
_bjid = ARGV[3]
_vmid = ARGV[4]
_dsid = ARGV[5]
rhost = dir[0]
rdir = dir[1]

View File

@ -61,15 +61,16 @@ require_relative '../lib/datastore'
include TransferManager::KVM
#-------------------------------------------------------------------------------
# BACKUP tm_mad host:remote_dir DISK_ID:...:DISK_ID deploy_id vmid dsid
# BACKUP tm_mad host:remote_dir DISK_ID:...:DISK_ID deploy_id vmid bjid dsid
#-------------------------------------------------------------------------------
vm_xml = STDIN.read
dir = ARGV[0].split ':'
disks = ARGV[1]
_deploy_id = ARGV[2]
_vmid = ARGV[3]
_dsid = ARGV[4]
_bjid = ARGV[3]
_vmid = ARGV[4]
_dsid = ARGV[5]
rhost = dir[0]
rdir = dir[1]