[pve-devel] [PATCH] Exclude .zfs folder which is located on zfs subvolume.
Wolfgang Link
w.link at proxmox.com
Wed Sep 6 14:57:14 CEST 2017
The .zfs snapdir is usually hidden, but if it is set to "visible", we can back it up.
This increases the amount of backup space and makes restoration impossible.
We will exclude only the .zfs in the root of the mountponit
and in all other volumes which are mounted in the container.
This applies only to zfs volumes.
---
src/PVE/VZDump/LXC.pm | 33 ++++++++++++++++++++++++++++++++-
1 file changed, 32 insertions(+), 1 deletion(-)
diff --git a/src/PVE/VZDump/LXC.pm b/src/PVE/VZDump/LXC.pm
index 45a851c..b8165f7 100644
--- a/src/PVE/VZDump/LXC.pm
+++ b/src/PVE/VZDump/LXC.pm
@@ -16,6 +16,15 @@ use base qw (PVE::VZDump::Plugin);
my $default_mount_point = "/mnt/vzsnap0";
+my $disk_on_zfs = sub {
+ my ($self, $disk) = @_;
+
+ my ($storeid) = PVE::Storage::parse_volume_id($disk->{volume});
+ my $scfg = PVE::Storage::storage_config($self->{storecfg}, $storeid);
+ return $scfg->{type} eq 'zfspool' ? 1 : undef;
+
+};
+
my $rsync_vm = sub {
my ($self, $task, $to, $text, $first) = @_;
@@ -45,9 +54,18 @@ my $rsync_vm = sub {
# directives need to be modified for every command as they are meant to be
# relative to the rootdir, while rsync treats them as relative to the
# source dir.
+ my @sources;
foreach my $disk (@$disks) {
- push @$rsync, "$from/.$disk->{mp}";
+ push @sources, "$from/.$disk->{mp}";
+
+ # exclude snapdir if disk is on zfs
+ if ($self->$disk_on_zfs($disk)) {
+ push @$rsync, $disk->{mp} eq '/' ? "--exclude=/.zfs" : "--exclude=$disk->{mp}/.zfs";
+ }
+
}
+ push @$rsync, @sources;
+
$self->cmd([@$rsync, $to]);
my $delay = time () - $starttime;
@@ -301,6 +319,7 @@ sub archive {
my $disks = $task->{disks};
my @sources;
+ my @exclude_zfs_snapdir;
if ($task->{mode} eq 'stop') {
my $rootdir = $default_mount_point;
@@ -311,6 +330,11 @@ sub archive {
# add every enabled mountpoint (since we use --one-file-system)
# mp already starts with a / so we only need to add the dot
push @sources, ".$disk->{mp}";
+
+ # exclude snapdir if disk is on zfs
+ if ($self->$disk_on_zfs($disk)) {
+ push @exclude_zfs_snapdir, $disk->{mp} eq '/' ? "--exclude=./.zfs" : "--exclude=.$disk->{mp}/.zfs";
+ }
}
$task->{snapdir} = $rootdir;
} elsif ($task->{mode} eq 'snapshot') {
@@ -318,6 +342,12 @@ sub archive {
# but we need to include all mountpoints here!
foreach my $disk (@$disks) {
push @sources, ".$disk->{mp}";
+
+ # exclude snapdir if disk is on zfs
+ if ($self->$disk_on_zfs($disk)) {
+ push @exclude_zfs_snapdir, $disk->{mp} eq '/' ? "--exclude=./.zfs" : "--exclude=.$disk->{mp}/.zfs";
+ }
+
}
} else {
# the data was rsynced to a temporary location, only use '.' to avoid
@@ -350,6 +380,7 @@ sub archive {
push @$tar, '--no-anchored', '--exclude=lost+found' if $userns_cmd;
push @$tar, '--anchored';
push @$tar, map { "--exclude=.$_" } @{$self->{vzdump}->{findexcl}};
+ push @$tar, @exclude_zfs_snapdir;
push @$tar, @sources;
--
2.11.0
More information about the pve-devel
mailing list