tar: Move the main code into a make_backup function.
authorMatthijs Kooijman <matthijs@stdin.nl>
Fri, 19 Mar 2010 15:18:27 +0000 (16:18 +0100)
committerMatthijs Kooijman <matthijs@stdin.nl>
Fri, 19 Mar 2010 20:41:05 +0000 (21:41 +0100)
handlers/tar.in

index b4f8c58bea31847dae357ed18ea1acf8328043c1..f75df22e7a124586ed88ffd69f8e91cba6024481 100644 (file)
@@ -20,61 +20,63 @@ then
    warning "vservers enabled, but tar does not support it!"
 fi
 
-if [ ! -d "$backupdir" ]
-then
-   mkdir -p "$backupdir" || fatal "Can not make directory $backupdir"
-fi
+function make_backup () {
+   if [ ! -d "$backupdir" ]
+   then
+      mkdir -p "$backupdir" || fatal "Can not make directory $backupdir"
+   fi
 
-if [ ! -w "$backupdir" ]
-then
-   fatal "Directory $backupdir is not writable"
-fi
-
-## DO IT #################################################
-#
-# here we grab a list of the packages installed and removed.
-#
+   if [ ! -w "$backupdir" ]
+   then
+      fatal "Directory $backupdir is not writable"
+   fi
 
-case $compress in
-   "compress")
-      compress_option="-Z"
-      EXTENSION="tar.compress"
-      ;;
-   "gzip")
-      compress_option="-z"
-      EXTENSION="tgz"
-      ;;
-   "bzip")
-      compress_option="-j"
-      EXTENSION="tar.bz2"
-      ;;
-   "none")
-      compress_option=""
-      ;;
-   *)
-      warning "Unknown compress filter ($tar_compress)"
-      compress_option=""
-      EXTENSION="tgz"
-      ;;
-esac
+   ## DO IT #################################################
+   #
+   # here we grab a list of the packages installed and removed.
+   #
 
-exclude_options=""
-for i in $excludes
-do
-   exclude_options="$exclude_options --exclude $i"
-done
+   case $compress in
+      "compress")
+         compress_option="-Z"
+         EXTENSION="tar.compress"
+         ;;
+      "gzip")
+         compress_option="-z"
+         EXTENSION="tgz"
+         ;;
+      "bzip")
+         compress_option="-j"
+         EXTENSION="tar.bz2"
+         ;;
+      "none")
+         compress_option=""
+         ;;
+      *)
+         warning "Unknown compress filter ($tar_compress)"
+         compress_option=""
+         EXTENSION="tgz"
+         ;;
+   esac
 
-debug "Running backup: " $TAR -c -p -v $compress_option $exclude_options \
-   -f "$backupdir/$backupname-"`$DATE "+$DATEFORMAT"`".$EXTENSION" \
-   $includes
+   exclude_options=""
+   for i in $excludes
+   do
+      exclude_options="$exclude_options --exclude $i"
+   done
 
-$TAR -c -p -v $compress_option $exclude_options \
-   -f "$backupdir/$backupname-"`$DATE "+$DATEFORMAT"`".$EXTENSION" \
-   $includes \
-   > "$backupdir/$backupname-"`$DATE "+$DATEFORMAT"`.list \
-   2> "$backupdir/$backupname-"`$DATE "+$DATEFORMAT"`.err
+   debug "Running backup: " $TAR -c -p -v $compress_option $exclude_options \
+      -f "$backupdir/$backupname-"`$DATE "+$DATEFORMAT"`".$EXTENSION" \
+      $includes
 
-[ $? -ne 0 ] && fatal "Tar backup failed"
+   $TAR -c -p -v $compress_option $exclude_options \
+      -f "$backupdir/$backupname-"`$DATE "+$DATEFORMAT"`".$EXTENSION" \
+      $includes \
+      > "$backupdir/$backupname-"`$DATE "+$DATEFORMAT"`.list \
+      2> "$backupdir/$backupname-"`$DATE "+$DATEFORMAT"`.err
 
+   [ $? -ne 0 ] && fatal "Tar backup failed"
 
+}
 
+make_backup