Skip to content

Instantly share code, notes, and snippets.

@AjayKumar01
Last active November 15, 2016 10:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AjayKumar01/f1f1cfab112d8b8d5a02a339c5899388 to your computer and use it in GitHub Desktop.
Save AjayKumar01/f1f1cfab112d8b8d5a02a339c5899388 to your computer and use it in GitHub Desktop.
Script to take automatic db backup daily basis
#!/bin/bash
#Script to take automatic db dump
#Written by Ajay Kumar
#Dated 07 July 2016
DBUSERNAME="root"
DBPASS="*******"
BACKUPDIR="/home/restore/"
TODAY=`date +"%A"`
#enter database names here
DBs=( sugar_dev )
#if backupdirectory doesn't exist, create it
if [ ! -d "$BACKUPDIR" ]; then
mkdir -p "$BACKUPDIR"
fi
for database in "${DBs[@]}"; do
#concate directory path, today's day and dbname with .sql ext
filename=$BACKUPDIR${database}_${TODAY}.sql
#take dump
mysqldump -u$DBUSERNAME -p$DBPASS $database > $filename
#compress it
gzip -f $filename
done
-------
Add the below entry in crontab
0 20 * * * sh /root/cronfiles/daily_db_dump
This will get execute everyday 8PM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment