From: Stoiko Ivanov <s.ivanov@proxmox.com>
To: pmg-devel@lists.proxmox.com
Subject: [pmg-devel] [RFC pmg-api 02/12] Backup: split backup creation and creating tar
Date: Mon, 19 Oct 2020 21:01:59 +0200 [thread overview]
Message-ID: <20201019190209.11495-3-s.ivanov@proxmox.com> (raw)
In-Reply-To: <20201019190209.11495-1-s.ivanov@proxmox.com>
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@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..3854a5d 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 ($backupdir, $include_statistics) = @_;
+
my $time = time;
- my $dirname = "/tmp/proxbackup_$$.$time";
+ my $dirname = $backupdir // '/var/lib/pmg/backup/current';
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;
# 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
next prev parent reply other threads:[~2020-10-19 19:02 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-19 19:01 [pmg-devel] [RFC pmg-api 00/12] POC PBS integration Stoiko Ivanov
2020-10-19 19:01 ` [pmg-devel] [RFC pmg-api 01/12] drop left-over commented out code Stoiko Ivanov
2020-10-19 19:01 ` Stoiko Ivanov [this message]
2020-10-20 5:43 ` [pmg-devel] [RFC pmg-api 02/12] Backup: split backup creation and creating tar Dietmar Maurer
2020-10-19 19:02 ` [pmg-devel] [RFC pmg-api 03/12] Restore: optionally restore from directory Stoiko Ivanov
2020-10-19 19:02 ` [pmg-devel] [RFC pmg-api 04/12] Backup: push restore options to PMG::Backup Stoiko Ivanov
2020-10-19 19:02 ` [pmg-devel] [RFC pmg-api 05/12] debian: add dependency on proxmox-backup-client Stoiko Ivanov
2020-10-19 19:02 ` [pmg-devel] [RFC pmg-api 06/12] add helper module for handling PBS Integration Stoiko Ivanov
2020-10-19 19:02 ` [pmg-devel] [RFC pmg-api 07/12] PBSTools: add methods for managing backups Stoiko Ivanov
2020-10-19 19:02 ` [pmg-devel] [RFC pmg-api 08/12] PBSTools: add systemd-timer helpers Stoiko Ivanov
2020-10-19 19:02 ` [pmg-devel] [RFC pmg-api 09/12] add initial SectionConfig for pbs Stoiko Ivanov
2020-10-19 19:02 ` [pmg-devel] [RFC pmg-api 10/12] Add API2 module for PBS configuration Stoiko Ivanov
2020-10-19 19:02 ` [pmg-devel] [RFC pmg-api 11/12] Add API2 module for per-node backups to PBS Stoiko Ivanov
2020-10-19 19:02 ` [pmg-devel] [RFC pmg-api 12/12] pbs-integration: add CLI calls to pmgbackup Stoiko Ivanov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201019190209.11495-3-s.ivanov@proxmox.com \
--to=s.ivanov@proxmox.com \
--cc=pmg-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox