Pour éditer le wiki, il faut demander un compte à un Lapin !
Difference between revisions of "Routeur rabbit/backup"
From Le L∞p's Wiki
(Created page with "<pre> #!/bin/bash HOST="rabbit.caserne" LOGIN="===== HIDDEN LOGIN =====" PASS="===== HIDDEN PASSWORD =====" BACKUP_DIR="/home/backup" COOK="/tmp/cookies.txt" LOG="${BACKUP_D...") |
(Amelioration du script avec stockage des credentials dans un fichier lisible que par root / Choix du backup ou non des RRD) |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
<pre> | <pre> | ||
#!/bin/bash | #!/bin/bash | ||
+ | RRD=1 | ||
+ | |||
+ | # force umask to rw------- for cookie protection | ||
+ | umask 0177 | ||
HOST="rabbit.caserne" | HOST="rabbit.caserne" | ||
− | LOGIN="===== HIDDEN LOGIN =====" | + | source ${HOME}/.backup-rabbit |
− | PASS="===== HIDDEN PASSWORD =====" | + | #LOGIN="===== HIDDEN LOGIN =====" |
+ | #PASS="===== HIDDEN PASSWORD =====" | ||
− | BACKUP_DIR="/home/backup" | + | BACKUP_DIR="/home/backup/rabbit" |
− | COOK="/tmp/cookies.txt" | + | COOK="/tmp/.cookies.txt" |
LOG="${BACKUP_DIR}/backup.log" | LOG="${BACKUP_DIR}/backup.log" | ||
+ | [ -e ${COOK} ] && rm -f ${COOK} | ||
+ | touch ${COOK} | ||
echo "Backup of ${HOST} with login ${LOGIN} in ${BACKUP_DIR}" | echo "Backup of ${HOST} with login ${LOGIN} in ${BACKUP_DIR}" | ||
curl -k -b ${COOK} -c ${COOK} --data "login=${LOGIN}&usernamefld=${LOGIN}&passwordfld=${PASS}" https://${HOST} 2>&1 |tee -a ${LOG} | curl -k -b ${COOK} -c ${COOK} --data "login=${LOGIN}&usernamefld=${LOGIN}&passwordfld=${PASS}" https://${HOST} 2>&1 |tee -a ${LOG} | ||
curl -k -b ${COOK} -c ${COOK} --data "login=${LOGIN}&usernamefld=${LOGIN}&passwordfld=${PASS}" https://${HOST}/diag_backup.php 2>&1 |tee -a ${LOG} | curl -k -b ${COOK} -c ${COOK} --data "login=${LOGIN}&usernamefld=${LOGIN}&passwordfld=${PASS}" https://${HOST}/diag_backup.php 2>&1 |tee -a ${LOG} | ||
− | curl -k -b ${COOK} -o ${BACKUP_DIR}/config-router-`date +%Y%m%d%H%M%S`.xml --data 'Submit=download&donotbackuprrd=no' https://${HOST}/diag_backup.php 2>&1 |tee -a ${LOG} | + | [ ${RRD} -eq 1 ] && { curl -k -b ${COOK} -o ${BACKUP_DIR}/config-router-`date +%Y%m%d%H%M%S`.xml --data 'Submit=download' https://${HOST}/diag_backup.php 2>&1 |tee -a ${LOG} ; } || { curl -k -b ${COOK} -o ${BACKUP_DIR}/config-router-`date +%Y%m%d%H%M%S`.xml --data 'Submit=download&donotbackuprrd=no' https://${HOST}/diag_backup.php 2>&1 |tee -a ${LOG} ; } |
gzip ${BACKUP_DIR}/*.xml | gzip ${BACKUP_DIR}/*.xml | ||
+ | [ -e ${COOK} ] && rm -f ${COOK} | ||
</pre> | </pre> | ||
+ | |||
+ | {{Voir aussi|{{fichier|/etc/rc.create_full_backup}} pour faire un [https://doc.pfsense.org/index.php/Full_Backup full backup]}} |
Latest revision as of 13:33, 18 November 2014
#!/bin/bash RRD=1 # force umask to rw------- for cookie protection umask 0177 HOST="rabbit.caserne" source ${HOME}/.backup-rabbit #LOGIN="===== HIDDEN LOGIN =====" #PASS="===== HIDDEN PASSWORD =====" BACKUP_DIR="/home/backup/rabbit" COOK="/tmp/.cookies.txt" LOG="${BACKUP_DIR}/backup.log" [ -e ${COOK} ] && rm -f ${COOK} touch ${COOK} echo "Backup of ${HOST} with login ${LOGIN} in ${BACKUP_DIR}" curl -k -b ${COOK} -c ${COOK} --data "login=${LOGIN}&usernamefld=${LOGIN}&passwordfld=${PASS}" https://${HOST} 2>&1 |tee -a ${LOG} curl -k -b ${COOK} -c ${COOK} --data "login=${LOGIN}&usernamefld=${LOGIN}&passwordfld=${PASS}" https://${HOST}/diag_backup.php 2>&1 |tee -a ${LOG} [ ${RRD} -eq 1 ] && { curl -k -b ${COOK} -o ${BACKUP_DIR}/config-router-`date +%Y%m%d%H%M%S`.xml --data 'Submit=download' https://${HOST}/diag_backup.php 2>&1 |tee -a ${LOG} ; } || { curl -k -b ${COOK} -o ${BACKUP_DIR}/config-router-`date +%Y%m%d%H%M%S`.xml --data 'Submit=download&donotbackuprrd=no' https://${HOST}/diag_backup.php 2>&1 |tee -a ${LOG} ; } gzip ${BACKUP_DIR}/*.xml [ -e ${COOK} ] && rm -f ${COOK}