X-Git-Url: https://git.stderr.nl/gitweb?p=matthijs%2Fupstream%2Fbackupninja.git;a=blobdiff_plain;f=handlers%2Ftar.in;h=f75df22e7a124586ed88ffd69f8e91cba6024481;hp=7f0d1471c7a5d8677d169fda490aca15f5b970e5;hb=bb8f89b11dddff700f5696e38f889b77d478c93c;hpb=579ea902ba24854b3c9acb307cda7e996e8e41a3 diff --git a/handlers/tar.in b/handlers/tar.in index 7f0d147..f75df22 100644 --- a/handlers/tar.in +++ b/handlers/tar.in @@ -1,17 +1,18 @@ # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*- +# vim: set filetype=sh sw=3 sts=3 expandtab autoindent: # # tar handler script for backupninja -getconf backupname `hostname --fqdn` -getconf backupdir /var/backups/`hostname --fqdn` -getconf compress bzip -getconf includes "/etc /home /usr/local" -getconf excludes "/tmp /proc /dev /sys /net /misc /media /srv /selinux" +getconf backupname `hostname --fqdn` +getconf backupdir /var/backups/`hostname --fqdn` +getconf compress bzip +getconf includes "/etc /home /usr/local" +getconf excludes "/tmp /proc /dev /sys /net /misc /media /srv /selinux" -getconf TAR `which tar` -getconf EXTENSION tar -getconf DATE `which date` -getconf DATEFORMAT "%Y.%m.%d-%H%M" +getconf TAR `which tar` +getconf EXTENSION tar +getconf DATE `which date` +getconf DATEFORMAT "%Y.%m.%d-%H%M" # See if vservers are configured if [ "$vservers" = "yes" ] @@ -19,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