Class: Pvectl::Commands::RestoreBackup
- Inherits:
-
Object
- Object
- Pvectl::Commands::RestoreBackup
- Defined in:
- lib/pvectl/commands/restore_backup.rb
Overview
Handler for the ‘pvectl restore backup` command.
Restores a backup identified by its full volume ID (volid) to a new or existing VM/container. Requires –vmid and –yes flags.
Class Method Summary collapse
-
.execute(resource_type, volid, options, global_options) ⇒ Integer
Executes the restore backup command.
-
.register(cli) ⇒ void
Registers the restore command with the CLI.
Instance Method Summary collapse
-
#execute ⇒ Integer
Executes the restore backup command.
-
#initialize(resource_type, volid, options, global_options) ⇒ RestoreBackup
constructor
Initializes a restore backup command.
Constructor Details
#initialize(resource_type, volid, options, global_options) ⇒ RestoreBackup
Initializes a restore backup command.
121 122 123 124 125 126 |
# File 'lib/pvectl/commands/restore_backup.rb', line 121 def initialize(resource_type, volid, , ) @resource_type = resource_type @volid = volid @options = @global_options = end |
Class Method Details
.execute(resource_type, volid, options, global_options) ⇒ Integer
Executes the restore backup command.
111 112 113 |
# File 'lib/pvectl/commands/restore_backup.rb', line 111 def self.execute(resource_type, volid, , ) new(resource_type, volid, , ).execute end |
.register(cli) ⇒ void
This method returns an undefined value.
Registers the restore command with the CLI.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/pvectl/commands/restore_backup.rb', line 22 def self.register(cli) cli.desc "Restore a resource from backup" cli.long_desc <<~HELP Restore a virtual machine or container from a backup (vzdump) volume. Creates a new or overwrites an existing VM/container with the backup data. EXAMPLES Restore to a new VMID: $ pvectl restore backup local:backup/vzdump-qemu-100-2026_01_01.vma.zst --vmid 200 --yes Restore to specific storage: $ pvectl restore backup local:backup/vzdump-qemu-100-2026_01_01.vma.zst --vmid 200 --storage local-lvm --yes Overwrite existing VM: $ pvectl restore backup local:backup/vzdump-qemu-100-2026_01_01.vma.zst --vmid 100 --force --yes Restore and start immediately: $ pvectl restore backup local:backup/vzdump-qemu-100-2026_01_01.vma.zst --vmid 200 --start --yes Regenerate unique properties (MAC, UUID): $ pvectl restore backup local:backup/vzdump-qemu-100-2026_01_01.vma.zst --vmid 200 --unique --yes NOTES --vmid is required to specify the target VM/container ID. --force overwrites an existing VM/container with the same VMID. Without it, restore fails if the VMID already exists. --unique regenerates MAC addresses and other unique properties, useful when restoring alongside the original VM. Use 'pvectl get backups' to find backup volume IDs. SEE ALSO pvectl help create backup Create a new backup pvectl help get backups List available backups pvectl help delete backup Delete backup volumes HELP cli.arg_name "RESOURCE_TYPE VOLID" cli.command :restore do |c| c.desc "Target VMID (required)" c.flag [:vmid], arg_name: "VMID", type: Integer c.desc "Target storage" c.flag [:storage], arg_name: "STORAGE" c.desc "Overwrite existing VM/container" c.switch [:force], negatable: false c.desc "Start after restore" c.switch [:start], negatable: false c.desc "Regenerate unique properties (MAC, UUID)" c.switch [:unique], negatable: false c.desc "Skip confirmation prompt (REQUIRED)" c.switch [:yes, :y], negatable: false c.desc "Timeout in seconds" c.flag [:timeout], type: Integer, arg_name: "SECONDS" c.desc "Force async mode" c.switch [:async], negatable: false c.action do |, , args| resource_type = args.shift volid = args.first exit_code = case resource_type when "backup" Commands::RestoreBackup.execute(resource_type, volid, , ) else $stderr.puts "Error: Unknown resource type: #{resource_type}" $stderr.puts "Valid types: backup" ExitCodes::USAGE_ERROR end exit exit_code if exit_code != 0 end end end |
Instance Method Details
#execute ⇒ Integer
Executes the restore backup command.
131 132 133 134 135 136 137 138 |
# File 'lib/pvectl/commands/restore_backup.rb', line 131 def execute return usage_error("Resource type required (backup)") unless @resource_type == "backup" return usage_error("Backup volid is required") if @volid.nil? || @volid.empty? return usage_error("--vmid is required") unless @options[:vmid] return usage_error("Confirmation required: use --yes to confirm restore") unless @options[:yes] perform_operation end |