[pmg-devel] [PATCH pmg-api 4/5] backup: add notify parameter to 'classic' backup

Stoiko Ivanov s.ivanov at proxmox.com
Wed Feb 24 19:31:01 CET 2021


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 at proxmox.com>
---
 src/PMG/API2/Backup.pm | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/src/PMG/API2/Backup.pm b/src/PMG/API2/Backup.pm
index 4ea28d1..5887bb2 100644
--- a/src/PMG/API2/Backup.pm
+++ b/src/PMG/API2/Backup.pm
@@ -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 => 'error',
+	    },
 	},
     },
     returns => { type => "string" },
@@ -129,11 +136,19 @@ __PACKAGE__->register_method ({
 	my $worker = sub {
 	    my $upid = shift;
 
-	    print "starting backup to: $filename\n";
+	    my $log = "starting backup to: $filename\n";
+
+	    eval { PMG::Backup::pmg_backup_pack($filename, $param->{statistic}) };
+	    my $err = $@;
+	    $log .= $err if $err;
+
+	    $log .= "backup finished\n";
+
+	    PMG::Backup::send_backup_notification($param->{notify}, undef, $log, $err);
 
-	    PMG::Backup::pmg_backup_pack($filename, $param->{statistic});
+	    die "$err\n" if $err;
 
-	    print "backup finished\n";
+	    print $log;
 
 	    return;
 	};
-- 
2.20.1





More information about the pmg-devel mailing list