[pmg-devel] applied: [PATCH pmg-api 02/11] Backup: split backup creation and creating tar

Dietmar Maurer dietmar at proxmox.com
Fri Oct 30 07:20:46 CET 2020


applied - see comment inline

> On 10/28/2020 7:54 PM Stoiko Ivanov <s.ivanov at proxmox.com> wrote:
> 
>  
> In preparation for integrating PMG with PBS split the current creation of
> a PMG backup into 2 methods:
> * create all files in a backup in a target directory
> * create a tarball from a backup in a temporary directory
> 
> use the changed method in the backup API call.
> 
> Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
> ---
>  src/PMG/API2/Backup.pm |  2 +-
>  src/PMG/Backup.pm      | 41 ++++++++++++++++++++++++++++++++---------
>  2 files changed, 33 insertions(+), 10 deletions(-)
> 
> diff --git a/src/PMG/API2/Backup.pm b/src/PMG/API2/Backup.pm
> index 0bfcfc9..08c06b5 100644
> --- a/src/PMG/API2/Backup.pm
> +++ b/src/PMG/API2/Backup.pm
> @@ -131,7 +131,7 @@ __PACKAGE__->register_method ({
>  
>  	    print "starting backup to: $filename\n";
>  
> -	    PMG::Backup::pmg_backup($filename, $param->{statistic});
> +	    PMG::Backup::pmg_backup_pack($filename, $param->{statistic});
>  
>  	    print "backup finished\n";
>  
> diff --git a/src/PMG/Backup.pm b/src/PMG/Backup.pm
> index 025bac2..40c41f3 100644
> --- a/src/PMG/Backup.pm
> +++ b/src/PMG/Backup.pm
> @@ -133,10 +133,11 @@ sub dumpstatdb {
>  }
>  
>  sub pmg_backup {
> -    my ($filename, $include_statistics) = @_;
> +    my ($dirname, $include_statistics) = @_;
> +
> +    die "No backupdir provided!\n" if !defined($dirname);
>  
>      my $time = time;
> -    my $dirname = "/tmp/proxbackup_$$.$time";
>      my $dbfn = "Proxmox_ruledb.sql";
>      my $statfn = "Proxmox_statdb.sql";
>      my $tarfn = "config_backup.tar";
> @@ -145,12 +146,7 @@ sub pmg_backup {
>  
>      eval {
>  
> -	my $targetdir = dirname($filename);
> -	mkdir $targetdir; # try to create target dir
> -	-d $targetdir ||
> -	    die "unable to access target directory '$targetdir'\n";
> -
> -	# create a temporary directory
> +	# create backup directory
>  	mkdir $dirname;

seems we do this twice now

>  
>  	# dump the database first
> @@ -197,7 +193,34 @@ sub pmg_backup {
>  	system("cd $dirname; md5sum $tarfn $dbfn $extradb $verfn> $sigfn") == 0 ||
>  	    die "unable to create backup signature: ERROR";
>  
> -	system("rm -f $filename; tar czf $filename -C $dirname $verfn $sigfn $dbfn $extradb $tarfn") == 0 ||
> +    };
> +    my $err = $@;
> +
> +    if ($err) {
> +	die $err;
> +    }
> +}
> +
> +sub pmg_backup_pack {
> +    my ($filename, $include_statistics) = @_;
> +
> +    my $time = time;
> +    my $dirname = "/tmp/proxbackup_$$.$time";
> +
> +    eval {
> +
> +	my $targetdir = dirname($filename);
> +	mkdir $targetdir; # try to create target dir
> +	-d $targetdir ||
> +	    die "unable to access target directory '$targetdir'\n";
> +
> +	rmtree $dirname;
> +	# create backup directory
> +	mkdir $dirname;
> +
> +	pmg_backup($dirname, $include_statistics);
> +
> +	system("rm -f $filename; tar czf $filename --strip-components=1 -C $dirname .") == 0 ||
>  	    die "unable to create backup archive: ERROR";
>      };
>      my $err = $@;
> -- 
> 2.20.1
> 
> 
> 
> _______________________________________________
> pmg-devel mailing list
> pmg-devel at lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pmg-devel




More information about the pmg-devel mailing list