Re: [PHP] One Button DB backup [Solved]

[email protected] (Tedd Sperling)
Newsgroups php.general
Message-ID <[email protected]>
> On Nov 5, 2016, at 4:15 PM, Adam Jon Richardson <[email protected]> wrote:
> 
>> Something like this little bit of code works:
>> 
>> $command = "mysqldump --add-drop-table -h localhost " .
>> "-u USERNAME -p PASSWORD DBNAME > FILETOPIPETO";
>> $ret_val = null;
>> // create current backup
>> $output = system($command, $ret_val);
> 
> Just a few quick follow-up points on this method:
> 
> 1) This approach shouldn't be used on a shared server, as the command-line
> logs could be viewed by others to gain the DB credentials (not an issue in
> the cases I've used this approach, as the server was only hosting one
> website.)
> 
> 2) I forgot that this approach requires no space between the password and
> the -p argument, so it should read:
> $command = "mysqldump --add-drop-table -h localhost " .
> "-u USERNAME -pPASSWORD DBNAME > FILETOPIPETO";
> $ret_val = null;
> // create current backup
> $output = system($command, $ret_val);

Adam:

It worked, but I modified the code a bit:

//=== start of code ===

$filename = "backup-" . date("d-m-Y") . ".sql";

$cmd = "mysqldump --opt -h $db_host -u $db_user -p$db_pass $db_name > $filename";

$null = null;
$content = system($cmd, $null);

exit(0);

//=== end of code ===

The “opt" does a lot of things including locking the db down.

Thanks!

Cheers,

tedd
_______________
tedd sperling
[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.