Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to take MySQL Database backup and put it in Amazon s3 every Night by using Cron tab?

I have got one server in Rackspace and i'm already running a cron job evry day night to process something...(some account related operation- that will send me email every mid night). my application is in groovy on grails. now i want to take mysql database (called myfleet) backup on every mid night and put that file in Amezon S3 . how can i do that? do i need to write any java or groovy file to process that? or is it can be done from Linux box itself? i have already got account in Amezon S3 (bucket name is fleetBucket)

like image 834
maaz Avatar asked May 30 '11 10:05

maaz


1 Answers

You can also use STDOUT and the AWS CLI tool to pipe the output of your mysqldump straight to S3:

mysqldump -h [db_hostname] -u [db_user] -p[db_passwd] [databasename] | aws s3 cp - s3://[s3_bucketname]/[mysqldump_filename]

For example:

mysqldump -h localhost -u db_user -ppassword test-database | aws s3 cp - s3://database-mysqldump-bucket/test-database-dump.sql

The mysqldump command outputs to STDOUT by default. Using - as the input argument for aws s3 cp tells the AWS CLI tool to use STDIN for the input.

like image 180
Sam Critchley Avatar answered Sep 23 '22 19:09

Sam Critchley