Skip to content

Commit

Permalink
Add linux_lvm_mountargs option
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
galenseitz committed Dec 13, 2022
1 parent 2fe4779 commit a3437b8
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 4 deletions.
67 changes: 65 additions & 2 deletions rsnapshot-program.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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'};
Expand All @@ -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;
Expand Down Expand Up @@ -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('/',
Expand Down Expand Up @@ -7095,6 +7107,44 @@ =head1 CONFIGURATION
=back
B<linux_lvm_mountargs [args]>
=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<linux_lvm_mountargs -o nouuid>
=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<linux_lvm_mountargs -o ro,nouuid>
=back
This supplies the proper arguments to mount an xfs snapshot in readonly mode.
=back
B<backup> /etc/ localhost/
B<backup> root@example.com:/etc/ example.com/
Expand All @@ -7105,6 +7155,8 @@ =head1 CONFIGURATION
B<backup> lvm://vg0/home/path2/ lvm-vg0/
B<backup> lvm://vg0/home/path2/ lvm-vg0/ linux_lvm_mountargs="-o ro,nouuid"
B<backup_script> /usr/local/bin/backup_pgsql.sh pgsql_backup/
=over 4
Expand Down Expand Up @@ -7199,6 +7251,17 @@ =head1 CONFIGURATION
=back
B<backup> 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<backup_script /usr/local/bin/backup_database.sh db_backup/>
=over 4
Expand Down
14 changes: 12 additions & 2 deletions rsnapshot.conf.default.in
Original file line number Diff line number Diff line change
Expand Up @@ -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@

#########################################
Expand Down Expand Up @@ -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 ###
###############################
Expand All @@ -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"
Expand Down

0 comments on commit a3437b8

Please sign in to comment.