From a3437b8cdc66fbc0718b4fb4f54d8a6f3979dda8 Mon Sep 17 00:00:00 2001 From: Galen Seitz Date: Wed, 21 Feb 2018 21:53:39 -0800 Subject: [PATCH] Add linux_lvm_mountargs option In order to allow backups of Linux LVM logical volumes containing a mix of xfs and non-xfs filesystems, it is necessary to have the ability to pass options to the mount command. This commit adds a linux_lvm_mountargs config variable. --- rsnapshot-program.pl | 67 +++++++++++++++++++++++++++++++++++++-- rsnapshot.conf.default.in | 14 ++++++-- 2 files changed, 77 insertions(+), 4 deletions(-) diff --git a/rsnapshot-program.pl b/rsnapshot-program.pl index 5b7ed64b..c9b80797 100755 --- a/rsnapshot-program.pl +++ b/rsnapshot-program.pl @@ -1411,7 +1411,7 @@ sub parse_config_file { } # LVM ARGS - if ($var =~ m/^linux_lvm_(vgpath|snapshotname|snapshotsize|mountpath)$/) { + if ($var =~ m/^linux_lvm_(vgpath|snapshotname|snapshotsize|mountpath|mountargs)$/) { $config_vars{$var} = $value; $line_syntax_ok = 1; next; @@ -1835,7 +1835,7 @@ sub parse_backup_opts { # lvm args } - elsif ($name =~ m/^linux_lvm_(vgpath|snapshotname|snapshotsize|mountpath)$/) { + elsif ($name =~ m/^linux_lvm_(vgpath|snapshotname|snapshotsize|mountpath|mountargs)$/) { # pass unchecked @@ -3775,7 +3775,12 @@ sub rsync_backup_point { $lvm_opts{'snapshotname'} = $config_vars{'linux_lvm_snapshotname'}; $lvm_opts{'vgpath'} = $config_vars{'linux_lvm_vgpath'}; $lvm_opts{'mountpath'} = $config_vars{'linux_lvm_mountpath'}; + # Mount args are optional. + if (defined($config_vars{'linux_lvm_mountargs'})) { + $lvm_opts{'mountargs'} = $config_vars{'linux_lvm_mountargs'}; + } + # Allow backup point option to override config variable value. if (defined($$bp_ref{'opts'})) { if (defined($$bp_ref{'opts'}->{'linux_lvm_snapshotsize'})) { $lvm_opts{'snapshotsize'} = $$bp_ref{'opts'}->{'linux_lvm_snapshotsize'}; @@ -3789,6 +3794,9 @@ sub rsync_backup_point { if (defined($$bp_ref{'opts'}->{'linux_lvm_mountpath'})) { $lvm_opts{'mountpath'} = $$bp_ref{'opts'}->{'linux_lvm_mountpath'}; } + if (defined($$bp_ref{'opts'}->{'linux_lvm_mountargs'})) { + $lvm_opts{'mountargs'} = $$bp_ref{'opts'}->{'linux_lvm_mountargs'}; + } } $lvm_src = $src; @@ -4093,6 +4101,10 @@ sub linux_lvm_mount { my @cmd_stack = (); push(@cmd_stack, split(' ', $config_vars{'linux_lvm_cmd_mount'})); + if (defined($$opts_ref{'mountargs'})) { + push(@cmd_stack, split(' ', $$opts_ref{'mountargs'})); + } + push( @cmd_stack, join('/', @@ -7095,6 +7107,44 @@ =head1 CONFIGURATION =back +B + +=over 4 + +Arguments to be used when temporarily mounting the LVM snapshot(s). This +can be used supply any special mount options that may be needed. For +example, when mounting a snapshot of an xfs filesystem, it is necessary +to use the nouuid mount option. + +=over 4 + +Example: + +B + +=back + +This allows snapshots of xfs filesystems to be properly mounted. If LVM +snapshots are being used with a mix of xfs and non-xfs filesystems, the +linux_lvm_mountargs option can be set on a per-backup-point basis. The +backup point option will override the config value. + +It is also common to mount the snapshot readonly. This can be done by +specifying the readonly argument when defining linux_lvm_cmd_mount, or by +specifying it in linux_lvm_mountargs. + +=over 4 + +Example: + +B + +=back + +This supplies the proper arguments to mount an xfs snapshot in readonly mode. + +=back + B /etc/ localhost/ B root@example.com:/etc/ example.com/ @@ -7105,6 +7155,8 @@ =head1 CONFIGURATION B lvm://vg0/home/path2/ lvm-vg0/ +B lvm://vg0/home/path2/ lvm-vg0/ linux_lvm_mountargs="-o ro,nouuid" + B /usr/local/bin/backup_pgsql.sh pgsql_backup/ =over 4 @@ -7199,6 +7251,17 @@ =head1 CONFIGURATION =back +B lvm://vg0/home/path2/ lvm-vg0/ linux_lvm_mountargs="-o ro,nouuid" + +=over 4 + +Backs up the LVM logical volume as in the previous example, but when the +LVM snapshot is mounted, "-o ro,nouuid" will be used as an argument to the +mount command. + +=back + + B =over 4 diff --git a/rsnapshot.conf.default.in b/rsnapshot.conf.default.in index efccbdd9..b46289a5 100644 --- a/rsnapshot.conf.default.in +++ b/rsnapshot.conf.default.in @@ -77,11 +77,13 @@ snapshot_root /.snapshots/ #cmd_postexec /path/to/postexec/script # Paths to lvcreate, lvremove, mount and umount commands, for use with -# Linux LVMs. +# Linux LVMs. If necessary, you can add arguments to any of the commands. +# The example -r argument shown on the mount command will cause all +# LVM snapshot mounts to be readonly. # #linux_lvm_cmd_lvcreate @CMD_LVCREATE@ #linux_lvm_cmd_lvremove @CMD_LVREMOVE@ -#linux_lvm_cmd_mount @CMD_MOUNT@ +#linux_lvm_cmd_mount @CMD_MOUNT@ -r #linux_lvm_cmd_umount @CMD_UMOUNT@ ######################################### @@ -218,6 +220,11 @@ lockfile /var/run/rsnapshot.pid # #linux_lvm_mountpath /path/to/mount/lvm/snapshot/during/backup +# Arguments to the mount command used to temporarily mount the snapshot(s). +# You may need to define this when you use xfs filesystems. +# +#linux_lvm_mountargs -o nouuid + ############################### ### BACKUP POINTS / SCRIPTS ### ############################### @@ -233,6 +240,9 @@ backup /usr/local/ localhost/ #backup_script /usr/local/bin/backup_pgsql.sh localhost/postgres/ # You must set linux_lvm_* parameters below before using lvm snapshots #backup lvm://vg0/xen-home/ lvm-vg0/xen-home/ +# You can override LVM options as needed. Use quotes if your option needs to +# contain a comma. +#backup lvm://vg0/xen-home/ lvm-vg0/xen-home/ linux_lvm_mountargs="-o ro,nouuid",linux_lvm_snapshotsize=1G # EXAMPLE.COM #backup_exec /bin/date "+ backup of example.com started at %c"