54 lines
1.7 KiB
Bash
Raw Normal View History

2023-02-17 18:04:21 +01:00
#!/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 ${SCW_BUCKET} | rev | cut -d "/" -f 2 | rev`
2023-02-17 18:04:21 +01:00
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 --s3-endpoint-url ${SCW_ENDPOINT_URL} --s3-region-name ${SCW_REGION} ${KEEP_BACKUP_TIME} ${SCW_BUCKET} --force >> ${LOGFILE_RECENT} 2>&1
2023-02-17 18:04:21 +01:00
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} \
2023-02-17 18:04:21 +01:00
--asynchronous-upload \
--s3-use-glacier \
--encrypt-key=${GPG_FINGERPRINT} \
--sign-key=${GPG_FINGERPRINT} \
${SOURCE} ${SCW_BUCKET} >> ${LOGFILE_RECENT} 2>&1
2023-02-17 18:04:21 +01:00
rotate_log
else
log ">>> Duplicity déjà en cours de route sur cette utilisateur ${USER}"
rotate_log
fi