From 4668b8d36a5d4f49aabbaade4f6f994fc6960912 Mon Sep 17 00:00:00 2001 From: Hugo Villeneuve Date: Sun, 16 Nov 2014 15:46:13 -0500 Subject: [PATCH] Ajout script de backup pour VPS --- scripts/vps-backup.sh | 47 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 scripts/vps-backup.sh diff --git a/scripts/vps-backup.sh b/scripts/vps-backup.sh new file mode 100755 index 0000000..16395fc --- /dev/null +++ b/scripts/vps-backup.sh @@ -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 -- 2.20.1