strago Posted May 26, 2010 Share Posted May 26, 2010 I'm making a simple script that optimizes all the databases twice, and then backs them up, so I can let crontab do all the work daily and all I have to do is download them. <? $datestamp = date("m-d-Y-h-i-s"); // Current date and time to put on filename of backup file in format of MM-DD-YYYY--hour-minute-second $optimize = "mysqlcheck -u root -pPASSWORD --auto-repair --check --optimize --all-databases"; $optimizeresult = passthru($optimize); //Make sure it's completely optimized. $optimizeresult2 = passthru($optimize); $command = "mysqldump -u root -pPASSWORD database > /FULL_PATH/back-ups/database-$datestamp.sql"; $result2 = passthru($command); $command2 = "mysqldump -u root -pPASSWORD database2 > /FULL_PATH/back-ups/database2-$datestamp.sql"; $result3 = passthru($command2); $command3 = "mysqldump -u root -pPASSWORD database3 > /FULL_PATH/back-ups/database3-$datestamp.sql"; $result4 = passthru($command3); ?> Is there any way to combine the three back-ups in to one command? So it creates a file for each database. Is there any thing that should be added to the optimize code? Like some anti-lock and unlock tables code? Link to comment https://forums.phpfreaks.com/topic/202916-possible-to-improve-this-little-optimizeback-up-script/ Share on other sites More sharing options...
BillyBoB Posted May 26, 2010 Share Posted May 26, 2010 I found your answer pretty easily with google... http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html#option_mysqldump_databases <? $datestamp = date("m-d-Y-h-i-s"); // Current date and time to put on filename of backup file in format of MM-DD-YYYY--hour-minute-second $optimize = "mysqlcheck -u root -pPASSWORD --auto-repair --check --optimize --all-databases"; $optimizeresult = passthru($optimize); //Make sure it's completely optimized. $optimizeresult2 = passthru($optimize); $command = "mysqldump -u root -pPASSWORD --databases database database2 database3 > /FULL_PATH/back-ups/databases-$datestamp.sql"; $result2 = passthru($command); ?> That should help Link to comment https://forums.phpfreaks.com/topic/202916-possible-to-improve-this-little-optimizeback-up-script/#findComment-1063381 Share on other sites More sharing options...
strago Posted May 26, 2010 Author Share Posted May 26, 2010 Except that doesn't give each database it's own file. Link to comment https://forums.phpfreaks.com/topic/202916-possible-to-improve-this-little-optimizeback-up-script/#findComment-1063383 Share on other sites More sharing options...
BillyBoB Posted May 26, 2010 Share Posted May 26, 2010 Ok then I would advise doing a loop. <? $datestamp = date("m-d-Y-h-i-s"); // Current date and time to put on filename of backup file in format of MM-DD-YYYY--hour-minute-second $optimize = "mysqlcheck -u root -pPASSWORD --auto-repair --check --optimize --all-databases"; $optimizeresult = passthru($optimize); //Make sure it's completely optimized. $optimizeresult2 = passthru($optimize); $i = 0; while($i<3) { $command[$i] = "mysqldump -u root -pPASSWORD database".$i=0?:$i+1." > /FULL_PATH/back-ups/database".$i=0?:$i+1."-$datestamp.sql"; $result[$i] = passthru($command[$i]); $i++; } ?> I didn't test it but it should be close. Link to comment https://forums.phpfreaks.com/topic/202916-possible-to-improve-this-little-optimizeback-up-script/#findComment-1063386 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.