Commit 9e105ea9 authored by Simone Piccardi's avatar Simone Piccardi
Browse files

Introduced command to access to backup data for recover.

parent a745e1ef
......@@ -39,6 +39,26 @@
LC_ALL=C
umask 077
# get command line command (argument 1)
COMMAND=$1
# local data variables (for dump retention)
MAXDAYS=7
MINCOPIES=6
BACKDIR=/var/backups
# temporary log files
DAY=$(date +%a)
TMPLOG=/tmp/fuss-backup-$DAY.log
ERRLOG=/tmp/fuss-backup-err.log
MESS="Data dump on $(hostname) for $(date +%x)"
# all output go to TMPLOG
exec > $TMPLOG 2>&1
# define exit function (sending email)
mail_exit () {
if [ $1 != 0 ]; then
......@@ -46,34 +66,23 @@ mail_exit () {
else
MAILSUBJ="Backup ok on $(hostname) for $(date +%x)"
fi
if [ "$MAILTO" ]; then
DESTINARI="$MAILTO"
if [ -z "$COMMAND" ]; then
if [ "$MAILTO" ]; then
DESTINARI="$MAILTO"
else
DESTINARI=root
fi
for i in $DESTINARI; do
grep -v "Hexadecimal number" $TMPLOG | mailx -s "$MAILSUBJ" $i
done
else
DESTINARI=root
cat $TMPLOG
echo error code $1
fi
for i in $DESTINARI; do
grep -v "Hexadecimal number" $TMPLOG | mailx -s "$MAILSUBJ" $i
done
exit $1
}
# local data variables (for dump retention)
MAXDAYS=7
MINCOPIES=6
BACKDIR=/var/backups
# temporary log files
DAY=$(date +%a)
TMPLOG=/tmp/dumpdata-$DAY.log
ERRLOG=/tmp/dumpdata-err.log
# clear logs
MESS="Data dump on $(hostname) for $(date +%x)"
exec > $TMPLOG 2>&1
echo "$MESS started, at $(date +%R)"
echo
# get configuration
# get configuration form file
if [ -f /etc/fuss-backup/fuss-backup.conf ]; then
. /etc/fuss-backup/fuss-backup.conf
else
......@@ -81,6 +90,15 @@ else
mail_exit 1
fi
# define help function
usage () {
echo "usage: fuss-backup [command]"
echo " for batch backup via cron do not give any command"
echo " only valid commands are:"
echo " mount (mount repository and backup data on $RECOVERDIR)"
echo " umount (mount repository and backup data)"
}
# check if the backup is enabled
if [ $START != "yes" ]; then
echo "ERRORE: è necessario configurare l'applicazione fuss-backup"
......@@ -123,6 +141,54 @@ function init_dump () {
cd $bak
}
# define borg backup destination
DESTINATION=$BASEDIR/$BACKUP_DIR
[ -d $BASEDIR ] || mkdir -p $BASEDIR
umount $BASEDIR 2> /dev/null
if [ ! $DISK ]; then
echo "Deve essere definito il disco/NAS di destinazione"
echo "Modificare il file /etc/fuss-backup/fuss-backup.conf"
echo "per definire un opportuno valore della variabile DISK"
mail_exit 3
fi
##
## Command management
##
case $COMMAND in
mount)
if mount $DISK $BASEDIR; then
borg mount $DESTINATION $RECOVERDIR
echo "mounted backup on $RECOVERDIR"
mail_exit 0
else
echo "cannot mount repository"
mail_exit 6
fi
;;
umount)
fusermount -u $RECOVERDIR
umount $DESTINATION
mail_exit 0
;;
*)
echo "unknown command $COMMAND"
usage()
mail_exit 5
;;
esac
##
## Batch backup execution (when no command is given)
##
# clear logs
echo "$MESS started, at $(date +%R)"
echo
# do a package list backup anyway
dpkg --get-selections > $BACKDIR/package-list.txt
......@@ -213,19 +279,6 @@ fi
#
# Borg backup section
#
if [ ! $DISK ]; then
echo "Deve essere definito il disco/NAS di destinazione"
echo "Modificare il file /etc/fuss-backup/fuss-backup.conf"
echo "per definire un opportuno valore della variabile DISK"
mail_exit 3
fi
# define borg backup destination
DESTINATION=$BASEDIR/$BACKUP_DIR
[ -d $BASEDIR ] || mkdir -p $BASEDIR
umount $BASEDIR 2> /dev/null
if mount $DISK $BASEDIR; then
echo "FUSS backup started at $(date +%R)"
echo "* dump su $DISK"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment