X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=scripts%2Fple-backup-cleanup.cron;h=289e47f809a482c03f64666cf2130cb024601773;hb=HEAD;hp=fd4fab65c871b92164ca8454fcfa15208452ac1b;hpb=0b084c6474b5c5887ff6e06bedbca6dc55a4d6f0;p=infrastructure.git diff --git a/scripts/ple-backup-cleanup.cron b/scripts/ple-backup-cleanup.cron index fd4fab6..289e47f 100755 --- a/scripts/ple-backup-cleanup.cron +++ b/scripts/ple-backup-cleanup.cron @@ -37,11 +37,22 @@ function backup_db { # $3: Date function backup_all_dbs { for i in $(psql -qtAF '|' -U postgres -l 2> /dev/null) ; do + NF=$(echo $i | awk -F '|' '{print NF}') + if [ $NF -ne 6 ]; then continue; fi DBNAME=$(echo $i | cut -d '|' -f 1) DBUSER=$(echo $i | cut -d '|' -f 2) case $DBNAME in - template*[01]) ;; - *) backup_db $1 $2 $3 $DBNAME $DBUSER + template*[01]) + ;; + monitor) + # only once every third day; this has reached the 10Bg mark already ! + #(( $(date +%d) % 3 )) || backup_db $1 $2 $3 $DBNAME $DBUSER ;; + # Thierry - dec 2015 - skip this one entirely + # too big and not really interesting + ;; + *) + backup_db $1 $2 $3 $DBNAME $DBUSER + ;; esac done } @@ -83,8 +94,11 @@ BACKUP_DIR=/db-backup # save all databases, either postgresql (currently on www) or ejabberd (currently on boot) function backup () { + echo "backup script on $HOST" + echo "Please do not change this script directly, use git and related makefile at" + echo "but http://git.onelab.eu/?p=infrastructure.git;a=blob;f=scripts/ple-backup-cleanup.cron" # postgresql - ps -C postmaster >& /dev/null && backup_all_dbs $BACKUP_DIR $HOST $DATE \ + ps -C postmaster >& /dev/null || ps -C postgres >& /dev/null && backup_all_dbs $BACKUP_DIR $HOST $DATE \ || echo "No postgresql database to backup on $HOST" # ejabberd type -p ejabberdctl >& /dev/null && backup_ejabberd $BACKUP_DIR $DATE \ @@ -94,6 +108,9 @@ function backup () { # trash old files in $BACKUP_DIR # formerly in /etc/cron.weekly/clean-backup.sh function cleanup () { + echo "cleanup script on $HOST" + echo "Please do not change this script directly, use git and related makefile at" + echo "but http://git.onelab.eu/?p=infrastructure.git;a=blob;f=scripts/ple-backup-cleanup.cron" DATE=$(date +%s) ONE_WEEK=$((7*24*60*6)) DATE_OLD=$(($DATE - $ONE_WEEK))