Last active
November 15, 2017 02:27
-
-
Save alhoqbani/b3050e233b2c6aea2fd02b411ab03a9f to your computer and use it in GitHub Desktop.
Databases Backup using github
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 | |
| # Author: Hamoud Alhoqbani | |
| # Backup mysql database every day at 00:00 | |
| # crontab -e | |
| # 0 0 * * * /bin/bash /home/user/db_backup/db_backup.sh /home/user/db_backup/cron.log 2>&1 | |
| # Update these variables to your linking. | |
| CURRENT_TIME=$(date +"%Y-%m-%d %I:%M:%S") | |
| DB_USER= | |
| DB_PASS= | |
| DB_NAME= | |
| BACKUP_PATH=/home/hamoud/db_backup | |
| BACKUP_NAME='db_backup.sql' | |
| # Don't edit beyond this point. | |
| echo "START -------${CURRENT_TIME}---------" | |
| GIT_WORK_TREE=$BACKUP_PATH | |
| echo “Dump Database” | |
| cd $BACKUP_PATH | |
| mysqldump -u $DB_USER -p"$DB_PASS" $DB_NAME > $BACKUP_PATH/db_backup.sql | |
| echo “Commit changes to git and push” | |
| git add . | |
| git add $BACKUP_PATH/$BACKUP_NAME ;git commit -m "Latest Database Snapshot"; git push origin master | |
| echo “Done” | |
| echo "----------------------------------------- END" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment