diff --git a/innobackupex b/innobackupex index 517202a..5ca318d 100755 --- a/innobackupex +++ b/innobackupex @@ -192,6 +192,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 = ''; @@ -457,6 +460,8 @@ sub backup { mysql_query(\%mysql, 'START SLAVE SQL_THREAD;'); } + write_backup_info(); + # copy ib_lru_dump # Copy buffer poll dump and/or LRU dump foreach my $dump_name ($buffer_pool_filename, 'ib_lru_dump') { @@ -805,6 +810,7 @@ sub copy_back { my $excluded_files = '\.\.?|backup-my\.cnf|xtrabackup_logfile|' . 'xtrabackup_binary|xtrabackup_binlog_info|xtrabackup_checkpoints|' . + 'xtrabackup_backup_info|' . '.*\.qp|' . '.*\.pmap|.*\.tmp|' . $iblog_files . '|'. @@ -1602,6 +1608,40 @@ 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 $xtrabackup_version = ''; + + # 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 + open(FILE, ">$backup_info") || + Die "Failed to open file '$backup_info': $!"; + + print FILE "mysql_server_version = $mysql_server_version\n"; + print FILE "xtrabackup_version = $xtrabackup_version\n"; + print FILE "innobackup_version = $innobackup_version\n"; + close(FILE); + + if ($option_stream) { + stream_encrypt_file($option_tmpdir, '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. @@ -1833,6 +1873,7 @@ sub init { $binlog_info = $work_dir . '/xtrabackup_binlog_info'; $galera_info = $work_dir . '/xtrabackup_galera_info'; $slave_info = $work_dir . '/xtrabackup_slave_info'; + $backup_info = $work_dir . '/xtrabackup_backup_info'; write_backup_config_file($backup_config_file); foreach (@xb_suspend_files) { diff --git a/test/t/ib_backup_info_basic.sh b/test/t/ib_backup_info_basic.sh new file mode 100644 index 0000000..416757b --- /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_server_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_server_version" $topdir/backup/xtrabackup_backup_info; then + vlog "found $mysql_server_version in xtrabackup_backup_info" +else + vlog "couldn't find $mysql_server_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