diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2009-12-11 00:27:50 +0100 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2009-12-11 00:27:50 +0100 |
commit | 350aa36802a674ed8f5181aaec8525fa14cdee2e (patch) | |
tree | 7552dae06066a685cfae9f1b2349c24085717976 | |
parent | cd110f2944e9fb37cd1f21bb869d24949f6941f0 (diff) | |
download | backup-350aa36802a674ed8f5181aaec8525fa14cdee2e.tar.gz backup-350aa36802a674ed8f5181aaec8525fa14cdee2e.tar.xz backup-350aa36802a674ed8f5181aaec8525fa14cdee2e.zip |
remove mysql binlog reset, server wide lock is not possible
-rwxr-xr-x | mysql/mysql_backup.sh | 30 |
1 files 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 |