- # Test to make sure mysqld is running, if it is not sqldump will not work
- $vexec su $user -c "$MYSQLADMIN $defaultsfile ping"
- if [ $? -ne 0 ]; then
- fatal "Either you have an authentication problem, or mysqld doesn't appear to be running!"
- fi
- if [ "$compress" == "yes" ]; then
- execstr="$vexec $DUMP | $GZIP > $vroot$dumpdir/${db}.sql.gz"
- else
- execstr="$vexec $DUMP -r $vroot$dumpdir/${db}.sql"
- fi
-
- debug "su $user -c \"$execstr\""
- if [ ! $test ]
- then
- output=`su $user -c "$execstr" 2>&1`
- code=$?
- if [ "$code" == "0" ]
- then
- debug $output
- info "Successfully finished dump of mysql database $db"
- else
- warning $output
- warning "Failed to dump mysql databases $db"
- fi
- fi
- done
-fi
+ fi
+
+ for db in $databases
+ do
+ DUMP_BASE="$MYSQLDUMP $defaultsfile $sqldumpoptions"
+
+ # 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
+ # Test to make sure mysqld is running, if it is not sqldump will not work
+ $vexec su $user -c "$MYSQLADMIN $defaultsfile ping"
+ if [ $? -ne 0 ]; then
+ fatal "Either you have an authentication problem, or mysqld doesn't appear to be running!"
+ fi
+ if [ "$compress" == "yes" ]; then
+ execstr="$vexec $DUMP | $GZIP > $vroot$dumpdir/${db}.sql.gz"
+ else
+ execstr="$vexec $DUMP -r $vroot$dumpdir/${db}.sql"
+ fi
+
+ debug "su $user -c \"$execstr\""
+ if [ ! $test ]
+ then
+ output=`su $user -c "$execstr" 2>&1`
+ code=$?
+ if [ "$code" == "0" ]
+ then
+ debug $output
+ info "Successfully finished dump of mysql database $db"
+ else
+ warning $output
+ warning "Failed to dump mysql databases $db"
+ fi
+ fi
+ done
+ fi
+
+ # clean up tmp config file
+ if [ "$dbusername" != "" -a "$dbpassword" != "" ]
+ then
+ ## clean up tmp config file
+ debug "rm $mycnf"
+ rm $mycnf
+ if [ -f "$tmpcnf" ]
+ then
+ debug "mv $tmpcnf $mycnf"
+ mv $tmpcnf $mycnf
+ fi
+ fi
+}