1
0
Fork 0
This repository has been archived on 2023-11-30. You can view files and clone it, but cannot push or open issues or pull requests.
dtux__config_lalis/sauvegarde.sh

63 lines
1.9 KiB
Bash
Executable File

#!/bin/bash
# Script de sauvegarde
# Daniel Tartavel (lalis.fr)
# directory to backup
npid=0
npid=`pidof -o %PPID -x sauvegarde.sh`
echo "#$npid#"
if [ -n "$npid" ]; then exit; fi
REP="journaliere"
if [ "$1" = "mensuelle" ]; then
REP=$1
fi
MSG='Content-Type: text/plain ;charset="utf-8"\n\rContent-Transfer-Econding: 8bit\n\r\n'
DDIR="dtux.ddns.net::save/serveur_lalis/$REP"
SDIRX=("/mnt/lalis" "/var/www" "/etc" "/var/lib/mysql" "/var/lib/tftpboot" "/usr/local/bin" "/mnt/nextcloud_data")
#SDIRX=("/var/www" "/etc" "/var/lib/mysql" "/var/lib/tftpboot" "/usr/local/bin")
FLAG=0
# excludes file - this contains a wildcard pattern per line of files to exclude
EXCLUDES=excludes.lst
INCLUDES=includes.lst
########################################################################
BACKUPFILE=`date +%g%m%d%H%M`
OPTS="--port 8073 --blocking-io --force --ignore-errors --delete-excluded --delete --backup --backup-dir=../deleted_$REP --suffix=$BACKUPFILE -alogtpxAX --delete-after --progress --relative --bwlimit=30M "
export PATH=$PATH:/bin:/usr/bin:/usr/local/bin
for SDIR in ${SDIRX[*]}; do
if [ -a $SDIR/$EXCLUDES ]; then
OPTS=$OPTS" --exclude-from=$SDIR/$EXCLUDES "
elif [ -a /etc/sauvegarde/$EXCLUDES ]; then
OPTS=$OPTS" --exclude-from=/etc/sauvegarde/$EXCLUDES "
fi
if [ -a $SDIR/$INCLUDES ]; then
OPTS=$OPTS" --include-from=$SDIR/$INCLUDES "
elif [ -a /etc/sauvegarde/$INCLUDES ]; then
OPTS=$OPTS" --include-from=/etc/sauvegarde/$INCLUDES "
fi
echo "rsync $OPTS $SDIR $DDIR/"
MSG=$MSG"rsync $OPTS $SDIR $DDIR/ => "
rsync $OPTS $SDIR $DDIR/
RET=$?
if [ $RET -ne 0 ]; then
MSG=$MSG"Erreur, code de retour : $RET\r\n"
FLAG=1
else
MSG=$MSG"OK, code de retour : $RET\r\n"
fi
done
if [ $FLAG -eq 1 ]; then
OBJ="Subject: [LALISNO] Problème lors de la sauvegarde\n\r"
else
OBJ="Subject: [LALISOK] Sauvegarde réussie\n\r"
fi
printf "$OBJ$MSG" | sendmail -f contact@lalis.fr contact@lalis.fr