#!/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} status="OK" if [ $(grep "Errors 0" ${LOGFILE_RECENT} |wc -l) -eq 0 ]; then status="ALERTE FAIL !!!" fi cat ${LOGFILE_RECENT} |mail -s "${status} | Backup ${SCW_BUCKET} `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} : " 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 --s3-endpoint-url ${SCW_ENDPOINT_URL} --s3-region-name ${SCW_REGION} ${KEEP_BACKUP_TIME} ${SCW_BUCKET} --force >> ${LOGFILE_RECENT} 2>&1 log ">>> creating and uploading backup to c14 cold storage ${SOURCE}" ${DUPLICITY} \ incr --full-if-older-than ${FULL_BACKUP_TIME} \ --s3-endpoint-url ${SCW_ENDPOINT_URL} \ --s3-region-name ${SCW_REGION} \ --asynchronous-upload \ --s3-use-glacier \ --encrypt-key=${GPG_FINGERPRINT} \ --sign-key=${GPG_FINGERPRINT} \ ${SOURCE} ${SCW_BUCKET} >> ${LOGFILE_RECENT} 2>&1 rotate_log else log ">>> Duplicity déjà en cours de route sur cette utilisateur ${USER}" rotate_log fi