Skip to content

Instantly share code, notes, and snippets.

@taiko19xx
Created March 3, 2013 08:03
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 taiko19xx/5075264 to your computer and use it in GitHub Desktop.
Save taiko19xx/5075264 to your computer and use it in GitHub Desktop.
mysqldump with gzip(monthly)
#!/bin/bash
_dir='/path/to/target/'
_target=`date +"%Y%m"`
if test ! -d $_dir$_target
then
mkdir $_dir$_target
_last=`date -d '1 month ago' +"%Y%m"`
if test -d $_dir$_last
then
cd $_dir
tar cvzf ${_last}.tar.gz $_last
rm -rf $_dir$_last
fi
fi
_file=`date +"%Y-%m-%d"`
cd $_dir$_target
mysqldump -uxxx -pxxx database > ${_file}.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment