Skip to content

Commit 051f681

Browse files
MDEV-39061 mariadb-backup compatible wrappers for BACKUP SERVER
scripts/mariabackup/mariabackup.sh: a drop-in wrapper that lets existing mariabackup invocations drive the server-side BACKUP SERVER command without changing user scripts. mariabackup.sh covers all four mariabackup modes. --backup translates into "BACKUP SERVER TO '<dir>'" via the mariadb client, forwarding connection options, and layers --stream/--compress as tar/gzip pipelines on the result. --prepare runs mariadbd --bootstrap on backup.cnf so InnoDB applies the archived redo log. --copy-back / --move-back drop a prepared backup into the datadir via cp -r / mv. --prepare --incremental-dir copies the incremental's ib_logfile* into the base and advances innodb_log_recovery_target; innodb_log_recovery_start stays pinned to the base checkpoint. --apply-log-only maps to --innodb-force-recovery=3 to skip rollback between incrementals. --rollback-xa runs two passes: normal recovery, then a second bootstrap with --tc-heuristic-recover=ROLLBACK. --copy-back / --move-back refuse a non-empty datadir unless --force-non-empty-directories is set, and print the post-action chown / systemctl start commands. For incremental --backup, innodb_log_archive_start is treated as a startup-only, read-only server invariant: the wrapper reads @@global.innodb_log_archive_start and fails fast if the archive floor exceeds the base backup's end LSN. Limitations: --export is accepted but not yet implemented; the wrapper prints a warning and runs plain recovery without producing the per-table .cfg files needed for ALTER TABLE ... IMPORT TABLESPACE. mbstream.sh shims the mbstream CLI onto tar, dropping mbstream-only flags (-p/--parallel) so legacy pipelines keep working. README.md maps every supported option per mode to its BACKUP SERVER equivalent and documents the backup.cnf format. Add include/have_mariabackup_wrapper.inc redirects $XTRABACKUP to the wrapper so a test opts in by sourcing one file; skips when the wrapper, bash, or the mariadb client is unavailable. wrapper_basic.test: exercises full backup, streaming, compression, the ignored legacy options.
1 parent 5633fc2 commit 051f681

6 files changed

