From 350aa36802a674ed8f5181aaec8525fa14cdee2e Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Fri, 11 Dec 2009 00:27:50 +0100 Subject: remove mysql binlog reset, server wide lock is not possible --- mysql/mysql_backup.sh | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/mysql/mysql_backup.sh b/mysql/mysql_backup.sh index 632c010..6ce5281 100755 --- a/mysql/mysql_backup.sh +++ b/mysql/mysql_backup.sh @@ -7,6 +7,10 @@ MYSQL_SERVER="localhost" MYSQL_USER="backup" MYSQL_PASSWORD="password" +# databases to exclude, seperated by space +# TODO +#MYSQL_EXCLUDE_DB="" + # ftp server data FTP_SERVER="backup" FTP_USER="ftp" @@ -42,18 +46,28 @@ mkdir -p ${TMP_DIRECTORY} TMP_DIR=$(mktemp -d --tmpdir=${TMP_DIRECTORY}) pushd ${TMP_DIR} >/dev/null 2>&1 -# backup all databases to file and reset binlog -mysqldump -h${MYSQL_SERVER} -u${MYSQL_USER} -p${MYSQL_PASSWORD} \ - --flush-logs --master-data=2 --all-databases --delete-master-logs \ - --lock-all-tables | bzip2 -zc > "${BACKUP_PREFIX}.sql.bz2" +# enumerate all mysql databases +MYSQL_DATABASES=$(mysqlshow -h${MYSQL_SERVER} -u${MYSQL_USER} \ + -p${MYSQL_PASSWORD} | awk '{ print $2 }' | grep -v "^$" | sed \ + '1d') + +# backup all databases to file +for db in ${MYSQL_DATABASES} +do + mysqldump -h${MYSQL_SERVER} -u${MYSQL_USER} -p${MYSQL_PASSWORD} \ + ${db} | bzip2 -zc > "${BACKUP_PREFIX}_${db}.sql.bz2" +done # echo created log of file sizes -du -sch "${BACKUP_PREFIX}.sql.bz2" | _log +du -sch * | _log echo | _log -# move backup to ftp server -ncftpput -u"${FTP_USER}" -p"${FTP_PASSWORD}" -V -DD "${FTP_SERVER}" \ - "${FTP_TARGET}" "${BACKUP_PREFIX}.sql.bz2" >/dev/null +# move backups to ftp server +for file in * +do + ncftpput -u${FTP_USER} -p${FTP_PASSWORD} -V -DD ${FTP_SERVER} \ + ${FTP_TARGET} ${file} >/dev/null +done echo "Finished backup of mysql databases ($(date +%c))" | _log -- cgit v1.2.3