mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-23 06:01:15 +00:00
56eba66f77
* 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
43 lines
1.2 KiB
Nix
43 lines
1.2 KiB
Nix
# 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");
|
|
'';
|
|
})
|