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

Thomas Lamprecht t.lamprecht at proxmox.com
Thu Feb 25 11:06:31 CET 2021


On 24.02.21 19:31, Stoiko Ivanov wrote:
> 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";

same regarding please avoiding $log at the end and no log in error case...
Just combine print and log string concat into a closure...

> +
> +	    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;
>  	};
> 





More information about the pmg-devel mailing list