summaryrefslogtreecommitdiff
path: root/share/hydractl/backup-site
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2011-09-27 18:07:24 -0300
committerSilvio Rhatto <rhatto@riseup.net>2011-09-27 18:07:24 -0300
commit9330113df08676ec82639aec8cca290709b7936e (patch)
tree93600833840c1d0f6d7420511335bf12bfc51195 /share/hydractl/backup-site
parentc040869beb026ecc309bf1c2ccf627261f41bc46 (diff)
downloadhydra-9330113df08676ec82639aec8cca290709b7936e.tar.gz
hydra-9330113df08676ec82639aec8cca290709b7936e.tar.bz2
Action backup-site now dumping db and storing things in the right place
Diffstat (limited to 'share/hydractl/backup-site')
-rwxr-xr-xshare/hydractl/backup-site61
1 files changed, 46 insertions, 15 deletions
diff --git a/share/hydractl/backup-site b/share/hydractl/backup-site
index 53119da..79bc4ec 100755
--- a/share/hydractl/backup-site
+++ b/share/hydractl/backup-site
@@ -2,31 +2,62 @@
#
# Pack a website.
#
-# TODO: put on $SITES/backups/site/$SITE, with htaccess and correct
-# ownership/permission.
-#
-# TODO: optionally backup database before packing
-#
-# TODO: add backup files in a dated folder
# Arguments
SITES="/var/sites"
SITE="$1"
PACK="$1.tar.bz2"
+DATE="`date +%Y%m%d`"
+DEST="$SITES/backups/site/$SITE/$DATE"
+# Syntax check
if [ -z "$SITE" ]; then
hydra_action_usage
exit 1
-elif [ ! -d "$SITES/$SITE" ]; then
- echo "No such site $SITE"
- exit 1
fi
-mkdir -p $SITES/backups/$SITE
-cd $SITES/backups/$SITE
+# Create folder
+mkdir -p $DEST
+cd $DEST
-tar jcvf $PACK $SITES/$SITE
-md5sum $PACK > $PACK.md5
-sha1sum $PACK > $PACK.sha1
+# Password setup
+if [ ! -e "$SITES/backups/site/$SITE/.htpasswd" ]; then
+ touch $SITES/backups/site/$SITE/.htpasswd
+ chmod 640 $SITES/backups/site/$SITE/.htpasswd
+ chown root.backups $SITES/backups/site/$SITE/.htpasswd
+fi
-echo "Saved $SITES/backups/$SITE/$PACK"
+# Access setup
+if [ ! -e "$SITES/backups/site/$SITE/.htaccess" ]; then
+ echo > $SITES/backups/site/$SITE/.htaccess <<EOF
+AuthType Basic
+AuthName "Backup $SITE"
+AuthUserFile $SITES/backups/site/$SITE/.htpasswd
+Require valid-user
+EOF
+fi
+
+# Backup site
+if [ ! -d "$SITES/$SITE" ]; then
+ echo "Backing up site folder..."
+ tar jcvf $PACK $SITES/$SITE
+ md5sum $PACK > $PACK.md5
+ sha1sum $PACK > $PACK.sha1
+ chown root.backups $PACK*
+ chmod 640 $PACK*
+ echo "Saved $DEST/$PACK"
+fi
+
+# Backup database
+if [ -d "/var/lib/mysql/$SITE" ]; then
+ echo "Backing up database $SITE..."
+ mysqldump $SITE > $SITE.sql
+ bzip2 $SITE.sql
+ md5sum $SITE.sql.bz2 > $SITE.sql.bz2.md5
+ sh1sum $SITE.sql.bz2 > $SITE.sql.bz2.sha1
+ chown root.backups $SITE.sql*
+ chmod 640 $SITE.sql*
+ echo "Saved $DEST/$SITE.sql.bz2"
+else
+ echo "Database not found, please backup it manually"
+fi