#! /bin/sh /usr/share/dpatch/dpatch-run ## 05_add_keep_mount.dpatch by ## ## All lines beginning with `## DP:' are a description of the patch. ## DP: No description. @DPATCH@ diff -urNad mylvmbackup-0.11~/man/mylvmbackup.pod mylvmbackup-0.11/man/mylvmbackup.pod --- mylvmbackup-0.11~/man/mylvmbackup.pod 2009-02-26 16:19:49.000000000 +0100 +++ mylvmbackup-0.11/man/mylvmbackup.pod 2009-02-26 16:19:50.000000000 +0100 @@ -291,6 +291,13 @@ before terminating. Note that keeping multiple LVM snapshots open at the same time can reduce I/O performance. +=item B<--keep_mount> + +If this option is given, mylvmbackup will not remove the mounted +partitions and the bindmount before terminating. This option also +implies I, since it's kinda unusable if the snapshot +is removed. + =item B<--relpath=string> Relative path on the logical volume to the MySQL data directory. diff -urNad mylvmbackup-0.11~/mylvmbackup.conf mylvmbackup-0.11/mylvmbackup.conf --- mylvmbackup-0.11~/mylvmbackup.conf 2009-02-26 16:19:49.000000000 +0100 +++ mylvmbackup-0.11/mylvmbackup.conf 2009-02-26 16:19:50.000000000 +0100 @@ -87,6 +87,7 @@ hooksdir=/usr/share/mylvmbackup skip_hooks=0 keep_snapshot=0 +keep_mount=0 quiet=0 # diff -urNad mylvmbackup-0.11~/mylvmbackup.pl.in mylvmbackup-0.11/mylvmbackup.pl.in --- mylvmbackup-0.11~/mylvmbackup.pl.in 2009-02-26 16:19:49.000000000 +0100 +++ mylvmbackup-0.11/mylvmbackup.pl.in 2009-02-26 16:20:35.000000000 +0100 @@ -47,6 +47,7 @@ my $skip_mycnf; my $extra_flush_tables; my $keep_snapshot; +my $keep_mount; my $lvcreate; my $lvname; my $lvremove; @@ -85,6 +86,7 @@ my $syslog_remotehost; my $running_backup; my $defaults_file; +my $tmp_cleanup; # Load defaults into variables load_defaults(); @@ -134,7 +136,14 @@ my $topmountdir = $mountdir; -my $posbasedir = tempdir('mylvmbackup-'.$fullprefix.'-XXXXXX', TMPDIR => 1, CLEANUP => 1); +# Don't try to remove the temporary directory when we want to keep the mounts. +unless ($keep_mount) { + $tmp_cleanup = 1; +} else { + $tmp_cleanup = 0; +} + +my $posbasedir = tempdir('mylvmbackup-'.$fullprefix.'-XXXXXX', TMPDIR => 1, CLEANUP => $tmp_cleanup); my $posdir = $posbasedir.'/pos'; mkdir $posdir; @@ -289,6 +298,7 @@ $hooksdir = $cfg->val ('misc', 'hooksdir', $hooksdir); $skip_hooks=$cfg->val ('misc', 'skip_hooks', $skip_hooks); $keep_snapshot=$cfg->val ('misc', 'keep_snapshot', $keep_snapshot); + $keep_mount=$cfg->val ('misc', 'keep_mount', $keep_mount); $quiet=$cfg->val ('misc', 'quiet', $quiet); $mountdir=$cfg->val ('fs', 'mountdir', $mountdir); @@ -355,6 +365,7 @@ "hooksdir=s" => \$hooksdir, "skip_hooks" => \&skip_hooks, "keep_snapshot" => \&keep_snapshot, + "keep_mount" => \&keep_mount, "quiet" => \&quiet, # fs @@ -420,6 +431,7 @@ $hooksdir='/usr/share/mylvmbackup'; $skip_hooks=0; $keep_snapshot=0; + $keep_mount=0; $quiet=0; # fs @@ -702,15 +714,19 @@ { run_hook("precleanup"); log_msg ("Cleaning up...", LOG_INFO); - system("$umount $mountdir") if ($mounted); - system("$umount $posmountdir") if ($posmounted); - unlink $pos_filename; - unlink $mycnf_filename; - if ($posmountdir) { - rmdir $mountdir; - rmdir $posmountdir; + unless ($keep_mount) { + system("$umount $mountdir") if ($mounted); + system("$umount $posmountdir") if ($posmounted); + unlink $pos_filename; + unlink $mycnf_filename; + if ($posmountdir) { + rmdir $mountdir; + rmdir $posmountdir; + } + rmdir $posdir; + } else { + log_msg("Not removing mount as requested by configuration", LOG_INFO); } - rmdir $posdir; if (-e "/dev/$vgname/$backuplv") { my @lvs_info = `$lvs /dev/$vgname/$backuplv`; chomp (@lvs_info); @@ -721,7 +737,7 @@ } if ($snapshot_created) { - unless ($keep_snapshot) { + unless ($keep_snapshot || $keep_mount) { system("$lvremove -f /dev/$vgname/$backuplv"); } else { log_msg("Not removing snapshot as requested by configuration", LOG_INFO); @@ -749,6 +765,10 @@ $keep_snapshot = 1; } +sub keep_mount { + $keep_mount = 1; +} + sub quiet { $quiet = 1; }