]>
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";
22 type
=> 'integer', minimum
=> '0',
23 format_description
=> 'N',
26 my %prune_properties = (
29 description
=> 'Keep the last <N> backups.',
33 description
=> 'Keep backups for the last <N> different hours. If there is more' .
34 'than one backup for a single hour, only the latest one is kept.'
38 description
=> 'Keep backups for the last <N> different days. If there is more' .
39 'than one backup for a single day, only the latest one is kept.'
43 description
=> 'Keep backups for the last <N> different weeks. If there is more' .
44 'than one backup for a single week, only the latest one is kept.'
48 description
=> 'Keep backups for the last <N> different months. If there is more' .
49 'than one backup for a single month, only the latest one is kept.'
53 description
=> 'Keep backups for the last <N> different years. If there is more' .
54 'than one backup for a single year, only the latest one is kept.'
60 type
=> { description
=> "Section type." },
62 description
=> "Proxmox Backup Server ID.",
63 type
=> 'string', format
=> 'pve-configid',
71 description
=> "Proxmox backup server datastore name.",
75 description
=> "Proxmox backup server address.",
76 type
=> 'string', format
=> 'address',
80 description
=> "Flag to disable/deactivate the entry.",
85 description
=> "Password for the user on the Proxmox backup server.",
89 username
=> get_standard_option
('pmg-email-address', {
90 description
=> "Username on the Proxmox backup server"
92 fingerprint
=> get_standard_option
('fingerprint-sha256'),
101 disable
=> { optional
=> 1 },
102 username
=> { optional
=> 1 },
103 password
=> { optional
=> 1 },
104 fingerprint
=> { optional
=> 1 },
105 'keep-last' => { optional
=> 1 },
106 'keep-hourly' => { optional
=> 1 },
107 'keep-daily' => { optional
=> 1 },
108 'keep-weekly' => { optional
=> 1 },
109 'keep-monthly' => { optional
=> 1 },
110 'keep-yearly' => { optional
=> 1 },
123 my ($self, $remote) = @_;
125 my $remote_cfg = $self->{ids
}->{$remote};
129 foreach my $keep_opt (keys %prune_properties) {
131 if (defined($remote_cfg->{$keep_opt})) {
132 $res->{$keep_opt} = $remote_cfg->{$keep_opt};
141 my $class = ref($type) || $type;
143 my $cfg = PVE
::INotify
::read_file
($inotify_file_id);
145 $cfg->{secret_dir
} = $secret_dir;
147 return bless $cfg, $class;
153 PVE
::INotify
::write_file
($inotify_file_id, $self);
156 my $lockfile = "/var/lock/pmgpbsconfig.lck";
159 my ($code, $errmsg) = @_;
161 my $p = PVE
::Tools
::lock_file
($lockfile, undef, $code);
163 $errmsg ?
die "$errmsg: $err" : die $err;
168 __PACKAGE__-
>register();
171 sub read_pmg_pbs_conf
{
172 my ($filename, $fh) = @_;
174 local $/ = undef; # slurp mode
176 my $raw = defined($fh) ?
<$fh> : '';
178 return __PACKAGE__-
>parse_config($filename, $raw);
181 sub write_pmg_pbs_conf
{
182 my ($filename, $fh, $cfg) = @_;
184 my $raw = __PACKAGE__-
>write_config($filename, $cfg);
186 PVE
::Tools
::safe_print
($filename, $fh, $raw);
189 PVE
::INotify
::register_file
($inotify_file_id, $config_filename,
191 \
&write_pmg_pbs_conf
,
193 always_call_parser
=> 1);