From a9e8e6d3250130a84af4095a3f37609f737107f8 Mon Sep 17 00:00:00 2001 From: Matthew Kent Date: Mon, 25 Feb 2013 13:16:06 -0600 Subject: [PATCH] Write out xtrabackup, mysql and innobackupex versions within the backup. --- innobackupex | 58 ++++++++++++++++++++++++++++++++++++++- test/t/ib_backup_info_basic.sh | 34 +++++++++++++++++++++++ test/t/ib_backup_info_rsync.sh | 17 ++++++++++++ test/t/ib_backup_info_stream.sh | 18 ++++++++++++ 4 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 test/t/ib_backup_info_basic.sh create mode 100644 test/t/ib_backup_info_rsync.sh create mode 100644 test/t/ib_backup_info_stream.sh diff --git a/innobackupex b/innobackupex index f201397..943ac4f 100755 --- a/innobackupex +++ b/innobackupex @@ -181,6 +181,9 @@ my $galera_info; # name of the file where slave info is written my $slave_info; +# name of the file where backup info is written +my $backup_info; + # mysql binlog position as given by "SHOW MASTER STATUS" command my $mysql_binlog_position = ''; @@ -441,6 +444,8 @@ sub backup { mysql_send('START SLAVE SQL_THREAD;'); } + write_backup_info(); + # Close the DB connection mysql_close(); @@ -716,7 +721,7 @@ sub copy_back { get_option(\%config, $option_defaults_group, 'innodb_log_group_home_dir'); my $iblog_files = 'ib_logfile.*'; my $excluded_files = - '\.\.?|backup-my\.cnf|xtrabackup_logfile|' . + '\.\.?|backup-my\.cnf|xtrabackup_logfile|xtrabackup_backup_info|' . 'xtrabackup_binary|xtrabackup_binlog_info|xtrabackup_checkpoints|' . '.*\.qp|' . $iblog_files; @@ -1474,6 +1479,54 @@ sub write_slave_info { $mysql_slave_position = "master host '$master', filename '$filename', position $position"; } +# +# write_backup_info subroutine writes out a file containting the running MySQL +# version, installed xtrabackup version and current innobackup version. +# +sub write_backup_info { + my @lines; + my @info_lines; + my $cmdline; + my $mysql_version = ''; + my $xtrabackup_version = ''; + + # grab version from running mysql + mysql_send 'SELECT VERSION() as Version\G'; + + # parse it + file_to_array($mysql_stdout, \@lines); + for (@lines) { + $mysql_version = $1 if /Version:\s*(\S*)\s*$/; + } + + # grab version from xtrabackup + $cmdline = "$option_ibbackup_binary -v 2>&1"; + @lines = `$cmdline`; + + # and parse it + for (@lines) { + $xtrabackup_version = $1 if / version (\S*) /; + } + + # print collected version info to a file + if (!$option_remote_host) { + open(FILE, ">$backup_info") || + Die "Failed to open file '$backup_info': $!"; + } else { + open(FILE, "| ssh $option_ssh_opt $option_remote_host 'cat > $backup_info'") || + Die "Failed to open file '$option_remote_host:$backup_info': $!"; + } + print FILE "mysql_version = $mysql_version\n"; + print FILE "xtrabackup_version = $xtrabackup_version\n"; + print FILE "innobackup_version = $innobackup_version\n"; + close(FILE); + + if ($option_stream) { + system("cd $option_tmpdir; $stream_cmd xtrabackup_backup_info") + and Die "Failed to stream 'xtrabackup_backup_info': $!"; + unlink $backup_info || Die "Failed to delete '$backup_info': $!"; + } +} # # mysql_lockall subroutine puts a read lock on all tables in all databases. @@ -1747,6 +1800,7 @@ sub init { $binlog_info = $backup_dir . '/xtrabackup_binlog_info'; $galera_info = $backup_dir . '/xtrabackup_galera_info'; $slave_info = $backup_dir . '/xtrabackup_slave_info'; + $backup_info = $backup_dir . '/xtrabackup_backup_info'; } else { $suspend_file = $option_tmpdir . '/xtrabackup_suspended'; $tmp_logfile = $option_tmpdir . '/xtrabackup_logfile'; @@ -1755,11 +1809,13 @@ sub init { $binlog_info = $option_tmpdir . '/xtrabackup_binlog_info'; $galera_info = $option_tmpdir . '/xtrabackup_galera_info'; $slave_info = $option_tmpdir . '/xtrabackup_slave_info'; + $backup_info = $option_tmpdir . '/xtrabackup_backup_info'; } else { $backup_config_file = $backup_dir . '/backup-my.cnf'; $binlog_info = $backup_dir . '/xtrabackup_binlog_info'; $galera_info = $backup_dir . '/xtrabackup_galera_info'; $slave_info = $backup_dir . '/xtrabackup_slave_info'; + $backup_info = $backup_dir . '/xtrabackup_backup_info'; } } write_backup_config_file($backup_config_file); diff --git a/test/t/ib_backup_info_basic.sh b/test/t/ib_backup_info_basic.sh new file mode 100644 index 0000000..4bbddc6 --- /dev/null +++ b/test/t/ib_backup_info_basic.sh @@ -0,0 +1,34 @@ +######################################################################## +# Test that xtrabackup_backup_info is included in a copied backup +######################################################################## + +. inc/common.sh + +start_server + +# take a backup with stream mode +innobackupex --no-timestamp $topdir/backup + +mysql_version=`${MYSQL} ${MYSQL_ARGS} -Ns -e "select version()"` +xtrabackup_version=`xtrabackup -v 2>&1 | cut -d" " -f3` + +if [ -f $topdir/backup/xtrabackup_backup_info ] ; then + vlog "xtrabackup_backup_info was backed up" +else + vlog "xtrabackup_backup_info was not backed up" + exit -1 +fi + +if grep "$mysql_version" $topdir/backup/xtrabackup_backup_info; then + vlog "found $mysql_version in xtrabackup_backup_info" +else + vlog "couldn't find $mysql_version in xtrabackup_backup_info" + exit -1 +fi + +if grep "$xtrabackup_version" $topdir/backup/xtrabackup_backup_info; then + vlog "found $xtrabackup_version in xtrabackup_backup_info" +else + vlog "couldn't find $xtrabackup_version in xtrabackup_backup_info" + exit -1 +fi diff --git a/test/t/ib_backup_info_rsync.sh b/test/t/ib_backup_info_rsync.sh new file mode 100644 index 0000000..30d518c --- /dev/null +++ b/test/t/ib_backup_info_rsync.sh @@ -0,0 +1,17 @@ +######################################################################## +# Test that xtrabackup_backup_info is included in a rsynced backup +######################################################################## + +. inc/common.sh + +start_server + +# take a backup with stream mode +innobackupex --rsync --no-timestamp $topdir/backup + +if [ -f $topdir/backup/xtrabackup_backup_info ] ; then + vlog "xtrabackup_backup_info was backed up" +else + vlog "xtrabackup_backup_info was not backed up" + exit -1 +fi diff --git a/test/t/ib_backup_info_stream.sh b/test/t/ib_backup_info_stream.sh new file mode 100644 index 0000000..0a3ab55 --- /dev/null +++ b/test/t/ib_backup_info_stream.sh @@ -0,0 +1,18 @@ +######################################################################## +# Test that xtrabackup_backup_info is included in a stream backup +######################################################################## + +. inc/common.sh + +start_server + +# take a backup with stream mode +mkdir -p $topdir/backup +innobackupex --stream=tar $topdir/backup > $topdir/backup/stream.tar + +if $TAR itf $topdir/backup/stream.tar | grep ^xtrabackup_backup_info; then + vlog "xtrabackup_backup_info was backed up" +else + vlog "xtrabackup_backup_info was not backed up" + exit -1 +fi -- 1.7.9.6 (Apple Git-31.1)