Mysqldump help


#1

I’ve recently switched over to Dreamhost (two days ago), and am working on making all of my scripts work on the new server. This one was written for me so I don’t understand it perfectly, this is just a snippet. BACKUPDIR is defined earlier as where I would like the backup to go. Now I’ve tried specifying the host, and I’ve tried saying a specific database instead of just the catch all databases, but that didn’t work either. Let’s assume I always want to back up all the databases, and all the tables therein. What do I do?

[php] // do we want to back up all databases?
$backupall = ($_POST[‘backupall’] == ‘false’) ? false : true;

// if we want to back up all databases, set this to -A in the command (backs up all), if not, set it to the name of the database to back up
$dbarg = $backupall ? '-A' : $_POST['backupwhichdb'];

// form our command to execute
$command = "mysqldump ".$dbarg." -u ".$_POST['mysqluser']." -p".$_POST['mysqlpass']." -r \"".BACKUPDIR.$_POST['filename']."\" 2>&1";

[/php]

This is the current version I am working on:

[php]
$command = “mysqldump -h mysql.absurdity981.com -u “.$_POST[‘mysqluser’].” -p”.$_POST[‘mysqlpass’]." -B absurdity981_sitemap “”.BACKUPDIR.$_POST[‘filename’]."" 2>&1";
[/php]

It displays all the database info in the page, instead of sending it to a new page. As well I get the error:

mysqldump: Got error: 1102: Incorrect database name ‘/home/kochier/www/absurdity981.com/library/22Mar2013_23.11.47.sql’ when selecting the database at the bottom of the page.

EDIT: Also if I use -A it’ll display a list of options "Usage: mysqldump [OPTIONS] database [tables] OR mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3…] OR mysqldump [OPTIONS] --all-databases [OPTIONS] For more options, use mysqldump --help " that I’m not sure how to utilize.


#2

Push it out to a file.

variables:

$usr = dbusername
$psw = dbpassword
$sql = dbhostname
$aff = an optional affix, such as date()

command format:

mysqldump --opt -u $usr -p$psw -h $sql -A > $sql_$aff.sql

#3

Thanks that helped me a lot. I just had things in the wrong order.[php]$command = “mysqldump -c -u “.$_POST[‘mysqluser’].” -p”.$_POST[‘mysqlpass’]." -h mysql.absurdity981.com -A > “.$_POST[‘filename’].” 2>&1";[/php]

That is the final code I used.


#4

Just FYI, you should change the subdomain that your database is hosted on because now that it’s clear what it is, anyone can attempt a dictionary attack on it by visiting http://absurdity981.com/dh_phpmyadmin/mysql.absurdity981.com


#5

^ Good advice that everyone should consider seriously.

Big random strings using a [nonsense].dreamhosters.com sub-domain work.

mysqloihs6dd98.adf935hr392fdsuf.dreamhosters.com


#6

Will do, thanks for the advice.