]>
Commit | Line | Data |
---|---|---|
0f79c55f DM |
1 | package PMG::CLI::pmgbackup; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
fb9e46a0 | 5 | use Data::Dumper; |
57203667 | 6 | use POSIX qw(strftime); |
0f79c55f DM |
7 | |
8 | use PVE::Tools; | |
9 | use PVE::SafeSyslog; | |
10 | use PVE::INotify; | |
11 | use PVE::CLIHandler; | |
57203667 SI |
12 | use PVE::CLIFormatter; |
13 | use PVE::JSONSchema qw(get_standard_option); | |
14 | use PVE::PTY; | |
0f79c55f DM |
15 | |
16 | use PMG::RESTEnvironment; | |
17 | use PMG::API2::Backup; | |
57203667 SI |
18 | use PMG::API2::PBS::Remote; |
19 | use PMG::API2::PBS::Job; | |
0f79c55f DM |
20 | |
21 | use base qw(PVE::CLIHandler); | |
22 | ||
23 | my $nodename = PVE::INotify::nodename(); | |
24 | ||
57203667 SI |
25 | sub param_mapping { |
26 | my ($name) = @_; | |
27 | ||
28 | my $password_map = PVE::CLIHandler::get_standard_mapping('pve-password', { | |
29 | func => sub { | |
30 | my ($value) = @_; | |
31 | return $value if $value; | |
32 | return PVE::PTY::get_confirmed_password(); | |
33 | }, | |
34 | }); | |
35 | ||
36 | my $enc_key_map = { | |
37 | name => 'encryption-key', | |
38 | desc => 'a file containing an encryption key, or the special value "autogen"', | |
39 | func => sub { | |
40 | my ($value) = @_; | |
41 | return $value if $value eq 'autogen'; | |
42 | return PVE::Tools::file_get_contents($value); | |
43 | } | |
44 | }; | |
45 | ||
46 | ||
47 | my $mapping = { | |
48 | 'create' => [ $password_map, $enc_key_map ], | |
49 | 'update_config' => [ $password_map, $enc_key_map ], | |
50 | }; | |
51 | return $mapping->{$name}; | |
52 | } | |
53 | ||
54 | ||
0f79c55f DM |
55 | sub setup_environment { |
56 | PMG::RESTEnvironment->setup_default_cli_env(); | |
57 | } | |
58 | ||
fb9e46a0 DM |
59 | my $format_backup_list = sub { |
60 | my ($data) = @_; | |
61 | ||
62 | foreach my $entry (@$data) { | |
63 | printf("%-30s %10d\n", $entry->{filename}, $entry->{size}); | |
64 | } | |
65 | }; | |
66 | ||
0f79c55f DM |
67 | our $cmddef = { |
68 | backup => [ 'PMG::API2::Backup', 'backup', undef, { node => $nodename } ], | |
69 | restore => [ 'PMG::API2::Backup', 'restore', undef, { node => $nodename } ], | |
fb9e46a0 | 70 | list => [ 'PMG::API2::Backup', 'list', undef, { node => $nodename }, $format_backup_list ], |
57203667 SI |
71 | remote => { |
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'] ], | |
79 | }, | |
80 | pbsjob => { | |
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} ], | |
7251cc51 SI |
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 ], | |
57203667 | 94 | }, |
0f79c55f DM |
95 | }; |
96 | ||
97 | 1; |