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 DBNAME=$(echo $i | cut -d '|' -f 1)
41 DBUSER=$(echo $i | cut -d '|' -f 2)
44 *) backup_db $1 $2 $3 $DBNAME $DBUSER
49 # backup the ejabberd database on this node
52 function backup_ejabberd () {
55 fullname=$dest/ejabberd-$date.backup
57 echo -n "Backup ejabberd database ..."
58 ejabberdctl backup $fullname
60 echo -n " ($(stat --printf="%s" $fullname) bytes)"
61 [ $RES -eq 0 ] && echo " [ OK ]" || { echo " [ KO ]" ; return 1 ; }
65 ########################################
66 # Thierry - 30 June 2011
67 # this now runs at INRIA
68 # we don't need to push this onto another box anymore, as we have the central backup system
69 # fetch this on a nightly basis
71 # /db-backup contains the snapshots of the databases
72 # /db-backup /etc /root /var/log and /var/www/html are then fetched
73 # directly from the central backup server
74 # we don't need to handle these anymore from here
75 # NOTE: the central backup server at INRIA has snapshots for moving back in time
79 DATE=$(date +%Y%m%d-%H%M)
84 # save all databases, either postgresql (currently on www) or ejabberd (currently on boot)
86 echo "backup script on $HOST"
87 echo "Please do not change this script directly, use git and related makefile at"
88 echo "but http://git.onelab.eu/?p=infrastructure.git;a=blob;f=scripts/ple-backup-cleanup.cron"
90 ps -C postmaster >& /dev/null && backup_all_dbs $BACKUP_DIR $HOST $DATE \
91 || echo "No postgresql database to backup on $HOST"
93 type -p ejabberdctl >& /dev/null && backup_ejabberd $BACKUP_DIR $DATE \
94 || echo "No ejabberd database to backup on $HOST"
97 # trash old files in $BACKUP_DIR
98 # formerly in /etc/cron.weekly/clean-backup.sh
100 echo "cleanup script on $HOST"
101 echo "Please do not change this script directly, use git and related makefile at"
102 echo "but http://git.onelab.eu/?p=infrastructure.git;a=blob;f=scripts/ple-backup-cleanup.cron"
104 ONE_WEEK=$((7*24*60*6))
105 DATE_OLD=$(($DATE - $ONE_WEEK))
107 for file in $BACKUP_REPO/*; do
108 [ -f $file ] || continue
109 STAT=$(stat --printf="%Y" $file)
110 [ $STAT -lt $DATE_OLD ] || continue
111 echo "ple-cleanup.cron: Remove old $file"
118 *cleanup*) cleanup ;;
119 *) echo "WARNING : invoked crontab script under a wrong name $0" ;;