Patch to support dar_manager catalogues

Steven Clark <[email protected]> Sun, 16 Jan 2005 06:53:50 -0500
Newsgroups gmane.comp.sysutils.backup.sarab
Message-ID <[email protected]>
--Boundary_(ID_9Ne28i24P3w81BAOor07pw)
Content-type: text/plain; CHARSET=US-ASCII
Content-transfer-encoding: 7BIT

Hello everyone,

I started playing around with sarab tonight and I liked what I saw. I
have implemented a feature so that sarab can manage catalogue files
using dar_manager. 

I am attaching the patches in case anyone is interested in playing
around with this, they are against released version sarab-0.2.2. It
hasn't been tested extensively yet but it seems to work for me... 

-Steve 



--Boundary_(ID_9Ne28i24P3w81BAOor07pw)
Content-type: text/x-patch; name=sarab.conf.patch; charset=us-ascii
Content-transfer-encoding: 7BIT
Content-disposition: attachment; filename=sarab.conf.patch

--- sarab.conf.old	2005-01-16 06:24:33.592004248 -0500
+++ sarab.conf	2005-01-16 06:26:27.845635056 -0500
@@ -14,6 +14,9 @@
 # Default="rotation.schedule"
 ROTATION_SCHEDULE="rotation.schedule"
 
+# Name of the catalogue file to use with dar_manager 
+CATALOGUE="catalogue"
+
 # Root directory where backups will be created and stored 
 # Note: Use the rotation.schedule file to specify the names of virtual tapes
 # Default="/mnt/backup/"
@@ -32,6 +35,9 @@
 # The email address that will receive notices (see above)
 EMAIL_ADDRESS="root@$HOSTNAME"
 
+# Update the catalogue upon backup create/removal?
+USE_DAR_MANAGER="yes"
+
 # Should SaraB include the statically-compiled DAR executable file with every archive?
 # This file can be used to restore the archive on any system.  (Size: ~1 MB)
 # Choose "yes" or "no"
@@ -70,6 +76,9 @@
 # The location of the DAR executable file
 DAR_BINARY="/usr/bin/dar"
 
+# The location of the DAR MANAGER executable file
+DAR_MANAGER="/usr/bin/dar_manager"
+
 # The location of the statically-compiled DAR executable file
 DAR_STATIC="/usr/bin/dar_static"
 

--Boundary_(ID_9Ne28i24P3w81BAOor07pw)
Content-type: text/x-patch; name=sarab.sh.patch; charset=us-ascii
Content-transfer-encoding: 7BIT
Content-disposition: attachment; filename=sarab.sh.patch

--- sarab.sh.old	2005-01-15 18:52:13.000000000 -0500
+++ sarab.sh	2005-01-16 06:21:57.226775376 -0500
@@ -232,7 +232,21 @@
    fi
 fi
 
-verbose
+# Test to make sure the catalogue file exists if they want us to use it
+if [ $USE_DAR_MANAGER = "yes" ] && [ ! -f "$SARAB_ETC/$CATALOGUE" ]; then
+   echo 
+   echo -n "Creating new catalogue..."
+   verbose
+   verbose "Catalogue file does not exist, creating it..."
+   verbose "$DAR_MANAGER --create $SARAB_ETC/$CATALOGUE"
+   $DAR_MANAGER --create "$SARAB_ETC/$CATALOGUE"
+   if [ "$?" != "0" ]; then
+      echo "ERROR: Failed to create catalogue file. The attempted command was..."
+      echo "$DAR_MANAGER --create $SARAB_ETC/$CATALOGUE"
+      exit 1
+   fi
+fi
+
 # Remove the old backup with the same name, if it exists
 if [ -d "$DESTINATION/$CURRENT_ARCHIVE/" ]; then
    verbose "Removing old backup files..."
@@ -250,9 +264,33 @@
       echo "rmdir -f $DESTINATION/$CURRENT_ARCHIVE/ "
       exit 1
    fi
+
+   if [ $USE_DAR_MANAGER = "yes" ]; then
+      # We need to go through the catalog and delete by path 
+      # Since dar_manager reorders its archive numbers after every deletion we have to
+      # reexecute after every deletion to get the updated numbers...
+      verbose "Searching for existing backups in catalogue to delete..."
+      while [ 1 ]; do
+          i=$( $DAR_MANAGER -B $SARAB_ETC/$CATALOGUE -l | grep "\W$DESTINATION/$CURRENT_ARCHIVE\W" | cut -f 2)
+          if [ -n "$i" ]; then 
+             i=$( echo $i | cut -f 1 -d" ")
+             verbose "Deleting record number $i from catalogue..."
+             verbose "$DAR_MANAGER -B $SARAB_ETC/$CATALOGUE --delete $i"
+             $DAR_MANAGER -B $SARAB_ETC/$CATALOGUE --delete $i
+             if [ "$?" != "0" ]; then
+                echo "ERROR: Failed to delete catalogue record number $i. The attempted command was..."
+                echo "$DAR_MANAGER -B $SARAB_ETC/$CATALOGUE --delete $i"
+                exit 1
+             fi
+          else 
+             break
+          fi
+      done
+   fi
 fi   
 
 # Create an empty directory to move the archive into
+verbose
 verbose "Creating virtual-tape directory... mkdir $DESTINATION/$CURRENT_ARCHIVE/"
 mkdir $DESTINATION/$CURRENT_ARCHIVE/
 
@@ -266,6 +304,21 @@
    exit 1
 fi
 
+# Update catalogue with new file
+if [ $USE_DAR_MANAGER = "yes" ]; then
+   # Add to the catalog the new backup
+   echo
+   echo -n "Adding backup to catalogue"
+   verbose
+   verbose "$DAR_MANAGER -B $SARAB_ETC/$CATALOGUE --add $DESTINATION/$CURRENT_ARCHIVE/$BASENAME"
+   $DAR_MANAGER -B $SARAB_ETC/$CATALOGUE --add $DESTINATION/$CURRENT_ARCHIVE/$BASENAME
+   if [ "$?" != "0" ]; then
+      echo "ERROR: Error when adding file to catalogue. The attempted command was..."
+      echo "$DAR_MANAGER -B $SARAB_ETC/$CATALOGUE --add $DESTINATION/$CURRENT_ARCHIVE/$BASENAME"
+      exit 1
+   fi
+fi
+
 # Copy the statically-compiled DAR executable with the arhive
 if [ "$COPY_DAR" = "yes" ]; then
    if [ -f "$DAR_STATIC" ]; then

--Boundary_(ID_9Ne28i24P3w81BAOor07pw)--


-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues
Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt