Backup MySQL Databases to Amazon S3 Using PHP
With a few lines of PHP code and S3tool’s s3cmd command-line tool you can backup your MySQL databases automatically to Amazon’s S3. To use this script you’ll need SSH access to your server. First download s3cmd and upload it to your server. Installation is straight forward. The PHP code is simple:
|
|
exec("mysqldump -udbuser1 -p12345 --databases db1 db2 > /home/user1/dbbackup-".date('Y-m-d').".sql");
exec("tar -zcvf /home/user1/dbbackup-".date('Y-m-d').".tar.gz /home/user1/dbbackup-".date('Y-m-d').".sql");
unlink("/home/user1/dbbackup-".date('Y-m-d').".sql");
@unlink("/home/user1/dbbackup-".date('Y-m-d', strtotime("now -3 days")).".tar.gz");
exec("s3cmd put /home/user1/dbbackup-".date('Y-m-d').".tar.gz s3://database-backups"); |
The first line [...]
Connect
Connect with us on the following social media platforms.