]>
git.proxmox.com Git - pmg-api.git/blob - src/PMG/CLI/pmgbackup.pm
1 package PMG
::CLI
::pmgbackup
;
6 use POSIX
qw(strftime);
12 use PVE
::CLIFormatter
;
13 use PVE
::JSONSchema
qw(get_standard_option);
16 use PMG
::RESTEnvironment
;
17 use PMG
::API2
::Backup
;
18 use PMG
::API2
::PBS
::Remote
;
19 use PMG
::API2
::PBS
::Job
;
21 use base
qw(PVE::CLIHandler);
23 my $nodename = PVE
::INotify
::nodename
();
28 my $password_map = PVE
::CLIHandler
::get_standard_mapping
('pve-password', {
31 return $value if $value;
32 return PVE
::PTY
::get_confirmed_password
();
37 name
=> 'encryption-key',
38 desc
=> 'a file containing an encryption key, or the special value "autogen"',
41 return $value if $value eq 'autogen';
42 return PVE
::Tools
::file_get_contents
($value);
48 'create' => [ $password_map, $enc_key_map ],
49 'update_config' => [ $password_map, $enc_key_map ],
51 return $mapping->{$name};
55 sub setup_environment
{
56 PMG
::RESTEnvironment-
>setup_default_cli_env();
59 my $format_backup_list = sub {
62 foreach my $entry (@$data) {
63 printf("%-30s %10d\n", $entry->{filename
}, $entry->{size
});
68 backup
=> [ 'PMG::API2::Backup', 'backup', undef, { node
=> $nodename } ],
69 restore
=> [ 'PMG::API2::Backup', 'restore', undef, { node
=> $nodename } ],
70 list
=> [ 'PMG::API2::Backup', 'list', undef, { node
=> $nodename }, $format_backup_list ],
72 list
=> ['PMG::API2::PBS::Remote', 'list', undef, undef, sub {
73 my ($data, $schema, $options) = @_;
74 PVE
::CLIFormatter
::print_api_result
($data, $schema, ['remote', 'server', 'datastore', 'username' ], $options);
75 }, $PVE::RESTHandler
::standard_output_options
],
76 add
=> ['PMG::API2::PBS::Remote', 'create', ['remote'] ],
77 remove
=> ['PMG::API2::PBS::Remote', 'delete', ['remote'] ],
78 set
=> ['PMG::API2::PBS::Remote', 'update_config', ['remote'] ],
81 list_backups
=> ['PMG::API2::PBS::Job', 'get_snapshots', ['remote'] , { node
=> $nodename }, sub {
82 my ($data, $schema, $options) = @_;
83 PVE
::CLIFormatter
::print_api_result
($data, $schema, ['time', 'size'], $options);
84 }, $PVE::RESTHandler
::standard_output_options
],
85 forget
=> ['PMG::API2::PBS::Job', 'forget_snapshot', ['remote', 'time'], { node
=> $nodename} ],
86 run
=> ['PMG::API2::PBS::Job', 'run_backup', ['remote'], { node
=> $nodename} ],
87 restore
=> ['PMG::API2::PBS::Job', 'restore', ['remote'], { node
=> $nodename} ],
88 create
=> ['PMG::API2::PBS::Job', 'create_timer', ['remote'], { node
=> $nodename }],
89 delete => ['PMG::API2::PBS::Job', 'delete_timer', ['remote'], { node
=> $nodename }],
90 schedule
=> ['PMG::API2::PBS::Job', 'list_timer', ['remote'], { node
=> $nodename }, sub {
91 my ($data, $schema, $options) = @_;
92 PVE
::CLIFormatter
::print_api_result
($data, $schema, ['remote', 'schedule', 'delay'], $options);
93 }, $PVE::RESTHandler
::standard_output_options
],