Skip to content

Instantly share code, notes, and snippets.

@ceekz
Last active October 7, 2015 03:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ceekz/3098850 to your computer and use it in GitHub Desktop.
Save ceekz/3098850 to your computer and use it in GitHub Desktop.
Backup shell script for MySQL
#!/bin/sh
keepday=14
dir=/home/dbbackup
file=dump.sql
now_date=`date +%Y%m%d`
old_date=`date "-d$keepday days ago" +%Y%m%d`
cd $dir
mysqldump -u USER -h HOST --password='PASS' --default-character-set=binary --hex-blob DB > $file
zip -q $now_date.zip $file
rm -f $old_date.zip $file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment