diff --git a/AUTHORS b/AUTHORS index 541e949f6de9f08bd34769e82bc1a2a9590ae67e..79e338a770e33222f42ff2520ebd5da183bf9c9c 100644 --- a/AUTHORS +++ b/AUTHORS @@ -15,7 +15,7 @@ rhatto -- rub handler and patches Patches: cmccallum@thecsl.org -Daniel.Bonniot@inria.fr +Daniel.Bonniot@inria.fr -- mysql ignores and nodata Brad Fritz <brad@fritzfam.com> -- trac patch garcondumonde@riseup.net Martin Krafft madduck@debian.org -- admingroup patch diff --git a/ChangeLog b/ChangeLog index ba68c07e20ce486ce30fbfd456927a475b4b07d1..5aa1fd056795f12edca00db890f79ceac32bc64c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -24,6 +24,10 @@ version 0.9.5 -- unreleased mysql: . Fixed case where odd combination of configuration options caused sqldump backups to get overwritten with an empty file (Closes: #402679) + . Added 'nodata' option to enable you to specify tables that you want to omit + the data from a backup, but still backup the table structure. This is very + useful in cases where tables contain large amounts of cache data. See the + example.mysql for options, thanks Daniel Bonniot (Closes: #408829) pgsql: . Support configuring PGSQLUSER for real, and document it a bit; this broken support actually prevented pgsql handler to work for VServers diff --git a/examples/example.mysql b/examples/example.mysql index 25750ad725d06c589dfa42e1b1b3a983307f1db3..d7ab8b6ff0c144cb51590ba464de2c611ebb29f7 100644 --- a/examples/example.mysql +++ b/examples/example.mysql @@ -53,6 +53,13 @@ compress = yes # which databases to backup. should either be the word 'all' or a # space separated list of database names. # +# nodata = < table1 table2 table3 > (no default) +# only dump the structure for the database tables listed here, this means +# no data contained in these tables will be dumped. This is very useful +# to backup databases that have tables with cache stored in tables that +# isn't necessary to backup, but you still need the structure to exist +# on a restore +# # backupdir = < path/to/destination > (default = /var/backups/mysql) # where to dump the backups. hotcopy backups will be in a subdirectory # 'hotcopy' and sqldump backups will be in a subdirectory 'sqldump' diff --git a/handlers/mysql.in b/handlers/mysql.in index de4e4c3d2f920d8117c2e960e9c1f5e1619ccf22..64b6f492188b31429ceb9249abd9c748fd68d99c 100644 --- a/handlers/mysql.in +++ b/handlers/mysql.in @@ -6,6 +6,7 @@ getconf backupdir /var/backups/mysql getconf databases all getconf ignores +getconf nodata getconf dbhost localhost getconf hotcopy no getconf sqldump no @@ -47,7 +48,7 @@ fi ## This only works for mysqldump at the moment ignore='' -for i in $ignores; do +for i in $ignores $nodata; do ignore="$ignore --ignore-table=$i" done @@ -243,10 +244,27 @@ then fatal "Authentication problem, maybe user/password is wrong or mysqld is not running?" fi fi -fi + fi for db in $databases do + DUMP_BASE="$MYSQLDUMP $defaultsfile --lock-tables --complete-insert --add-drop-table --quick --quote-names" + + # Dumping structure and data + DUMP="$DUMP_BASE $ignore $db" + + # If requested, dump only the table structure for this database + if echo "$nodata" | grep -E '(^|[[:space:]])'"$db\." >/dev/null + then + # Get the structure of the tables, without data + DUMP_STRUCT="$DUMP_BASE --no-data $db" + for qualified_table in $nodata + do + table=$( expr match "$qualified_table" "$db\.\([^\w]*\)" ) + DUMP_STRUCT="$DUMP_STRUCT $table" + done + DUMP="( $DUMP; $DUMP_STRUCT )" + fi if [ $usevserver = yes ] then # Test to make sure mysqld is running, if it is not sqldump will not work @@ -255,9 +273,9 @@ fi fatal "Either you have an authentication problem, or mysqld doesn't appear to be running!" fi if [ "$compress" == "yes" ]; then - execstr="$VSERVER $vsname exec $MYSQLDUMP $defaultsfile --lock-tables --complete-insert --add-drop-table --quick --quote-names $ignore $db | $GZIP > $vroot$dumpdir/${db}.sql.gz" + execstr="$VSERVER $vsname exec $DUMP | $GZIP > $vroot$dumpdir/${db}.sql.gz" else - execstr="$VSERVER $vsname exec $MYSQLDUMP $defaultsfile --lock-tables --complete-insert --add-drop-table --quick --quote-names $ignore $db -r $vroot$dumpdir/${db}.sql" + execstr="$VSERVER $vsname exec $DUMP -r $vroot$dumpdir/${db}.sql" fi else # Test to make sure mysqld is running, if it is not sqldump will not work @@ -266,9 +284,9 @@ fi fatal "Either you have an authentication problem, or mysqld doesn't appear to be running!" fi if [ "$compress" == "yes" ]; then - execstr="$MYSQLDUMP $defaultsfile --lock-tables --complete-insert --add-drop-table --quick --quote-names $ignore $db | $GZIP > $dumpdir/${db}.sql.gz" + execstr="$DUMP | $GZIP > $dumpdir/${db}.sql.gz" else - execstr="$MYSQLDUMP $defaultsfile --lock-tables --complete-insert --add-drop-table --quick --quote-names $ignore $db -r $dumpdir/${db}.sql" + execstr="$DUMP -r $dumpdir/${db}.sql" fi fi debug "su $user -c \"$execstr\""