Automating Database Backups
All,
I wanted to get everyone's feedback on automating database backups. I am in the process of developing the procedure for how to backup my growing number of Fuel sites and it would help if a few things that are cloudy for me right now could be explained:
1) First, which option is better? Use ci_cron.php or use CI's CLI? (options stated here:
http://getfuelcms.com/user_guide/modules/cronjobs)
2) When running a backup manually in the Fuel admin via the Backup module, it outputs a zip file to the data_backup folder with a date of when the backup is run in the filename. Is there a way using Cron to have a single file be overwritten each time a new backup is made rather than accumulate many many files over a certain amount of time? Or, is there any way that Fuel can aid in automating the removal of x amount of previous backup files that are not needed, say like 5 previous ones?
Thanks,
Erik
Comments
On this page: http://getfuelcms.com/user_guide/modules/cronjobs under "Database Backup" the examples shown there in the code view look unfamiliar to me as a cron novice. Where would I insert this code to be run? In the Fuel Cronjob module or somewhere in the fuel/crons folder?
What's tripping me up is the prefacing of each line with "php". Isn't it supposed to start with the numbers representing the hour, day, and days of week that the job is supposed to run?
PHP Warning: set_time_limit(): Cannot set time limit in safe mode in /var/www/vhosts/example.com/httpdocs/fuel/crons/ci_cron.php on line 72
Noticed that PHP deprecated safe mode, so I'm not sure what to do here. Should I comment out this line?
Erik
More on cron jobs:
http://www.webmasters-central.com/article-blog/tutorials/cron-tutorial-managing-cron-tab-or-cron-job-is-easy/
There is also a good shell script that we sometimes use if the database is big (due to memory issues using CI's database backup utility) and can sometimes be a simpler approach because you don't have to worry about the PHP user being able to run cron jobs:
http://sourceforge.net/projects/automysqlbackup/
You can comment out that line in the ci_cron.php file. However, I'm not sure if the admin interface for creating the cron will work in safe_mode.
Also, we will be addressing the issue of specifying the date with the file name as well as doing cleanup of older files in an upcoming release.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Error</title> <style> html,body { margin: 20px 0 10px 0; padding: 0; } body { font: 11px Arial, Helvetica, sans-serif; text-align: center; } h1 { margin: 0; padding:0; font-family: Arial,Helvetica,sans-serif; font-size: 22px; color: #999; font-weight: normal; padding: 10px 4px 5px 0; } p { font-size: 12px; margin: 0 0 10px 0; line-height: 15px; } a { color: #690; text-decoration: none; } a:hover { color: #333; text-decoration: underline; } #error_general { width: 500px; margin: auto; border: 1px solid #ddd; padding: 0 20px 20px 20px;} </style> </head> <body> <div id="error_general"> <h1>An Error Was Encountered</h1> <p>The URI you submitted has disallowed characters.</p> </div> </body> </html>
Looks like the error has to do with disallowed characters in the URI. Any idea where that is happening so I can fix that? Does this have to do with my cron command? Here is the command I am using just for reference:
php /var/www/vhosts/example.com/httpdocs/fuel/crons/ci_cron.php --run=/fuel/cron/db_backup
php /var/www/vhosts/example.com/httpdocs/fuel/crons/ci_cron.php backup/cron
When i try in my terminal the cron command:
~/htdocs/project/fuel/crons$ php ci_cron.php /fuel/my_module/my_controller/test
i get an error
Notice: Undefined offset: -1 in /Applications/MAMP/htdocs/toptennis/fuel/modules/fuel/config/fuel_constants.php on line 17
and a Database error
Unable to connect to your database server using the provided settings.
Filename: third_party/fuel/Loader.php
Line Number: 134
what am I doing wrong?
if (defined('STDIN')) { /* if your FUEL installation exists in a subfolder, then you may want to change SCRIPT_NAME to /subfolder/index.php (Needed for using Tester module if running via CLI) */ $_SERVER['SCRIPT_NAME'] = 'index.php'; $_SERVER['SERVER_NAME'] = 'localhost'; $_SERVER['SERVER_PORT'] = 80; $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; $_SERVER['HTTP_HOST'] = 'localhost'; }
Also, CI 2.0 provides CLI access via the index.php:
cd /path/to/webfolder/ php index.php /fuel/my_module/my_controller/test
and again the database connection error. Any clue?
define('WEB_FOLDER', (count($_FUEL_SEGS) > 1) ? $_FUEL_SEGS[count($_FUEL_SEGS)-2] : '/');
For the database connection issue, are you using MAMP by chance or do you have multiple versions of PHP? If so, try changing "php" command to point to another version or using the full path to the other PHP binary (e.g. /Applications/MAMP/bin/php/php5.2.17/bin/php). In my case, I have database issues with the PHP version that comes with OSX but the MAMP version does not so I use that instead.
http://stackoverflow.com/questions/8480663/changing-the-default-php-command-path
http://serverfault.com/questions/315022/how-to-change-php-binary-location-in-osx-command-line
Solved both issues, thank you very much!!!