1# Test whether mysqlBackup option works
2import ./make-test.nix ({ pkgs, ... } : {
3 name = "mysql-backup";
4 meta = with pkgs.stdenv.lib.maintainers; {
5 maintainers = [ rvl ];
6 };
7
8 nodes = {
9 master = { pkgs, ... }: {
10 services.mysql = {
11 enable = true;
12 initialDatabases = [ { name = "testdb"; schema = ./testdb.sql; } ];
13 package = pkgs.mysql;
14 };
15
16 services.mysqlBackup = {
17 enable = true;
18 databases = [ "doesnotexist" "testdb" ];
19 };
20 };
21 };
22
23 testScript =
24 '' startAll;
25
26 # Delete backup file that may be left over from a previous test run.
27 # This is not needed on Hydra but useful for repeated local test runs.
28 $master->execute("rm -f /var/backup/mysql/testdb.gz");
29
30 # Need to have mysql started so that it can be populated with data.
31 $master->waitForUnit("mysql.service");
32
33 # Wait for testdb to be fully populated (5 rows).
34 $master->waitUntilSucceeds("mysql -u root -D testdb -N -B -e 'select count(id) from tests' | grep -q 5");
35
36 # Do a backup and wait for it to start
37 $master->startJob("mysql-backup.service");
38 $master->waitForJob("mysql-backup.service");
39
40 # wait for backup to fail, because of database 'doesnotexist'
41 $master->waitUntilFails("systemctl is-active -q mysql-backup.service");
42
43 # wait for backup file and check that data appears in backup
44 $master->waitForFile("/var/backup/mysql/testdb.gz");
45 $master->succeed("${pkgs.gzip}/bin/zcat /var/backup/mysql/testdb.gz | grep hello");
46
47 # Check that a failed backup is logged
48 $master->succeed("journalctl -u mysql-backup.service | grep 'fail.*doesnotexist' > /dev/null");
49 '';
50})