One of the Best way for Automatic data Backup to S3🤔 — Using AutoMySQLBackup with S3cmd 💪

“Oh my god, server crashed”… looks like we lost all production data, am dazzled, don’t know what to do 😨 — Most of the developers / administrators would have crossed this phase.

Its worst when you have to face it in production. Sharing one such experience here 🙂

One of my mentor told me to do auto backup the DB(Database).

Then I found a way to backup my data, Which I am using in my production.

I used “automysqlbackup” which will help you to dump your data.

Install this package, then install S3cmd and write a cron hopefully you will get your daily backup 😃

Just install this package and write a cron — In which time your data to be backup and where you need to store backup.

Let us start, How to install automysqlbackup by the following commands.

STEP 1 — Installing AutoMySQLBackup

$apt-get install automysqlbackup

STEP 2 — Configure AutoMySQLBackup

After installing “automysqlbackup” we need to configure the automysqlbackup file.

Open the automysqlbackup.conf file by using below command,

$vi /etc/automysqlbackup/automysqlbackup.conf

A new file will be open, in that file set the below configuration directives:

CONFIG_mysql_dump_username='your_mysql_username'
CONFIG_mysql_dump_password='mysql_password'
CONFIG_mysql_dump_host='yourhost'
CONFIG_backup_dir='yourbackup_path'
CONFIG_do_monthly="01"
CONFIG_do_weekly="5"
CONFIG_rotation_daily=6
CONFIG_rotation_weekly=35
CONFIG_rotation_monthly=150
CONFIG_mysql_dump_port=3306
CONFIG_mysql_dump_compression='gzip

Create a directory to backup your MySql files.

$mkdir var/backup — Set this path as backup_dir in your automysqlbackup.conf file 👍🏻

All set 😉, In terminal run $automysqlbackup 😱

Check your backup directory you will have your DB backup up to date… 🤞🏻

Now that you got your backup, you should execute this command regularly for daily / weekly backup as your need be.

To reduce your work we can write our own cron and push this DB backup to AWS S3. It is more secure and your data will be safe and it is in separate place.Whenever you need your data you can fetch it from S3.

For more details have a short look on it, http://docs.aws.amazon.com/AmazonS3/latest/dev/Welcome.html

Create an account and buy a bucket in S3 to backup your DB.

STEP 3— Installing S3 cmd

Let us start commanding to install S3 in your system,

$ sudo apt-get install s3cmd

STEP 4— Configure S3

Once it is done, type $s3cmd — -configure it asks you to enter your Access Key 🗝 and Secret Key 🔐

S3 Configuration
Notes: In S3 you can also move your files,folders,etc..

STEP 5— Run your own CronTab

After installing S3 cmd, open CronTab by $sudo crontab -e

If you have cron tab it opens else it initiate a new cron tab by the above command.

And Paste Bellow lines:

01 00 * * * sudo automysqlbackup

03 00 * * * sudo s3cmd put -r /var/backup s3://your_bucket_name

Thats it.. !🤗

Happieeeee Backup(ing) 😎

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.