[libvirt-users] KVM incremental backup using CBT

Thomas Stein himbeere at meine-oma.de
Mon Nov 3 10:28:34 UTC 2014


Am 03.11.14 09:39, schrieb Eric Blake:
> On 11/02/2014 02:13 PM, Thomas Stein wrote:
> 
>> After a little bit of fiddling i've got this running. Here is what's 
>> neccessary in case someone wanna try this too.
> 
> That's awesome news! Thanks for sharing.
> 
> 
>> https://github.com/qemu/qemu/blob/master/scripts/qemu-guest-agent/fsfreeze-hook.d/mysql-flush.sh.sample
>> 
>> I had to adjust this script a little for mariadb 10.0.14. But after that 
>> everything works as expected.
> 
> Do you want to post your version of the script for others to learn from?

Sure. Here we go:

----
#!/bin/bash -x

# Flush MySQL tables to the disk before the filesystem is freezed.
# At the same time, this keeps a read lock while the filesystem is freezed
# in order to avoid write accesses by the other clients.

MYSQL="mysql -uroot -ppassword"
FIFO=/tmp/mysql-flush.fifo

flush_and_wait() {
    printf "FLUSH TABLES WITH READ LOCK \\G\n"
    read < $FIFO
    printf "UNLOCK TABLES \\G\n"
}

case "$1" in
    freeze)
        mkfifo $FIFO || exit 1
        flush_and_wait | $MYSQL &
        # wait until every block is flushed
        while [ "$(echo 'SHOW STATUS LIKE "Key_blocks_not_flushed"' |\
                 $MYSQL | tail -1 | cut -f 2)" -gt 0 ]; do
            sleep 1
        done
        # for InnoDB, wait until every log is flushed
        INNODB_STATUS=$(mktemp /tmp/mysql-flush.XXXXXX)
        [ $? -ne 0 ] && exit 2
       trap "rm -f $INNODB_STATUS" SIGINT
        while :; do
            printf "SHOW ENGINE INNODB STATUS \\G" | $MYSQL >
$INNODB_STATUS

            LOG_CURRENT=$(grep 'Log sequence number' $INNODB_STATUS tr
-s ' ' | cut -d' ' -f4)

            LOG_FLUSHED=$(grep 'Log flushed up to' $INNODB_STATUS tr -s
' ' | cut -d' ' -f7)

            [ "$LOG_CURRENT" = "$LOG_FLUSHED" ] && break
            sleep 1
        done
        rm -f $INNODB_STATUS
        ;;

    thaw)
        [ ! -p $FIFO ] && exit 1
        echo > $FIFO
        rm -f $FIFO
        ;;
esac
----

cheers
t.




More information about the libvirt-users mailing list