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
|
28
web_scrap.py
28
web_scrap.py
@@ -13,9 +13,11 @@ def mkdirPath(path_dir, logger):
|
||||
if not os.path.exists(repath):
|
||||
logger.debug("Dossier crée : {0}".format(repath))
|
||||
try:
|
||||
os.mkdir(repath)
|
||||
if len(repath) > 0:
|
||||
os.mkdir(repath)
|
||||
except Exception as 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)
|
||||
|
||||
|
||||
@@ -189,21 +191,21 @@ if __name__ == '__main__':
|
||||
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-html", help="No HTML", dest="html", action="store_true")
|
||||
|
||||
parser.add_argument("--quiet", help="No console output", action="store_true")
|
||||
args = parser.parse_args()
|
||||
logger = logging.getLogger('web_scrap')
|
||||
ch = logging.StreamHandler()
|
||||
|
||||
if args.debug is True:
|
||||
logger.setLevel(logging.DEBUG)
|
||||
ch.setLevel(logging.DEBUG)
|
||||
else:
|
||||
logger.setLevel(logging.INFO)
|
||||
ch.setLevel(logging.INFO)
|
||||
|
||||
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||
ch.setFormatter(formatter)
|
||||
logger.addHandler(ch)
|
||||
|
||||
if args.quiet is False:
|
||||
ch = logging.StreamHandler()
|
||||
if args.debug is True:
|
||||
logger.setLevel(logging.DEBUG)
|
||||
ch.setLevel(logging.DEBUG)
|
||||
else:
|
||||
logger.setLevel(logging.INFO)
|
||||
ch.setLevel(logging.INFO)
|
||||
ch.setFormatter(formatter)
|
||||
logger.addHandler(ch)
|
||||
|
||||
|
||||
if len(args.logfile) > 0:
|
||||
|
Reference in New Issue
Block a user