[pve-devel] [PATCH 2/3] Change backup dir structure.
Wolfgang Link
w.link at proxmox.com
Tue Aug 25 13:24:52 CEST 2015
This is necessary, because we want use ro snapshots and can't write to it.
---
src/PVE/VZDump/LXC.pm | 39 ++++++++++++++++++++++++---------------
1 file changed, 24 insertions(+), 15 deletions(-)
diff --git a/src/PVE/VZDump/LXC.pm b/src/PVE/VZDump/LXC.pm
index eb43807..4ee0e7c 100644
--- a/src/PVE/VZDump/LXC.pm
+++ b/src/PVE/VZDump/LXC.pm
@@ -10,9 +10,12 @@ use PVE::Storage;
use PVE::VZDump;
use PVE::LXC;
use PVE::Tools;
+use File::Path;
use base qw (PVE::VZDump::Plugin);
+my $mountpointdir = '/mnt/';
+
my $rsync_vm = sub {
my ($self, $task, $from, $to, $text) = @_;
@@ -106,6 +109,8 @@ sub prepare {
my $rootinfo = PVE::LXC::parse_ct_mountpoint($conf->{rootfs});
my $volid = $rootinfo->{volume};
+ my $mountpoint = $mountpointdir.$vmid."/rootfs";
+
# fixme: when do we deactivate ??
PVE::Storage::activate_volumes($self->{storecfg}, [$volid]) if $volid;
@@ -125,7 +130,7 @@ sub prepare {
# library dos not handle mount/unmount of snapshots
if ($scfg->{type} ne 'zfs') {
- $diskinfo->{mountpoint} = "/mnt/vzsnap0";
+ $diskinfo->{mountpoint} = $mountpoint;
} else {
die "mode failure - storage does not support snapshot mount\n"
}
@@ -138,10 +143,10 @@ sub prepare {
} else {
if ($mode eq 'stop') {
- my $mountpoint = "/mnt/vzsnap0";
+
my $path = PVE::Storage::path($self->{storecfg}, $volid);
&$loop_mount_image($path, $mountpoint);
- $task->{cleanup}->{snapshot_mount} = 1;
+ $task->{cleanup}->{snapshot_mount} = $mountpoint;
$diskinfo->{dir} = $diskinfo->{mountpoint} = $mountpoint;
} elsif ($mode eq 'suspend') {
my $tasks_fn = "/sys/fs/cgroup/cpu/lxc/$vmid/tasks";
@@ -217,15 +222,16 @@ sub assemble {
my $dir = $task->{snapdir};
- $task->{cleanup}->{etc_vzdump} = 1;
-
- mkpath "$dir/etc/vzdump/";
+ my $conf_dir = $mountpointdir.$vmid."/etc/vzdump/";
+ File::Path::make_path($conf_dir);
my $conf = PVE::LXC::load_config($vmid);
delete $conf->{snapshots};
delete $conf->{'pve.parent'};
- PVE::Tools::file_set_contents("$dir/etc/vzdump/pct.conf", PVE::LXC::write_pct_config("/lxc/$vmid.conf", $conf));
+ PVE::Tools::file_set_contents("$conf_dir/pct.conf",
+ PVE::LXC::write_pct_config("/lxc/$vmid.conf",
+ $conf))
}
sub archive {
@@ -251,7 +257,11 @@ sub archive {
my $cmd = "(";
$cmd .= "cd $snapdir;find . $findargs|sed 's/\\\\/\\\\\\\\/g'|";
- $cmd .= "tar cpf - $taropts ./etc/vzdump/pct.conf --null -T -";
+ $cmd .= "tar cpf - $taropts ";
+ # The directory parameter can give a alternative directory as source.
+ # the second parameter gives the structure in the tar.
+ $cmd .= "--directory=".$mountpointdir.$vmid." ./etc/vzdump/pct.conf ";
+ $cmd .= "--directory=$snapdir --null -T -";
my $bwl = $opts->{bwlimit}*1024; # bandwidth limit for cstream
$cmd .= "|cstream -t $bwl" if $opts->{bwlimit};
$cmd .= "|$comp" if $comp;
@@ -276,19 +286,18 @@ sub cleanup {
# for example when we stop the tar with kill (stop task)
# We use -d to automatically free used loop devices
sleep(1);
- $self->cmd_noerr("umount -d $di->{mountpoint}");
- File::Path::remove_tree($di->{mountpoint});
+ $self->cmd_noerr("umount -d $task->{cleanup}->{snapshot_mount}");
+ File::Path::remove_tree($task->{cleanup}->{snapshot_mount});
}
if (my $volid = $task->{cleanup}->{snap_volid}) {
eval { PVE::Storage::volume_snapshot_delete($self->{storecfg}, $volid, '__vzdump__'); };
warn $@ if $@;
}
-
- if ($task->{cleanup}->{etc_vzdump}) {
- my $dir = "$task->{snapdir}/etc/vzdump";
- eval { rmtree $dir if -d $dir; };
- $self->logerr ($@) if $@;
+
+ if ( -d $mountpointdir.$vmid) {
+ eval { File::Path::remove_tree($mountpointdir.$vmid); };
+ self->logerr ($@) if $@;
}
}
--
2.1.4
More information about the pve-devel
mailing list