clamd.conf.in \
postgresql.conf.in \
pg_hba.conf.in \
+ backup-notification.tt \
TEMPLATES_FILES = $(addprefix templates/, ${TEMPLATES})
optional => 1,
default => 1,
},
+ notify => {
+ description => "Specify when to notify via e-mail",
+ type => 'string',
+ enum => [ 'always', 'error', 'never' ],
+ optional => 1,
+ default => 'never',
+ },
},
},
returns => { type => "string" },
die "PBS remote '$remote' is disabled\n" if $remote_config->{disable};
$param->{statistic} //= $remote_config->{'include-statistics'} // 1;
+ my $notify = $param->{notify} // $remote_config->{notify} // 'never';
my $pbs = PVE::PBSClient->new($remote_config, $remote, $conf->{secret_dir});
my $worker = sub {
my $upid = shift;
- print "starting update of current backup state\n";
+ my $full_log = "";
+ my $log = sub { print "$_[0]\n"; $full_log .= "$_[0]\n"; };
+
+ $log->("starting update of current backup state");
eval {
-d $backup_dir || mkdir $backup_dir;
rmtree $backup_dir;
};
if (my $err = $@) {
+ $log->($err);
+ PMG::Backup::send_backup_notification($notify, $remote, $full_log, $err);
rmtree $backup_dir;
die "backup failed: $err\n";
-
}
- print "backup finished\n";
+ $log->("backup finished");
my $group = "host/$node";
if (defined(my $prune_opts = $conf->prune_options($remote))) {
- print "starting prune of $group\n";
- my $res = $pbs->prune_group(undef, $prune_opts, $group);
-
+ $log->("starting prune of $group");
+ my $res = eval { $pbs->prune_group(undef, $prune_opts, $group) };
+ if (my $err = $@) {
+ $log->($err);
+ PMG::Backup::send_backup_notification($notify, $remote, $full_log, $err);
+ die "pruning failed: $err\n";
+ }
foreach my $pruned (@$res){
my $time = strftime("%FT%TZ", gmtime($pruned->{'backup-time'}));
my $snap = $pruned->{'backup-type'} . '/' . $pruned->{'backup-id'} . '/' . $time;
- print "pruned snapshot: $snap\n";
+ $log->("pruned snapshot: $snap");
}
- print "prune finished\n";
+ $log->("prune finished");
}
+ PMG::Backup::send_backup_notification($notify, $remote, $full_log, undef);
+
return;
};
use Data::Dumper;
use File::Basename;
use File::Path;
+use POSIX qw(strftime);
use PVE::JSONSchema qw(get_standard_option);
use PVE::Tools;
die $err if $err;
}
+sub send_backup_notification {
+ my ($notify_on, $target, $log, $err) = @_;
+
+ return if !$notify_on;
+ return if $notify_on eq 'never';
+ return if $notify_on eq 'error' && !$err;
+
+ my $cfg = PMG::Config->new();
+ my $email = $cfg->get ('admin', 'email');
+ if (!$email) {
+ warn "not sending notifcation: no admin email configured\n";
+ return;
+ }
+
+ my $nodename = PVE::INotify::nodename();
+ my $fqdn = PVE::Tools::get_fqdn($nodename);
+
+
+ my $vars = {
+ hostname => $nodename,
+ fqdn => $fqdn,
+ date => strftime("%F", localtime()),
+ target => $target,
+ log => $log,
+ err => $err,
+ };
+
+ my $tt = PMG::Config::get_template_toolkit();
+
+ my $mailfrom = "Proxmox Mail Gateway <postmaster>";
+ PMG::Utils::finalize_report($tt, 'backup-notification.tt', $vars, $mailfrom, $email);
+
+}
+
1;
description => "Username or API token ID on the Proxmox Backup Server"
}),
fingerprint => get_standard_option('fingerprint-sha256'),
+ notify => {
+ description => "Specify when to notify via e-mail",
+ type => 'string',
+ enum => [ 'always', 'error', 'never' ],
+ optional => 1,
+ },
'include-statistics' => {
description => "Include statistics in scheduled backups",
type => 'boolean',
username => { optional => 1 },
password => { optional => 1 },
fingerprint => { optional => 1 },
+ notify => { optional => 1 },
'include-statistics' => { optional => 1 },
'keep-last' => { optional => 1 },
'keep-hourly' => { optional => 1 },
--- /dev/null
+[%- IF err -%]
+[%- SET titleprefix = "Backup failed" -%]
+[%- ELSE %]
+[%- SET titleprefix = "Backup successful" -%]
+[%- END -%]
+[%- IF target -%]
+[%- SET titlesuffix = "to ${target} - ($fqdn)" -%]
+[%- ELSE %]
+[%- SET titlesuffix = "($fqdn)" -%]
+[%- END -%]
+<html>
+ <head>
+ <title>[% titleprefix %] [% titlesuffix %]</title>
+ </head>
+ <body>
+ Detailed backup logs:<br /><br />
+ <pre>[% log %]</pre>
+ </body>
+</html>