Below is the simple code to create sql script of database on Amazon EC2 server using “mysqldump”…
then upload this sql script to Amazon S3 bucket using command line S3 tool “s3cmd”…
<?php
$sqlbackup=”/usr/bin/mysqldump -v -u root -h localhost -r /var/www/html/backup/”.date(“Y-m-d-H-i-s”).”_db.sql -pdbusername databasename 2>&1″;
exec($sqlbackup, $o);
echo implode(“<br /> “, $o);
$file = “/var/www/html/backup/”.date(“Y-m-d-H-i-s”).”_db.sql”;
$bucket = “s3bucketname”;
exec(“/usr/bin/s3cmd put –acl-public –guess-mime-type –config=/var/www/html/.s3cfg “.$file.” s3://”.$bucket.” 2>&1″, $o);
echo implode(“<br /> “, $o);
?>
2 Responses to Backup mysql database to amazon S3
Leave a Reply
You must be logged in to post a comment.
You completed several good points there. I did so searching within the issue and found almost all people goes in conjunction with along with your blog.
Thanks, these will keep me thinking for a couple of weeks.