about summary refs log tree commit diff
path: root/nixos/tests
diff options
context:
space:
mode:
authorRodney Lorrimar <dev@rodney.id.au>2017-09-23 15:58:07 +0100
committerRobin Gloster <mail@glob.in>2017-09-27 18:44:49 +0200
commit56eba66f77bb1d4711e824158e3b9a8d55a929f1 (patch)
treedab3d2a609304bfa93422bf493c41ae48a0997e3 /nixos/tests
parent75ba415fbcfe48fdf5fb88f2aa461ce83921303f (diff)
downloadnixlib-56eba66f77bb1d4711e824158e3b9a8d55a929f1.tar
nixlib-56eba66f77bb1d4711e824158e3b9a8d55a929f1.tar.gz
nixlib-56eba66f77bb1d4711e824158e3b9a8d55a929f1.tar.bz2
nixlib-56eba66f77bb1d4711e824158e3b9a8d55a929f1.tar.lz
nixlib-56eba66f77bb1d4711e824158e3b9a8d55a929f1.tar.xz
nixlib-56eba66f77bb1d4711e824158e3b9a8d55a929f1.tar.zst
nixlib-56eba66f77bb1d4711e824158e3b9a8d55a929f1.zip
mysqlBackup service: let it work with default settings
* Grants enough privileges to the configured user so that it can run
  mysqldump.

* Adds a nixos test.

* Use systemd timers instead of a cronjob (by @fadenb).

* Creates a new user for backups by default, instead of using mysql
  user.

* Ensures that backup user has write permissions on backup location.

* Write backup to a temporary file before renaming so that a failed
  backup won't overwrite the previous backup, and so that the backup
  location will never contain a partial backup.

Breaking changes:

 * Renamed period to calendar to reflect the change in how to
   configure the backup time.

 * A failed backup will no longer result in cron sending an e-mail --
   users' monitoring systems must be updated.

Resolves #24728
Diffstat (limited to 'nixos/tests')
-rw-r--r--nixos/tests/mysql-backup.nix42
-rw-r--r--nixos/tests/testdb.sql1
2 files changed, 43 insertions, 0 deletions
diff --git a/nixos/tests/mysql-backup.nix b/nixos/tests/mysql-backup.nix
new file mode 100644
index 000000000000..f5bcc460cba7
--- /dev/null
+++ b/nixos/tests/mysql-backup.nix
@@ -0,0 +1,42 @@
+# Test whether mysqlBackup option works
+import ./make-test.nix ({ pkgs, ... } : {
+  name = "mysql-backup";
+  meta = with pkgs.stdenv.lib.maintainers; {
+    maintainers = [ rvl ];
+  };
+
+  nodes = {
+    master = { config, pkgs, ... }: {
+      services.mysql = {
+        enable = true;
+        initialDatabases = [ { name = "testdb"; schema = ./testdb.sql; } ];
+        package = pkgs.mysql;
+      };
+
+      services.mysqlBackup = {
+        enable = true;
+        databases = [ "doesnotexist" "testdb" ];
+      };
+    };
+  };
+
+  testScript =
+    '' startAll;
+
+       # Need to have mysql started so that it can be populated with data.
+       $master->waitForUnit("mysql.service");
+
+       # Wait for testdb to be populated.
+       $master->sleep(10);
+
+       # Do a backup and wait for it to finish.
+       $master->startJob("mysql-backup.service");
+       $master->waitForJob("mysql-backup.service");
+
+       # Check that data appears in backup
+       $master->succeed("${pkgs.gzip}/bin/zcat /var/backup/mysql/testdb.gz | grep hello");
+
+       # Check that a failed backup is logged
+       $master->succeed("journalctl -u mysql-backup.service | grep 'fail.*doesnotexist' > /dev/null");
+    '';
+})
diff --git a/nixos/tests/testdb.sql b/nixos/tests/testdb.sql
index 4fb28fea3df9..3c68c49ae82c 100644
--- a/nixos/tests/testdb.sql
+++ b/nixos/tests/testdb.sql
@@ -8,3 +8,4 @@ insert into tests values (1, 'a');
 insert into tests values (2, 'b');
 insert into tests values (3, 'c');
 insert into tests values (4, 'd');
+insert into tests values (5, 'hello');