← Back to team overview

mylvmbackup-discuss team mailing list archive

suggested new mode: snapshot only

 

when using normal backup software (simply doing backups of visible files
on the host), it's a bit wasteful to make a tar file of the MySQL data.
the backup software is happy to read the files directly from the
snapshot without any extra steps.  so I wrote a small patch which allows
two new backuptypes: "snapshot" and "release".

(the *practical* meaning of mountdir becomes backupdir, as this mode
doesn't put anything in backupdir)

in Bacula, usage is:

  RunScript {
    RunsWhen = Before
    AbortJobOnError = yes
    Command = "mylvmbackup --backuptype=snapshot"
  }
  RunScript {
    RunsWhen = After
    Command = "mylvmbackup --backuptype=release"
  }

I hope this feature can be integrated upstream.

(the odd filenames in the diff are due to us distributing mylvmbackup as
part of our SVN controlled Puppet configuration :-)
-- 
Kjetil T. Homme
Redpill Linpro AS - Changing the game
Index: modules/mysql/files/mylvmbackup
===================================================================
--- modules/mysql/files/mylvmbackup	(revision 10423)
+++ modules/mysql/files/mylvmbackup	(working copy)
@@ -129,7 +129,7 @@
 $backupdir = clean_dirname($backupdir);
 
 # Validate the existence of a prefix
-die "You must specify a non-empty prefix to name your backup!\n" unless ($prefix ne "");
+die "You must specify a non-empty prefix to name your backup!\n" if ($prefix eq "");
 
 $backuplv = $lvname.'_snapshot' if length($backuplv) == 0;
 my $date = time2str($datefmt, time);
@@ -137,9 +137,11 @@
 
 my $topmountdir = $mountdir;
 
-my $posbasedir = tempdir('mylvmbackup-'.$fullprefix.'-XXXXXX', TMPDIR => 1, CLEANUP => 1);
+my $posbasedir = tempdir('mylvmbackup-'.$fullprefix.'-XXXXXX',
+                         TMPDIR => 1,
+                         CLEANUP => $backuptype ne "snapshot");
 my $posdir = $posbasedir.'/pos';
-mkdir $posdir;
+mkdir $posdir || log_msg("mkdir $posdir: $!", LOG_ERR);
 
 my $pos_filename = $posdir.'/'.$fullprefix.'.pos';
 my $mycnf_basename = File::Basename::basename($mycnf);
@@ -164,6 +166,40 @@
 my $posmountdir = $mountdir;
 $posmountdir .= '-pos'; # Notice that we do not add a slash.
 
+if ($backuptype eq 'release')
+{
+  $snapshot_created = -e "/dev/$vgname/$backuplv";
+  my $tempdir;
+  my $mapper_name = $backuplv;
+  $mapper_name =~ s/-/--/g;
+  $mapper_name = "mapper/$vgname-$mapper_name";
+  if (open(my $mountfd, "$mount|")) {
+    while (<$mountfd>) {
+      if (m:^/dev/($vgname/$backuplv|$mapper_name)\s:) {
+        log_msg ("found mounted LV", LOG_INFO);
+        $mounted = 1;
+      } elsif (m:(.*?) on $posmountdir:) {
+        log_msg ("found pos mounted $1", LOG_INFO);
+        $tempdir = $1;
+        $posmounted = 1;
+      }
+    }
+    close($mountfd);
+  }
+  cleanup();
+
+  # A bit of a hack, removing the temporary files created by the
+  # previous invocation.
+  if ($tempdir) {
+      system("rm -f $tempdir/$prefix-*_mysql_my.cnf $tempdir/$prefix-*_mysql.pos");
+      rmdir($tempdir);
+      $tempdir =~ s:[^/]*$::;
+      rmdir($tempdir);
+  }
+  exit(0);
+}
+
+
 # Now create it
 mkdir $mountdir;
 mkdir $posmountdir;
@@ -246,6 +282,9 @@
   do_backup_rsync();
 } elsif ($backuptype eq 'rsnap') {
   do_backup_rsnap();
+} elsif ($backuptype eq 'snapshot') {
+  $keep_snapshot = 1;
+  do_backup_none();
 } else {
   do_backup_none();
 }
@@ -690,6 +729,10 @@
 {
   run_hook("precleanup");
   log_msg ("Cleaning up...", LOG_INFO);
+  if ($backuptype eq "snapshot") {
+    log_msg ("Leaving snapshot mounted", LOG_INFO);
+    return;
+  }
   system("$umount $mountdir") if ($mounted);
   system("$umount $posmountdir") if ($posmounted);
   unlink $pos_filename;

Follow ups