summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2014-03-21 17:53:22 -0300
committerSilvio Rhatto <rhatto@riseup.net>2014-03-21 17:53:22 -0300
commitaa6e0e9fead7a7922fe47c898601b5f8cfe80354 (patch)
tree3b1eb3c742fda559aa11c09645b13350d9bbc5f5
parent8afafcbdcd7a68dd6d12ba67a9c78efa16c7047d (diff)
downloadhydra-aa6e0e9fead7a7922fe47c898601b5f8cfe80354.tar.gz
hydra-aa6e0e9fead7a7922fe47c898601b5f8cfe80354.tar.bz2
Truncate database name to 16 chars max
-rw-r--r--TODO.md1
-rw-r--r--lib/hydra/backup6
-rwxr-xr-xshare/hydractl/backup-restore-database4
-rwxr-xr-xshare/hydractl/backup-site25
4 files changed, 21 insertions, 15 deletions
diff --git a/TODO.md b/TODO.md
index ea6f5ce..3c887ca 100644
--- a/TODO.md
+++ b/TODO.md
@@ -21,4 +21,3 @@ Hydractl
- backup-restore-site:
- metastore integration for fine-grained permissions
- use metadata do detect drupal series
- - truncate database name to 16 chars max
diff --git a/lib/hydra/backup b/lib/hydra/backup
index 000bc5a..5d61db3 100644
--- a/lib/hydra/backup
+++ b/lib/hydra/backup
@@ -168,3 +168,9 @@ function hydra_backup_restore_database {
echo "Database should be manually restored"
fi
}
+
+# Return a normalized database name
+function hydra_database_name {
+ # MySQL 16 chars limit
+ echo $1 | sed -r 's/(^>.{16}).*/\1/'"
+}
diff --git a/share/hydractl/backup-restore-database b/share/hydractl/backup-restore-database
index 1912529..ca0a755 100755
--- a/share/hydractl/backup-restore-database
+++ b/share/hydractl/backup-restore-database
@@ -23,12 +23,12 @@ hydra_config_load
# Parameters.
DATE="`date +%Y%m%d`"
HOST="$1"
-DATABASE="$2"
+DATABASE="`hydra_database_name $2`"
BASEDIR="/tmp"
# Check restore strategy.
if [ "$1" == "backups" ]; then
- DATABASE="$3"
+ DATABASE="`hydra_database_name $3`"
hydra_backup_environment_local_website $2 $3
elif [ "$HOST" == "localhost" ] || [ "$HOST" == "`facter hostname`" ]; then
hydra_backup_environment_local
diff --git a/share/hydractl/backup-site b/share/hydractl/backup-site
index 68b2e4c..437d3e4 100755
--- a/share/hydractl/backup-site
+++ b/share/hydractl/backup-site
@@ -28,6 +28,7 @@ DATE="`date +%Y%m%d`"
DEST_BASE="$SITES/backups/site"
DEST_BASE_SITE="$DEST_BASE/$SITE"
DEST="$DEST_BASE_SITE/`facter hostname`/$DATE"
+DATABASE="`hydra_database_name $SITE`"
# Syntax check.
if [ -z "$SITE" ]; then
@@ -116,18 +117,18 @@ if [ -d "$LOCATION" ]; then
fi
# Backup database
-if [ -d "/var/lib/mysql/$SITE" ]; then
- if [ -e "$SITE.sql.bz2" ]; then
- echo "File $SITE.sql.bz2 already exists, skipping..."
+if [ -d "/var/lib/mysql/$DATABASE" ]; then
+ if [ -e "$DATABASE" ]; then
+ echo "File $DATABASE already exists, skipping..."
else
- echo "Backing up database $SITE..."
- mysqldump $SITE > $SITE.sql
- bzip2 $SITE.sql
- rm -f $SITE.sql
- md5sum $SITE.sql.bz2 > $SITE.sql.bz2.md5
- sha1sum $SITE.sql.bz2 > $SITE.sql.bz2.sha1
- chown root.$BACKUPS_GROUP $SITE.sql*
- chmod 640 $SITE.sql*
- echo "Saved $DEST/$SITE.sql.bz2"
+ echo "Backing up database $DATABASE..."
+ mysqldump $DATABASE > $DATABASE.sql
+ bzip2 $DATABASE.sql
+ rm -f $DATABASE.sql
+ md5sum $DATABASE.sql.bz2 > $DATABASE.sql.bz2.md5
+ sha1sum $DATABASE.sql.bz2 > $DATABASE.sql.bz2.sha1
+ chown root.$BACKUPS_GROUP $DATABASE.sql*
+ chmod 640 $DATABASE.sql*
+ echo "Saved $DEST/$DATABASE.sql.bz2"
fi
fi