RSS

Tag Archives: mysqldump

Backup mysql database to amazon S3

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);

?>


Lunarpages.com Web Hosting

Advertisements
 

Tags: , , , , , , , , , , , , , ,

MySQL backup by command line

# mysqldump -u username -p databasename > filename.sql
Compress the .sql file with gzip:

#gzip filename.sql

# mysqldump --all-databases > all_databases.sql

# mysqldump --user=root \
> --password=sa --host=localhost \
> database > backup.sql

# mysqldump --user=root --password=sa --host=localhost  database > /var/www/backup.sql
 
Leave a comment

Posted by on November 13, 2008 in Linux, php, resources

 

Tags: , , ,