Permalink
Browse files

Added the ability to only back up the structure for some (wildcard) t…

…ables.
  • Loading branch information...
1 parent fcae915 commit d6046efaf54e4746df8c2977f92ce1570791ab54 @wimleers committed Feb 13, 2012
Showing with 17 additions and 1 deletion.
  1. +17 −1 automysqlbackup.sh
View
@@ -67,6 +67,10 @@ DBEXCLUDE=""
# List of tables to exclude from the backup (in form db.table)
TABLEEXCLUDE=""
+# List of wildcard table names for which to only back up the structure (not
+# the data). They'll be expanded to the proper form (db.table) automatically.
+TABLENODATA=""
+
# Include CREATE DATABASE in backup?
CREATE_DATABASE=yes
@@ -408,7 +412,8 @@ exec 2> $LOGERR # stderr replaced with file $LOGERR.
# Database dump function
dbdump () {
-mysqldump --user=$USERNAME --password=$PASSWORD --host=$DBHOST $OPT $1 > $2
+mysqldump --user=$USERNAME --password=$PASSWORD --host=$DBHOST $OPT --no-data $1 > $2
+mysqldump --user=$USERNAME --password=$PASSWORD --host=$DBHOST $OPT $OPT_DATA $1 >> $2
return 0
}
@@ -454,6 +459,17 @@ if [ -n "$TABLEEXCLUDE" ]; then
done
fi
+# Add --ignore-table options to $OPT_DATA
+OPT_DATA=""
+if [ -n "$TABLENODATA" ]; then
+ for table_wildcard in $TABLENODATA ; do
+ tables_found="`mysql --user=$USERNAME --password=$PASSWORD --host=$DBHOST --batch --skip-column-names -e "select CONCAT(table_schema, '.', table_name) from information_schema.tables where table_name like '${table_wildcard}';"`"
+ for table in $tables_found ; do
+ OPT_DATA="${OPT_DATA} --ignore-table=${table}"
+ done
+ done
+fi
+
if [ "$SEPDIR" = "yes" ]; then # Check if CREATE DATABSE should be included in Dump
if [ "$CREATE_DATABASE" = "no" ]; then
OPT="$OPT --no-create-db"

2 comments on commit d6046ef

Hiya, Wim. How hard would it be for your to introduce these changes into the latest version of AutoMySQLBackup? I took a gander, and it didn't seem so straightforward.

Owner

wimleers replied Sep 3, 2013

@derekderaps That's why I didn't do it originally. That's why I didn't do it. But feel free to try and get it merged back upstream!

Please sign in to comment.