Re: One Button DB backup [Solved]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> On Nov 5, 2016, at 4:15 PM, Adam Jon Richardson <adamjonr@xxxxxxxxx> 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
tedd@xxxxxxxxxxxx






-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux