2006-04-12 23:17:06 +02:00
|
|
|
# -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
|
2009-05-22 15:27:09 +02:00
|
|
|
# vim: set filetype=sh sw=3 sts=3 expandtab autoindent:
|
2006-04-12 23:17:06 +02:00
|
|
|
#
|
|
|
|
# tar handler script for backupninja
|
|
|
|
|
2009-05-22 14:50:52 +02:00
|
|
|
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"
|
2006-04-12 23:17:06 +02:00
|
|
|
|
2009-05-22 14:50:52 +02:00
|
|
|
getconf TAR `which tar`
|
|
|
|
getconf EXTENSION tar
|
|
|
|
getconf DATE `which date`
|
|
|
|
getconf DATEFORMAT "%Y.%m.%d-%H%M"
|
2006-04-12 23:17:06 +02:00
|
|
|
|
|
|
|
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.
|
|
|
|
#
|
|
|
|
|
|
|
|
case $compress in
|
|
|
|
"compress")
|
|
|
|
compress_option="-Z"
|
|
|
|
EXTENSION="tar.compress"
|
|
|
|
;;
|
|
|
|
"gzip")
|
|
|
|
compress_option="-z"
|
|
|
|
EXTENSION="tgz"
|
|
|
|
;;
|
|
|
|
"bzip")
|
|
|
|
compress_option="-j"
|
|
|
|
EXTENSION="tar.bz2"
|
|
|
|
;;
|
2013-06-27 21:36:23 +02:00
|
|
|
"xz")
|
|
|
|
compress_option="-J"
|
|
|
|
EXTENSION="tar.xz"
|
|
|
|
;;
|
2021-01-02 19:32:15 +01:00
|
|
|
"zstd")
|
|
|
|
compress_option="--zstd"
|
|
|
|
EXTENSION="tar.zst"
|
|
|
|
;;
|
2006-04-12 23:17:06 +02:00
|
|
|
"none")
|
|
|
|
compress_option=""
|
|
|
|
;;
|
|
|
|
*)
|
2021-01-02 19:30:30 +01:00
|
|
|
warning "Unknown compress filter ($compress), defaulting to gzip"
|
|
|
|
compress_option="-z"
|
2006-04-12 23:17:06 +02:00
|
|
|
EXTENSION="tgz"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
exclude_options=""
|
|
|
|
for i in $excludes
|
|
|
|
do
|
|
|
|
exclude_options="$exclude_options --exclude $i"
|
|
|
|
done
|
|
|
|
|
|
|
|
debug "Running backup: " $TAR -c -p -v $compress_option $exclude_options \
|
|
|
|
-f "$backupdir/$backupname-"`$DATE "+$DATEFORMAT"`".$EXTENSION" \
|
2009-05-22 14:50:52 +02:00
|
|
|
$includes
|
2006-04-12 23:17:06 +02:00
|
|
|
|
2013-06-28 10:53:47 +02:00
|
|
|
if [ ! $test ]; then
|
2006-04-12 23:17:06 +02:00
|
|
|
$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
|
2013-06-28 10:53:47 +02:00
|
|
|
fi
|
2006-04-12 23:17:06 +02:00
|
|
|
|
2009-05-22 14:50:52 +02:00
|
|
|
[ $? -ne 0 ] && fatal "Tar backup failed"
|
2006-04-12 23:17:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
|