Lines changed: 1072 additions & 0 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# ==== Purpose ====
2+
#
3+
# Redirect `$XTRABACKUP` so existing test invocations like
4+
#
5+
# --exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf \
6+
# --backup --target-dir=$targetdir
7+
#
8+
# run through scripts/mariabackup/mariabackup.sh — the BACKUP SERVER
9+
# compatibility wrapper — without any change to the test body.
10+
#
11+
#
12+
# Skip the test if any of these are missing:
13+
# - the wrapper script
14+
# - bash
15+
# - the mariadb client (wrapper shells out to it)
16+
#
17+
# ==== Usage ====
18+
#
19+
# --source include/have_mariabackup_wrapper.inc
20+
# # ... rest of the test, using $XTRABACKUP as usual ...
21+
#
22+
# ==== Exposed variables ====
23+
#
24+
# $XTRABACKUP — now points at mariabackup.sh
25+
26+
--source include/linux.inc
27+
28+
--let MARIABACKUP_WRAPPER=$MYSQL_TEST_DIR/../scripts/mariabackup/mariabackup.sh
29+
30+
--error 0,1
31+
perl;
32+
use strict;
33+
use warnings;
34+
use File::Basename;
35+
36+
my $wrapper = $ENV{MARIABACKUP_WRAPPER};
37+
exit 1 unless $wrapper && -x $wrapper;
38+
39+
chomp(my $bash = `command -v bash 2>/dev/null`);
40+
exit 1 unless $bash && -x $bash;
41+
42+
# Prepend its directory to PATH so the bare `mariadb` invocation
43+
# inside the wrapper resolves.
44+
my ($mariadb) = split /\s+/, ($ENV{MYSQL} // '');
45+
exit 1 unless $mariadb && -x $mariadb;
46+
$ENV{PATH} = dirname($mariadb) . ":$ENV{PATH}";
47+
48+
exit 0;
49+
EOF
50+
51+
if ($errno)
52+
{
53+
--skip mariabackup.sh wrapper unavailable (script, bash, or mariadb client missing)
54+
}
55+
56+
--let XTRABACKUP=$MARIABACKUP_WRAPPER
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
CREATE TABLE t1(a INT PRIMARY KEY) ENGINE=InnoDB;
2+
INSERT INTO t1 VALUES (1), (2), (3);
3+
#
4+
# Full backup succeeds and runs BACKUP SERVER
5+
#
6+
FOUND 1 /Executing: BACKUP SERVER TO/ in wrapper.log
7+
#
8+
# (--parallel/--throttle/--no-lock/--safe-slave-backup)
9+
#
10+
FOUND 1 /Executing: BACKUP SERVER TO/ in wrapper.log
11+
#
12+
# --stream=mbstream emits a valid tar archive to stdout
13+
#
14+
FOUND 1 /Creating tar stream/ in wrapper.log
15+
#
16+
# --compress produces a valid gzip stream
17+
#
18+
FOUND 1 /Compressing with gzip/ in wrapper.log
19+
#
20+
# Backup into an already-existing target directory is rejected
21+
#
22+
FOUND 1 /Target directory already exists/ in wrapper.log
23+
#
24+
# Missing --target-dir is rejected
25+
#
26+
FOUND 1 /--target-dir required/ in wrapper.log
27+
#
28+
# Non-existent parent directory is rejected
29+
#
30+
FOUND 1 /Parent directory does not exist/ in wrapper.log
31+
DROP TABLE t1;
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
--source include/have_mariabackup_wrapper.inc
2+
--source include/have_innodb.inc
3+
4+
--let $defaults=--defaults-file=$MYSQLTEST_VARDIR/my.cnf
5+
--let $logfile=$MYSQLTEST_VARDIR/tmp/wrapper.log
6+
--let SEARCH_FILE=$logfile
7+
--let SEARCH_ABORT=NOT FOUND
8+
9+
CREATE TABLE t1(a INT PRIMARY KEY) ENGINE=InnoDB;
10+
INSERT INTO t1 VALUES (1), (2), (3);
11+
12+
--echo #
13+
--echo # Full backup succeeds and runs BACKUP SERVER
14+
--echo #
15+
--let $targetdir=$MYSQLTEST_VARDIR/tmp/bk_full
16+
--exec $XTRABACKUP $defaults --backup --target-dir=$targetdir > $logfile 2>&1
17+
--let SEARCH_PATTERN=Executing: BACKUP SERVER TO
18+
--source include/search_pattern_in_file.inc
19+
--rmdir $targetdir
20+
21+
--echo #
22+
--echo # (--parallel/--throttle/--no-lock/--safe-slave-backup)
23+
--echo #
24+
--let $targetdir=$MYSQLTEST_VARDIR/tmp/bk_legacy
25+
--exec $XTRABACKUP $defaults --backup --target-dir=$targetdir --parallel=4 --throttle=100 --no-lock --safe-slave-backup > $logfile 2>&1
26+
--let SEARCH_PATTERN=Executing: BACKUP SERVER TO
27+
--source include/search_pattern_in_file.inc
28+
--rmdir $targetdir
29+
30+
--echo #
31+
--echo # --stream=mbstream emits a valid tar archive to stdout
32+
--echo #
33+
--let $targetdir=$MYSQLTEST_VARDIR/tmp/bk_stream
34+
--let $streamfile=$MYSQLTEST_VARDIR/tmp/bk_stream.tar
35+
--exec $XTRABACKUP $defaults --backup --target-dir=$targetdir --stream=mbstream > $streamfile 2>$logfile
36+
--exec tar -tf $streamfile > /dev/null
37+
--let SEARCH_PATTERN=Creating tar stream
38+
--source include/search_pattern_in_file.inc
39+
--rmdir $targetdir
40+
--remove_file $streamfile
41+
42+
--echo #
43+
--echo # --compress produces a valid gzip stream
44+
--echo #
45+
--let $targetdir=$MYSQLTEST_VARDIR/tmp/bk_gz
46+
--let $gzfile=$MYSQLTEST_VARDIR/tmp/bk.tar.gz
47+
--exec $XTRABACKUP $defaults --backup --target-dir=$targetdir --compress > $gzfile 2>$logfile
48+
--exec gzip -t $gzfile
49+
--let SEARCH_PATTERN=Compressing with gzip
50+
--source include/search_pattern_in_file.inc
51+
--rmdir $targetdir
52+
--remove_file $gzfile
53+
54+
--echo #
55+
--echo # Backup into an already-existing target directory is rejected
56+
--echo #
57+
--let $targetdir=$MYSQLTEST_VARDIR/tmp/bk_exists
58+
--mkdir $targetdir
59+
--error 1
60+
--exec $XTRABACKUP $defaults --backup --target-dir=$targetdir > $logfile 2>&1
61+
--let SEARCH_PATTERN=Target directory already exists
62+
--source include/search_pattern_in_file.inc
63+
--rmdir $targetdir
64+
65+
--echo #
66+
--echo # Missing --target-dir is rejected
67+
--echo #
68+
--error 1
69+
--exec $XTRABACKUP $defaults --backup > $logfile 2>&1
70+
--let SEARCH_PATTERN=--target-dir required
71+
--source include/search_pattern_in_file.inc
72+
73+
--echo #
74+
--echo # Non-existent parent directory is rejected
75+
--echo #
76+
--error 1
77+
--exec $XTRABACKUP $defaults --backup --target-dir=$MYSQLTEST_VARDIR/tmp/no_such_parent/bk > $logfile 2>&1
78+
--let SEARCH_PATTERN=Parent directory does not exist
79+
--source include/search_pattern_in_file.inc
80+
81+
DROP TABLE t1;
82+
--remove_file $logfile

0 commit comments

Comments
 (0)