add backup-helper and backup-databases.sh to infrastructure
[infrastructure.git] / scripts / backup-databases.sh
diff --git a/scripts/backup-databases.sh b/scripts/backup-databases.sh
new file mode 100755 (executable)
index 0000000..2b87947
--- /dev/null
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+source /etc/backup-helper
+
+DATE=`date +%Y%m%d-%H%M`
+HOST=`hostname -s`
+
+ps -C postmaster 2>&1 >/dev/null
+if [ $? -eq 0 ]; then
+       backup_all_dbs /mnt/backup $HOST $DATE
+fi
+
+# thierry : tmp backup solution on gorillaz
+# note that in addition to the db dumps in /mnt/backup, this also keeps a backup of 
+# (*) /etc/ and in particular /etc/planetlab + all other crontabs and backup-helper
+# (*) /var/www/html for the drupal themes and other stuff
+# (*) /root with various tweaks in particular in /root/thierry
+# in general this is not intended to be restored as-is (as it might overwrite too much stuff)
+# but can be helpful so, just in case ...
+
+# baris: create archive files in /mnt/backup for /etc /var/www/html and /root respectively and sync only /mnt/backup
+# bicudo: added 'cd /' to stop with crontab huge mails
+for d in etc var/www/html root
+do
+  cd /
+  dir_name=`echo ${d} | sed 's/\//_/g'`_
+  tar cjf /mnt/backup/${HOST}_${dir_name}${DATE}.tar.bz2 $d
+done
+
+# baris: copy all files from today to the "latest" directory.
+BACKUP=/mnt/backup
+LATESTDATE=`date +%Y%m%d`
+LATEST=/mnt/backup/latest
+TMP=${LATEST}.temp
+mkdir -p ${TMP} && cp -r $BACKUP/*${LATESTDATE}*.bak $TMP && rm -rf $LATEST && mv $TMP $LATEST
+
+for d in etc var/www/html root
+do
+  mkdir -p $LATEST/$d
+  rsync --archive --verbose --relative --delete  /$d/ $LATEST/$d/
+done
+
+rsync --archive --verbose --relative --delete  /mnt/backup/  --exclude '*~' root@gorillaz:/backup-ple-www