From a6d642811ec194a08f05f6b61f83b55a73d90efe Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Thu, 9 Mar 2023 23:06:34 +0100 Subject: [PATCH] add script backup canalblog --- backup_canalblog.sh | 47 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 backup_canalblog.sh diff --git a/backup_canalblog.sh b/backup_canalblog.sh new file mode 100755 index 0000000..4b87d40 --- /dev/null +++ b/backup_canalblog.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +TAR=/usr/bin/tar +PYTHON=/usr/bin/python3 +GZIP=/usr/bin/gzip +SCRIPTDIR=/home/valentin/script +WEBSCRAP=${SCRIPTDIR}/web_scrap.py +URL=www.clarissariviere.com +DATE=$(date +%Y%m%d) +DIRECTORY=/home/valentin/backup +BACKUPDIR=/home/valentin/backup_clarissa +LIST=${BACKUPDIR}/backup.list +fileBackup="backup-clarissa-${DATE}" +LOGFILE=web_scrap.txt +SENDER="valczebackup@gmail.com" +if [ $(date +%u) -eq 5 ]; then + echo > ${LIST} + rm -rf "${BACKUPDIR}/*-incr.tar.gz" + fileBackup="${fileBackup}-full" + subject="Sauvegarde full" +else + fileBackup="${fileBackup}-incr" + subject="Sauvegarde incremental" +fi +subject="${subject} ${URL} ${DATE}" +echo > ${BACKUPDIR}/${LOGFILE} +${PYTHON} ${WEBSCRAP} --url ${URL} --dir ${DIRECTORY} --quiet --logfile ${BACKUPDIR}/${LOGFILE} +if [ ${?} -ne 0 ]; then + subject="${subject} echoue : recuperation page" + echo ${subject} | mail -s "${subject}" -A ${BACKUPDIR}/${LOGFILE} ${SENDER} + exit 1 +fi +${TAR} --create --file="${BACKUPDIR}/${fileBackup}.tar" --listed-incremental=${LIST} ${DIRECTORY} +if [ ${?} -ne 0 ]; then + subject="${subject} echoue : archivage page " + echo ${subject} | mail -s "${subject}" -A ${BACKUPDIR}/${LOGFILE} ${SENDER} + exit 1 +fi +${GZIP} -f -9 "${BACKUPDIR}/${fileBackup}.tar" +if [ ${?} -ne 0 ]; then + subject="${subject} echoue : compression archive " + echo ${subject} | mail -s "${subject}" -A ${BACKUPDIR}/${LOGFILE} ${SENDER} + exit 1 +fi +subject="${subject} OK" +echo ${subject}| mail -s "${subject}" -A ${BACKUPDIR}/${LOGFILE} ${SENDER} +exit 0