3 # Thierry : 30 June 2011
4 # simplify distribution - backup-helper is used only here anyways - embed it right here
5 # also removed unused functions - see backup-helper-deprecated for further reference if needed
8 # backup_vserver_offline
9 # backup_vserver_online
13 ######################################## formerly in backup-helper
14 # Goal: backup a PostgreSQL database
16 # $2: Server name (i.e.: onelab2)
24 fullname=$DEST/$2-db-$DBNAME-$3.sql
26 echo -n "Backup postgresql database $DBNAME..."
27 pg_dump -i -U postgres --user=$DBUSER -F c -f $fullname $DBNAME
29 echo -n " ($(stat --printf="%s" $fullname) bytes)"
30 [ $RES -eq 0 ] && echo " [ OK ]" || { echo " [ KO ]" ; return 1 ; }
34 # Goal: backup all PostgreSQL databases on the machine
36 # $2: Server name (i.e.: onelab2)
38 function backup_all_dbs {
39 for i in $(psql -qtAF '|' -U postgres -l 2> /dev/null) ; do
40 NF=$(echo $i | awk -F '|' '{print NF}')
41 if [ $NF -ne 6 ]; then continue; fi
42 DBNAME=$(echo $i | cut -d '|' -f 1)
43 DBUSER=$(echo $i | cut -d '|' -f 2)
48 # only once every third day; this has reached the 10Bg mark already !
49 #(( $(date +%d) % 3 )) || backup_db $1 $2 $3 $DBNAME $DBUSER ;;
50 # Thierry - dec 2015 - skip this one entirely
51 # too big and not really interesting
54 backup_db $1 $2 $3 $DBNAME $DBUSER
60 # backup the ejabberd database on this node
63 function backup_ejabberd () {
66 fullname=$dest/ejabberd-$date.backup
68 echo -n "Backup ejabberd database ..."
69 ejabberdctl backup $fullname
71 echo -n " ($(stat --printf="%s" $fullname) bytes)"
72 [ $RES -eq 0 ] && echo " [ OK ]" || { echo " [ KO ]" ; return 1 ; }
76 ########################################
77 # Thierry - 30 June 2011
78 # this now runs at INRIA
79 # we don't need to push this onto another box anymore, as we have the central backup system
80 # fetch this on a nightly basis
82 # /db-backup contains the snapshots of the databases
83 # /db-backup /etc /root /var/log and /var/www/html are then fetched
84 # directly from the central backup server
85 # we don't need to handle these anymore from here
86 # NOTE: the central backup server at INRIA has snapshots for moving back in time
90 DATE=$(date +%Y%m%d-%H%M)
95 # save all databases, either postgresql (currently on www) or ejabberd (currently on boot)
97 echo "backup script on $HOST"
98 echo "Please do not change this script directly, use git and related makefile at"
99 echo "but http://git.onelab.eu/?p=infrastructure.git;a=blob;f=scripts/ple-backup-cleanup.cron"
101 ps -C postmaster >& /dev/null || ps -C postgres >& /dev/null && backup_all_dbs $BACKUP_DIR $HOST $DATE \
102 || echo "No postgresql database to backup on $HOST"
104 type -p ejabberdctl >& /dev/null && backup_ejabberd $BACKUP_DIR $DATE \
105 || echo "No ejabberd database to backup on $HOST"
108 # trash old files in $BACKUP_DIR
109 # formerly in /etc/cron.weekly/clean-backup.sh
110 function cleanup () {
111 echo "cleanup script on $HOST"
112 echo "Please do not change this script directly, use git and related makefile at"
113 echo "but http://git.onelab.eu/?p=infrastructure.git;a=blob;f=scripts/ple-backup-cleanup.cron"
115 ONE_WEEK=$((7*24*60*6))
116 DATE_OLD=$(($DATE - $ONE_WEEK))
118 for file in $BACKUP_REPO/*; do
119 [ -f $file ] || continue
120 STAT=$(stat --printf="%Y" $file)
121 [ $STAT -lt $DATE_OLD ] || continue
122 echo "ple-cleanup.cron: Remove old $file"
129 *cleanup*) cleanup ;;
130 *) echo "WARNING : invoked crontab script under a wrong name $0" ;;