]>
git.proxmox.com Git - pmg-api.git/blob - src/PMG/PBSConfig.pm
1 package PMG
::PBSConfig
;
3 # section config implementation for PBS integration in PMG
8 use PVE
::Tools
qw(extract_param);
9 use PVE
::SectionConfig
;
10 use PVE
::JSONSchema
qw(get_standard_option);
13 use base
qw(PVE::SectionConfig);
15 my $inotify_file_id = 'pmg-pbs.conf';
16 my $secret_dir = '/etc/pmg/pbs';
17 my $config_filename = "${secret_dir}/pbs.conf";
21 type
=> 'integer', minimum
=> '0',
22 format_description
=> 'N',
25 my %prune_properties = (
28 description
=> 'Keep the last <N> backups.',
32 description
=> 'Keep backups for the last <N> different hours. If there is'
33 .' more than one backup for a single hour, only the latest one is kept.'
37 description
=> 'Keep backups for the last <N> different days. If there is'
38 .' more than one backup for a single day, only the latest one is kept.'
42 description
=> 'Keep backups for the last <N> different weeks. If there is'
43 .'more than one backup for a single week, only the latest one is kept.'
47 description
=> 'Keep backups for the last <N> different months. If there is'
48 .' more than one backup for a single month, only the latest one is kept.'
52 description
=> 'Keep backups for the last <N> different years. If there is'
53 .' more than one backup for a single year, only the latest one is kept.'
59 type
=> { description
=> "Section type." },
61 description
=> "Proxmox Backup Server ID.",
62 type
=> 'string', format
=> 'pve-configid',
70 description
=> "Proxmox Backup Server datastore name.",
74 description
=> "Proxmox Backup Server address.",
75 type
=> 'string', format
=> 'address',
79 description
=> "Flag to disable (deactivate) the entry.",
84 description
=> "Password or API token secret for the user on the"
85 ." Proxmox Backup Server.",
89 username
=> get_standard_option
('pmg-email-address', {
90 description
=> "Username or API token ID on the Proxmox Backup Server"
92 fingerprint
=> get_standard_option
('fingerprint-sha256'),
93 'include-statistics' => {
94 description
=> "Include statistics in scheduled backups",
106 disable
=> { optional
=> 1 },
107 username
=> { optional
=> 1 },
108 password
=> { optional
=> 1 },
109 fingerprint
=> { optional
=> 1 },
110 'include-statistics' => { optional
=> 1 },
111 'keep-last' => { optional
=> 1 },
112 'keep-hourly' => { optional
=> 1 },
113 'keep-daily' => { optional
=> 1 },
114 'keep-weekly' => { optional
=> 1 },
115 'keep-monthly' => { optional
=> 1 },
116 'keep-yearly' => { optional
=> 1 },
129 my ($self, $remote) = @_;
131 my $remote_cfg = $self->{ids
}->{$remote};
135 foreach my $keep_opt (keys %prune_properties) {
136 if (defined($remote_cfg->{$keep_opt})) {
138 $res->{$keep_opt} = $remote_cfg->{$keep_opt};
141 return $pruning_setup ?
$res : undef;
147 my $class = ref($type) || $type;
149 my $cfg = PVE
::INotify
::read_file
($inotify_file_id);
151 $cfg->{secret_dir
} = $secret_dir;
153 return bless $cfg, $class;
159 PVE
::INotify
::write_file
($inotify_file_id, $self);
163 my ($code, $errmsg) = @_;
165 my $lockfile = "/var/lock/pmgpbsconfig.lck";
167 my $p = PVE
::Tools
::lock_file
($lockfile, undef, $code);
169 $errmsg ?
die "$errmsg: $err" : die $err;
173 __PACKAGE__-
>register();
176 sub read_pmg_pbs_conf
{
177 my ($filename, $fh) = @_;
179 local $/ = undef; # slurp mode
181 my $raw = defined($fh) ?
<$fh> : '';
183 return __PACKAGE__-
>parse_config($filename, $raw);
186 sub write_pmg_pbs_conf
{
187 my ($filename, $fh, $cfg) = @_;
189 my $raw = __PACKAGE__-
>write_config($filename, $cfg);
191 PVE
::Tools
::safe_print
($filename, $fh, $raw);
194 PVE
::INotify
::register_file
(
198 \
&write_pmg_pbs_conf
,
200 always_call_parser
=> 1