Πέμπτη 25 Οκτωβρίου 2007

How to backup mysql using php, and shell script, the easy way

As I was trying to find an easy way to backup a MySQL database with no ssh access to the server, there should be better ways, but i found this easy one. You will need a Shell script, a .php script. Ok, lets make this work
First create a shell script with this line
mysqldump --opt -u [user_name] -p [database_name] | gzip>[backup_file].dump.gz
and name it, lets say:
the_backup_script.sh
Now create the .php script that will call the shell script.
It will contain this:
<?php
echo exec('./the_back_script.sh');
?>
and name it, for instance
the_backup_php_script.php
Until this point this should work, just copy the two files using your ftp account in the root directory of your site.
Here comes the security issue, nobody wants that somebody discover this file and can get all you mysql database, so you have some options.
1. Create a complete server based security like shown here: http://www.pagetutor.com/keeper/http_authentication.html
2. Erase the files from your server once used, and upload them each time you may need to do a backup.

Δεν υπάρχουν σχόλια: