Last active
January 31, 2016 05:56
-
-
Save vishalbasnet23/dfe0fc5a72964961310c to your computer and use it in GitHub Desktop.
Auto Backup all the databases every 30 days on server
This file contains hidden or 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 | |
USER="USER_NAME" | |
PASSWORD="PASSWORD" | |
OUTPUT="BACKUP_PATH" | |
#Deletes all the files before dumping again | |
rm "$OUTPUT/*gz" > /dev/null 2>&1 | |
databases=`mysql --user=$USER --password=$PASSWORD -e "SHOW DATABASES;" | tr -d "| " | grep -v Database` | |
for db in $databases; do | |
if [[ "$db" != "information_schema" ]] && [[ "$db" != _* ]] ; then | |
echo "Dumping database: $db" | |
mysqldump --force --opt --user=$USER --password=$PASSWORD --databases $db > $OUTPUT/`date +%Y%m%d`.$db.sql | |
gzip $OUTPUT/`date +%Y%m%d`.$db.sql | |
fi | |
done |
This file contains hidden or 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
crontab -e | |
0 0 */3 * * /PATH/autobck.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment