[mylvmbackup] xfs_freeze

I think it would be better if we use xfs_freeze while making snapshots,
from the manual.

"xfs_freeze halts new access to the  filesystem  and  creates  a  stable
image  on disk.  xfs_freeze is intended to be used with volume managers
and hardware RAID devices that support the creation of snapshots."

This is a patch which adds support for xfs_freeze, I wasn't sure how to
work out the data location from the other options so I added dataroot as
an option as well although xfs_freeze works if you supply a file on the
filesystem and not just the mount point, it wouldn't work if mysql was
spread accross multiple filesystems. Just a sugggestion anyway.


--- /usr/bin/mylvmbackup        2007-11-03 10:58:09.000000000 +0000
+++ /usr/bin/mylvmbackup        2007-11-28 11:22:16.157973270 +0000
@@ -73,6 +73,8 @@
 my $syslog_socktype;
 my $syslog_facility;
 my $syslog_remotehost;
+my $xfs_freeze ;
+my $dataroot ;
 
 # Load defaults into variables
 load_defaults();
@@ -267,6 +269,7 @@
   $tararg=$cfg->val ('misc', 'tararg', $tararg);
   $tarsuffixarg=$cfg->val ('misc', 'tarsuffixarg', $tarsuffixarg);
   $tarfilesuffix = $cfg->val ('misc', 'tarfilesuffix', $tarfilesuffix);
+  $dataroot=$cfg->val ('misc', 'dataroot', $dataroot );
 
   $mountdir=$cfg->val ('fs', 'mountdir', $mountdir);
   $backupdir=$cfg->val ('fs', 'backupdir', $backupdir);
@@ -280,6 +283,7 @@
   $umount=$cfg->val ('tools', 'umount', $umount);
   $tar=$cfg->val ('tools', 'tar', $tar);
   $rsync=$cfg->val ('tools', 'rsync', $rsync);
+  $xfs_freeze=$cfg->val ('tools', 'xfs_freeze', $xfs_freeze );
 
   $log_method = $cfg->val('logging', 'log_method', $log_method);
   $syslog_socktype = $cfg->val ('logging', 'syslog_socktype', 
$syslog_socktype);
@@ -322,6 +326,7 @@
     "tarsuffixarg=s" => \$tarsuffixarg,
     "tarfilesuffix=s" => \$tarfilesuffix,
     "rsyncarg=s" => \$rsyncarg,
+    "dataroot=s" => \$dataroot,
 
 # fs
     "mountdir=s" => \$mountdir,
@@ -336,7 +341,8 @@
     "mount=s" => \$mount,
     "umount=s" => \$umount,
     "tar=s" => \$tar,
-    "rsync=s" => \$rsync,
+    "rsync=s" => \$rsync, 
+    "xfs_freeze=s" => \$xfs_freeze,
 
 # logging
     "log_method=s" => \$log_method,
@@ -376,6 +382,7 @@
   $tarsuffixarg='';
   $tarfilesuffix='.tar.gz';
   $rsyncarg='-avPW';
+  $dataroot='/mysql' ;
 
 # fs
   $mountdir='/var/cache/mylvmbackup/mnt/';
@@ -391,6 +398,7 @@
   $umount='umount';
   $tar='tar';
   $rsync='rsync';
+  $xfs_freeze='xfs_freeze' ;
 
 # logging
   $log_method = 'console';
@@ -509,9 +517,18 @@
 
 sub create_snapshot 
 { 
+  if ( $need_xfsworkaround ) 
+    {
+     system ( "$xfs_freeze -f $dataroot" ) ;
+    } 
+  
   $snapshot_created=1 if 
    ( system("$lvcreate",'-s',"--size=$lvsize",
             "--name=$backuplv","/dev/$vgname/$lvname") == 0); 
+  if ( $need_xfsworkaround ) 
+    {
+     system ( "$xfs_freeze -u $dataroot" ) ;
+    }
   log_msg ("Cannot create snapshot: $!", LOG_ERR) unless $snapshot_created eq 
1;
   return $snapshot_created;
 }

Other related posts: