Q & A

  • GNU/Linux.ro
  • 1 year ago

Here is the sample shellscript to take  backup of all batabase

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
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  10 *  *  *  /usr/bin/back_mysql.sh

This will execute everyday at 10.30