Last active
November 15, 2016 10:43
-
-
Save AjayKumar01/f1f1cfab112d8b8d5a02a339c5899388 to your computer and use it in GitHub Desktop.
Script to take automatic db backup daily basis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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