Compare commits
4 Commits
c62e3e6646
...
1.0.0
Author | SHA1 | Date | |
---|---|---|---|
4b9a790f8a | |||
a6d642811e | |||
dfc9c4277b | |||
89ea5720e5 |
47
backup_canalblog.sh
Executable file
47
backup_canalblog.sh
Executable file
@@ -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
|
10
web_scrap.py
10
web_scrap.py
@@ -13,9 +13,11 @@ def mkdirPath(path_dir, logger):
|
|||||||
if not os.path.exists(repath):
|
if not os.path.exists(repath):
|
||||||
logger.debug("Dossier crée : {0}".format(repath))
|
logger.debug("Dossier crée : {0}".format(repath))
|
||||||
try:
|
try:
|
||||||
|
if len(repath) > 0:
|
||||||
os.mkdir(repath)
|
os.mkdir(repath)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
logger.error("Directory error : {0}".format(err))
|
logger.error("Directory error : {0}".format(err))
|
||||||
|
logger.debug("Directory error : {0} {1} {2} {3} {4}".format(err, path_dir, repath, pathh, makedir))
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
@@ -189,19 +191,19 @@ if __name__ == '__main__':
|
|||||||
parser.add_argument("--no-js", help="No JS", dest="js", action="store_true")
|
parser.add_argument("--no-js", help="No JS", dest="js", action="store_true")
|
||||||
parser.add_argument("--no-img", help="No img", dest="img", action="store_true")
|
parser.add_argument("--no-img", help="No img", dest="img", action="store_true")
|
||||||
parser.add_argument("--no-html", help="No HTML", dest="html", action="store_true")
|
parser.add_argument("--no-html", help="No HTML", dest="html", action="store_true")
|
||||||
|
parser.add_argument("--quiet", help="No console output", action="store_true")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
logger = logging.getLogger('web_scrap')
|
logger = logging.getLogger('web_scrap')
|
||||||
ch = logging.StreamHandler()
|
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||||
|
|
||||||
|
if args.quiet is False:
|
||||||
|
ch = logging.StreamHandler()
|
||||||
if args.debug is True:
|
if args.debug is True:
|
||||||
logger.setLevel(logging.DEBUG)
|
logger.setLevel(logging.DEBUG)
|
||||||
ch.setLevel(logging.DEBUG)
|
ch.setLevel(logging.DEBUG)
|
||||||
else:
|
else:
|
||||||
logger.setLevel(logging.INFO)
|
logger.setLevel(logging.INFO)
|
||||||
ch.setLevel(logging.INFO)
|
ch.setLevel(logging.INFO)
|
||||||
|
|
||||||
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
|
||||||
ch.setFormatter(formatter)
|
ch.setFormatter(formatter)
|
||||||
logger.addHandler(ch)
|
logger.addHandler(ch)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user