Skip to content

Instantly share code, notes, and snippets.

@forkbombe
Created September 1, 2015 07:54
Show Gist options
  • Save forkbombe/bc5fdc0db19b912a7d5b to your computer and use it in GitHub Desktop.
Save forkbombe/bc5fdc0db19b912a7d5b to your computer and use it in GitHub Desktop.
Automated backup of MySQL database via cron
#!/bin/sh
USER=$1
PASS=$2
DB=$3
HOST=''
DATE=`date +"%Y%m%d"`
cd ~/db-daily
mysqldump -u $USER -p$PASS -h $HOST $DB | gzip > $DB.sql.gz
# Run backup.sh from home directory every day at 3am
0 3 * * * bash ~/backup.sh DATABASEUSER DATABASEPASS DATABASENAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment