]> git.proxmox.com Git - pmg-api.git/commitdiff
backup: add notify parameter to 'classic' backup
authorStoiko Ivanov <s.ivanov@proxmox.com>
Mon, 1 Mar 2021 14:12:20 +0000 (15:12 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 5 Mar 2021 21:41:38 +0000 (22:41 +0100)
for feature-parity, and since we recently had a user in our community
forum, who does regular backups via cron+rsync (small site w/o
dedicated backup host). Those setups could also benefit from this.

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/PMG/API2/Backup.pm

index 4ea28d13e28f23956ec7e0ff64e77ea04a333a53..172e810f6bca1800b7fe9a57bb906a868a543afa 100644 (file)
@@ -110,6 +110,13 @@ __PACKAGE__->register_method ({
                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" },
@@ -129,11 +136,21 @@ __PACKAGE__->register_method ({
        my $worker = sub {
            my $upid = shift;
 
-           print "starting backup to: $filename\n";
+           my $full_log = "";
+           my $log = sub { print "$_[0]\n"; $full_log .= "$_[0]\n"; };
+
+           $log->("starting backup to: $filename");
+
+           eval { PMG::Backup::pmg_backup_pack($filename, $param->{statistic}) };
+           if (my $err = $@) {
+               $log->($err);
+               PMG::Backup::send_backup_notification($param->{notify}, undef, $full_log, $err);
+               die "backup failed: $err\n";
+           }
 
-           PMG::Backup::pmg_backup_pack($filename, $param->{statistic});
+           $log->("backup finished");
 
-           print "backup finished\n";
+           PMG::Backup::send_backup_notification($param->{notify}, undef, $full_log, undef);
 
            return;
        };