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 = { config, 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 # Need to have mysql started so that it can be populated with data.
27 $master->waitForUnit("mysql.service");
28
29 # Wait for testdb to be populated.
30 $master->sleep(10);
31
32 # Do a backup and wait for it to finish.
33 $master->startJob("mysql-backup.service");
34 $master->waitForJob("mysql-backup.service");
35
36 # Check that data appears in backup
37 $master->succeed("${pkgs.gzip}/bin/zcat /var/backup/mysql/testdb.gz | grep hello");
38
39 # Check that a failed backup is logged
40 $master->succeed("journalctl -u mysql-backup.service | grep 'fail.*doesnotexist' > /dev/null");
41 '';
42})