Skip to content

Instantly share code, notes, and snippets.

@alhoqbani
Last active November 15, 2017 02:27
Show Gist options
  • Select an option

  • Save alhoqbani/b3050e233b2c6aea2fd02b411ab03a9f to your computer and use it in GitHub Desktop.

Select an option

Save alhoqbani/b3050e233b2c6aea2fd02b411ab03a9f to your computer and use it in GitHub Desktop.
Databases Backup using github
#!/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