Ajout script de backup pour VPS
authorHugo Villeneuve <hugo@hugovil.com>
Sun, 16 Nov 2014 20:46:13 +0000 (15:46 -0500)
committerHugo Villeneuve <hugo@hugovil.com>
Sun, 16 Nov 2014 20:46:13 +0000 (15:46 -0500)
scripts/vps-backup.sh [new file with mode: 0755]

diff --git a/scripts/vps-backup.sh b/scripts/vps-backup.sh
new file mode 100755 (executable)
index 0000000..16395fc
--- /dev/null
@@ -0,0 +1,47 @@
+#!/bin/bash
+
+USERDIR=/home/myuser
+
+BACKUP_DIR=${USERDIR}/backup
+MYSQL_BACKUP_DIR=${BACKUP_DIR}/mysql
+
+MYSQL_DATABASES="\
+    mysql \
+    db1"
+
+read -s -p "Enter MySQL password: " password
+
+if [ "x${password}" == "x" ]; then
+    echo "Error, empty MySQL password"
+    exit 1
+fi
+
+if [ ! -d ${BACKUP_DIR} ]; then
+    mkdir ${BACKUP_DIR}
+fi
+
+if [ ! -d ${MYSQL_BACKUP_DIR} ]; then
+    mkdir ${MYSQL_BACKUP_DIR}
+fi
+
+for db in ${MYSQL_DATABASES}; do
+    mysqldump -u root -p${password} ${db} > ${MYSQL_BACKUP_DIR}/${db}.sql
+done
+
+# Compact GIT repositories
+for r in /srv/git/*; do
+    if [ -f ${r}/HEAD ]; then
+       pushd ${r}
+       git gc --aggressive
+       popd
+    fi
+done
+
+# Backup GIT repositories
+tar cf - /srv/git | bzip2 -9 > ${BACKUP_DIR}/git.tar.bz2
+
+# Backup web sites
+tar cf - /srv/www | bzip2 -9 > ${BACKUP_DIR}/www.tar.bz2
+
+# Backup emails
+tar cf - ${USERDIR}/.mail | bzip2 -9 > ${BACKUP_DIR}/mail.tar.bz2