52 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
LOGFILE_RECENT="/var/log/scw-log/logfile-recent.log"
LOGFILE="/var/log/scw-log/logfile.log"
DUPLICITY=/usr/local/bin/duplicity
log () {
date=`date +%Y-%m-%d`
hour=`date +%H:%M:%S`
echo "$date $hour $*" >> ${LOGFILE_RECENT}
}
rotate_log() {
cat ${LOGFILE_RECENT} >> ${LOGFILE}
backupScw=`echo ${URL_SCW} | rev | cut -d "/" -f 2 | rev`
status="OK"
if [ $(grep "Errors 0" ${LOGFILE_RECENT} |wc -l) -eq 0 ]; then
status="ALERTE FAIL !!!"
fi
cat ${LOGFILE_RECENT} |mail -s "${status} | Backup ${backupScw} `date +%Y-%m-%d`" valczebackup@gmail.com
}
USER=$(whoami)
currently_backuping=$(ps -ef | grep duplicity | grep python |grep ${USER} | wc -l)
if [ $currently_backuping -eq 0 ]; then
if [ ${#} -ne 1 ]; then
log ">>> Il manque un paramètre ${0} : <CONFIGFILE>"
rotate_log
exit 1
fi
if [ ! -f ${1} ]; then
log ">>> Le paramètre n'est pas un fichier ${USER} : ${1}"
rotate_log
exit 1
fi
source "$1"
echo > ${LOGFILE_RECENT}
log ">>> removing old backups"
${DUPLICITY} remove-older-than ${KEEP_BACKUP_TIME} ${URL_SCW} --force >> ${LOGFILE_RECENT} 2>&1
log ">>> creating and uploading backup to c14 cold storage ${SOURCE}"
${DUPLICITY} \
incr --full-if-older-than ${FULL_BACKUP_TIME} \
--asynchronous-upload \
--s3-use-glacier \
--encrypt-key=${GPG_FINGERPRINT} \
--sign-key=${GPG_FINGERPRINT} \
${SOURCE} ${URL_SCW} >> ${LOGFILE_RECENT} 2>&1
rotate_log
else
log ">>> Duplicity déjà en cours de route sur cette utilisateur ${USER}"
rotate_log
fi