Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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