Skip to content

Instantly share code, notes, and snippets.

@tureki
Created March 18, 2014 11:30
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 tureki/9618295 to your computer and use it in GitHub Desktop.
Save tureki/9618295 to your computer and use it in GitHub Desktop.
Linux mysql backup shell script
#!/bin/bash
export PGCLIENTENCODING="UTF8"
DBLIST="$@"
if [ -z "${DBLIST}" ]; then
DBLIST="all"
fi
#backup directory
BACKUP=/var/backup/database/mysql/
ARCHNAME=`date +%Y%m%d-%H`
YEARMONTH=`date +%y%m`
TODAY=`date +%d`
mkdir -p ${BACKUP}/${YEARMONTH}/${TODAY}
for DBNAME in ${DBLIST} ; do
BACKFILE=${DBNAME}.${ARCHNAME}.sql
if [ -f ${BACKUP}/${YEARMONTH}/${TODAY}/${BACKFILE} ]; then
continue
fi
mysqldump -u root --password=edyna168 --all-databases --skip-opt -h mysql.citytalk.tw > ${BACKUP}/${YEARMONTH}/${TODAY}/${BACKFILE}
bzip2 -z ${BACKUP}/${YEARMONTH}/${TODAY}/${BACKFILE}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment