diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2010-02-02 06:01:29 +0100 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2010-02-02 06:01:29 +0100 |
commit | 6f460e45a2606167a54bb8dbc718da001d7663b5 (patch) | |
tree | 187313a4b5eb0ee344dc2ff124d1f7dc04e30ab9 | |
parent | f6cd196d2eade11a439177072f8b91d78a67fab3 (diff) | |
download | backup-6f460e45a2606167a54bb8dbc718da001d7663b5.tar.gz backup-6f460e45a2606167a54bb8dbc718da001d7663b5.tar.xz backup-6f460e45a2606167a54bb8dbc718da001d7663b5.zip |
save binlog position and flush logs before backup
-rwxr-xr-x | mysql/mysql_backup.sh | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/mysql/mysql_backup.sh b/mysql/mysql_backup.sh index a255314..689fb70 100755 --- a/mysql/mysql_backup.sh +++ b/mysql/mysql_backup.sh @@ -41,10 +41,16 @@ _check_tools mysqlshow mysqldump ncftpput echo "Started backup of mysql databases ($(date +%c)):" | _log echo | _log -# pause the replication to be able to do consistent backups -echo "STOP SLAVE SQL_THREAD;" | mysql -h${MYSQL_SERVER} -u${MYSQL_USER} \ +# flush logs on master +# get master +MYSQL_MASTER=$(sed -n '4p' /var/lib/mysql/master.info) + +echo "flush logs;" | mysql -h${MYSQL_MASTER} -u${MYSQL_USER} \ -p${MYSQL_PASSWORD} +# pause the replication to be able to do consistent backups +mysqladmin -h${MYSQL_SERVER} -u${MYSQL_USER} -p${MYSQL_PASSWORD} stop-slave + # create temporary dir mkdir -p ${TMP_DIRECTORY} TMP_DIR=$(mktemp -d --tmpdir=${TMP_DIRECTORY}) @@ -55,16 +61,19 @@ MYSQL_DATABASES=$(mysqlshow -h${MYSQL_SERVER} -u${MYSQL_USER} \ -p${MYSQL_PASSWORD} | awk '{ print $2 }' | grep -v "^$" | sed \ '1d') +# get binlog position +MYSQL_BINLOG=$(sed -n '2p;3p' /var/lib/mysql/master.info | while read i + do echo -n "-$i" ; done) + # 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" + ${db} | bzip2 -zc > "${BACKUP_PREFIX}-${db}${MYSQL_BINLOG}.sql.bz2" done # restart the replication -echo "START SLAVE SQL_THREAD;" | mysql -h${MYSQL_SERVER} -u${MYSQL_USER} \ - -p${MYSQL_PASSWORD} +mysqladmin -h${MYSQL_SERVER} -u${MYSQL_USER} -p${MYSQL_PASSWORD} start-slave # echo created log of file sizes du -sch * | _log |