From: Hugo Villeneuve Date: Sun, 16 Nov 2014 20:46:13 +0000 (-0500) Subject: Ajout script de backup pour VPS X-Git-Url: http://gitweb.hugovil.com/?p=hvutilities.git;a=commitdiff_plain;h=4668b8d36a5d4f49aabbaade4f6f994fc6960912 Ajout script de backup pour VPS --- 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