f37 -> f39
[infrastructure.git] / scripts / backup-databases.sh
1 #!/bin/sh
2
3 source /etc/backup-helper
4
5 DATE=`date +%Y%m%d-%H%M`
6 HOST=`hostname -s`
7
8 ps -C postmaster 2>&1 >/dev/null
9 if [ $? -eq 0 ]; then
10         backup_all_dbs /mnt/backup $HOST $DATE
11 fi
12
13 # thierry : tmp backup solution on gorillaz
14 # note that in addition to the db dumps in /mnt/backup, this also keeps a backup of 
15 # (*) /etc/ and in particular /etc/planetlab + all other crontabs and backup-helper
16 # (*) /var/www/html for the drupal themes and other stuff
17 # (*) /root with various tweaks in particular in /root/thierry
18 # in general this is not intended to be restored as-is (as it might overwrite too much stuff)
19 # but can be helpful so, just in case ...
20
21 # baris: create archive files in /mnt/backup for /etc /var/www/html and /root respectively and sync only /mnt/backup
22 # bicudo: added 'cd /' to stop with crontab huge mails
23 for d in etc var/www/html root
24 do
25   cd /
26   dir_name=`echo ${d} | sed 's/\//_/g'`_
27   tar cjf /mnt/backup/${HOST}_${dir_name}${DATE}.tar.bz2 $d
28 done
29
30 # baris: copy all files from today to the "latest" directory.
31 BACKUP=/mnt/backup
32 LATESTDATE=`date +%Y%m%d`
33 LATEST=/mnt/backup/latest
34 TMP=${LATEST}.temp
35 mkdir -p ${TMP} && cp -r $BACKUP/*${LATESTDATE}*.bak $TMP && rm -rf $LATEST && mv $TMP $LATEST
36
37 for d in etc var/www/html root
38 do
39   mkdir -p $LATEST/$d
40   rsync --archive --verbose --relative --delete  /$d/ $LATEST/$d/
41 done
42
43 rsync --archive --verbose --relative --delete  /mnt/backup/  --exclude '*~' root@gorillaz:/backup-ple-www