Shell Script For Mysql Backup

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 1

www.coretimer.

com

#!/bin/bash
export DB_BACKUP="/backup/mysql_backup"
export DB_USER="root"
export DB_PASSWD="pass123"
rm -rf $DB_BACKUP/04             # Removing oldest backup
mv $DB_BACKUP/03 $DB_BACKUP/04   #moving next to oldest
mv $DB_BACKUP/02 $DB_BACKUP/03
mv $DB_BACKUP/01 $DB_BACKUP/02
mkdir -p $DB_BACKUP/01
mysqldump --user=$DB_USER --password=$DB_PASSWD --all-databases | gzip >
$DB_BACKUP/01/mysql-`date +%Y-%m-%d`.gz
exit 0

Then add this entry to crontab to automate the task


#crontab -e
30  12 *  *  *  /usr/bin/back_mysql.sh

This will execute everyday at 12.30

You might also like