Welcome to Geeklog Tuesday, May 21 2013 @ 07:03 AM EDT
As some of my already know, you can use PHP as a shell scripting language. While as a pure shell language it lacks some of the power of, say, Bash, it is still a viable option for the PHP coder.
This script is a PHP shell script I wrote that will back up a MySQL database. If you already have PHP compiled as a CGI on your system (see php.net's install docs for how to do that) then you can drop this in and it should work fine. The script keeps 7 daily backups, 4 weekly backups and 12 monthly backups which should make recovery much simpler.
In addition to the PHP CGI, you will need tar because the script will compress the database backups. For a point of reference, on my Geeklog database of over 500 stories and 450 users a backup is 1.6MB and only 515KB compressed. Give it a try and let me know what you think!
The following comments are owned by whomever posted them. This site is not responsible for what they say.
exec(\"$mysqldump -h$mysqlhost -u$mysqluser
$database > \" . $backup_dir . \'daily/\' . $backup_file);
to remove the -p for the password.
It would be nice to have a restore procedure!!!
Thanks,
Jerry
mysql -u user -p database < file.sql
?
after some minor tweaking it worked great. My PHP is installed as an APACHE module so I have to mess around a little more with getting it to work with lynx