Class: Pvectl::Commands::CreateBackup

Inherits:
Object
  • Object
show all
Defined in:
lib/pvectl/commands/create_backup.rb

Overview

Handler for the ‘pvectl create backup` command.

Creates backups for one or more VMs/containers. Supports multiple VMIDs with optional confirmation prompt.

Examples:

Create single backup

pvectl create backup 100 --storage local

Create backup for multiple VMs

pvectl create backup 100 101 102 --storage nfs --mode snapshot

Create backup with options

pvectl create backup 100 --storage local --compress zstd --notes "Pre-upgrade" --protected

Constant Summary collapse

SUPPORTED_RESOURCES =
%w[backup].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource_type, resource_ids, options, global_options) ⇒ CreateBackup

Initializes a create backup command.

Parameters:

  • resource_type (String, nil)

    resource type (backup)

  • resource_ids (Array<String>, String, nil)

    VM identifiers

  • options (Hash)

    command options

  • global_options (Hash)

    global CLI options



39
40
41
42
43
44
# File 'lib/pvectl/commands/create_backup.rb', line 39

def initialize(resource_type, resource_ids, options, global_options)
  @resource_type = resource_type
  @resource_ids = Array(resource_ids).compact.map(&:to_i)
  @options = options
  @global_options = global_options
end

Class Method Details

.execute(resource_type, resource_ids, options, global_options) ⇒ Integer

Executes the create backup command.

Parameters:

  • resource_type (String, nil)

    resource type (backup)

  • resource_ids (Array<String>, String, nil)

    VM identifiers

  • options (Hash)

    command options

  • global_options (Hash)

    global CLI options

Returns:

  • (Integer)

    exit code



29
30
31
# File 'lib/pvectl/commands/create_backup.rb', line 29

def self.execute(resource_type, resource_ids, options, global_options)
  new(resource_type, resource_ids, options, global_options).execute
end

Instance Method Details

#executeInteger

Executes the create backup command.

Returns:

  • (Integer)

    exit code



49
50
51
52
53
54
55
56
# File 'lib/pvectl/commands/create_backup.rb', line 49

def execute
  return usage_error("Resource type required (backup)") unless @resource_type
  return usage_error("Unsupported resource: #{@resource_type}") unless SUPPORTED_RESOURCES.include?(@resource_type)
  return usage_error("At least one VMID is required") if @resource_ids.empty?
  return usage_error("--storage is required") unless @options[:storage]

  perform_operation
end