Merge pull request #203452 from robryk/restic
nixos/tests/restic: readability & not parsing human-readable output
This commit is contained in:
commit
86730cdb4b
1 changed files with 43 additions and 19 deletions
|
@ -2,9 +2,8 @@ import ./make-test-python.nix (
|
||||||
{ pkgs, ... }:
|
{ pkgs, ... }:
|
||||||
|
|
||||||
let
|
let
|
||||||
password = "some_password";
|
remoteRepository = "/tmp/restic-backup";
|
||||||
repository = "/tmp/restic-backup";
|
remoteFromFileRepository = "/tmp/restic-backup-from-file";
|
||||||
repositoryFile = "${pkgs.writeText "repositoryFile" "/tmp/restic-backup-from-file"}";
|
|
||||||
rcloneRepository = "rclone:local:/tmp/restic-rclone-backup";
|
rcloneRepository = "rclone:local:/tmp/restic-rclone-backup";
|
||||||
|
|
||||||
backupPrepareCommand = ''
|
backupPrepareCommand = ''
|
||||||
|
@ -18,7 +17,6 @@ import ./make-test-python.nix (
|
||||||
'';
|
'';
|
||||||
|
|
||||||
passwordFile = "${pkgs.writeText "password" "correcthorsebatterystaple"}";
|
passwordFile = "${pkgs.writeText "password" "correcthorsebatterystaple"}";
|
||||||
initialize = true;
|
|
||||||
paths = [ "/opt" ];
|
paths = [ "/opt" ];
|
||||||
pruneOpts = [
|
pruneOpts = [
|
||||||
"--keep-daily 2"
|
"--keep-daily 2"
|
||||||
|
@ -40,12 +38,18 @@ import ./make-test-python.nix (
|
||||||
{
|
{
|
||||||
services.restic.backups = {
|
services.restic.backups = {
|
||||||
remotebackup = {
|
remotebackup = {
|
||||||
inherit repository passwordFile initialize paths pruneOpts backupPrepareCommand backupCleanupCommand;
|
inherit passwordFile paths pruneOpts backupPrepareCommand backupCleanupCommand;
|
||||||
|
repository = remoteRepository;
|
||||||
|
initialize = true;
|
||||||
};
|
};
|
||||||
remotebackup-from-file = {
|
remote-from-file-backup = {
|
||||||
inherit repositoryFile passwordFile initialize paths pruneOpts;
|
inherit passwordFile paths pruneOpts;
|
||||||
|
initialize = true;
|
||||||
|
repositoryFile = pkgs.writeText "repositoryFile" remoteFromFileRepository;
|
||||||
};
|
};
|
||||||
rclonebackup = {
|
rclonebackup = {
|
||||||
|
inherit passwordFile paths pruneOpts;
|
||||||
|
initialize = true;
|
||||||
repository = rcloneRepository;
|
repository = rcloneRepository;
|
||||||
rcloneConfig = {
|
rcloneConfig = {
|
||||||
type = "local";
|
type = "local";
|
||||||
|
@ -57,14 +61,15 @@ import ./make-test-python.nix (
|
||||||
[local]
|
[local]
|
||||||
type=ftp
|
type=ftp
|
||||||
'';
|
'';
|
||||||
inherit passwordFile initialize paths pruneOpts;
|
|
||||||
};
|
};
|
||||||
remoteprune = {
|
remoteprune = {
|
||||||
inherit repository passwordFile;
|
inherit passwordFile;
|
||||||
|
repository = remoteRepository;
|
||||||
pruneOpts = [ "--keep-last 1" ];
|
pruneOpts = [ "--keep-last 1" ];
|
||||||
};
|
};
|
||||||
custompackage = {
|
custompackage = {
|
||||||
inherit repository passwordFile paths;
|
inherit passwordFile paths;
|
||||||
|
repository = "some-fake-repository";
|
||||||
package = pkgs.writeShellScriptBin "restic" ''
|
package = pkgs.writeShellScriptBin "restic" ''
|
||||||
echo "$@" >> /tmp/fake-restic.log;
|
echo "$@" >> /tmp/fake-restic.log;
|
||||||
'';
|
'';
|
||||||
|
@ -82,50 +87,69 @@ import ./make-test-python.nix (
|
||||||
server.start()
|
server.start()
|
||||||
server.wait_for_unit("dbus.socket")
|
server.wait_for_unit("dbus.socket")
|
||||||
server.fail(
|
server.fail(
|
||||||
"${pkgs.restic}/bin/restic -r ${repository} -p ${passwordFile} snapshots",
|
"${pkgs.restic}/bin/restic -r ${remoteRepository} -p ${passwordFile} snapshots",
|
||||||
'${pkgs.restic}/bin/restic --repository-file ${repositoryFile} -p ${passwordFile} snapshots"',
|
'${pkgs.restic}/bin/restic -r ${remoteFromFileRepository} -p ${passwordFile} snapshots"',
|
||||||
"${pkgs.restic}/bin/restic -r ${rcloneRepository} -p ${passwordFile} snapshots",
|
"${pkgs.restic}/bin/restic -r ${rcloneRepository} -p ${passwordFile} snapshots",
|
||||||
"grep 'backup .* /opt' /tmp/fake-restic.log",
|
"grep 'backup .* /opt' /tmp/fake-restic.log",
|
||||||
)
|
)
|
||||||
server.succeed(
|
server.succeed(
|
||||||
|
# set up
|
||||||
"mkdir -p /opt",
|
"mkdir -p /opt",
|
||||||
"touch /opt/some_file",
|
"touch /opt/some_file",
|
||||||
"mkdir -p /tmp/restic-rclone-backup",
|
"mkdir -p /tmp/restic-rclone-backup",
|
||||||
|
|
||||||
|
# test that remotebackup runs custom commands and produces a snapshot
|
||||||
"timedatectl set-time '2016-12-13 13:45'",
|
"timedatectl set-time '2016-12-13 13:45'",
|
||||||
"systemctl start restic-backups-remotebackup.service",
|
"systemctl start restic-backups-remotebackup.service",
|
||||||
"rm /opt/backupCleanupCommand",
|
"rm /opt/backupCleanupCommand",
|
||||||
"systemctl start restic-backups-remotebackup-from-file.service",
|
'${pkgs.restic}/bin/restic -r ${remoteRepository} -p ${passwordFile} snapshots --json | ${pkgs.jq}/bin/jq "length | . == 1"',
|
||||||
|
|
||||||
|
# test that remote-from-file-backup produces a snapshot
|
||||||
|
"systemctl start restic-backups-remote-from-file-backup.service",
|
||||||
|
'${pkgs.restic}/bin/restic -r ${remoteFromFileRepository} -p ${passwordFile} snapshots --json | ${pkgs.jq}/bin/jq "length | . == 1"',
|
||||||
|
|
||||||
|
# test that rclonebackup produces a snapshot
|
||||||
"systemctl start restic-backups-rclonebackup.service",
|
"systemctl start restic-backups-rclonebackup.service",
|
||||||
'${pkgs.restic}/bin/restic -r ${repository} -p ${passwordFile} snapshots -c | grep -e "^1 snapshot"',
|
'${pkgs.restic}/bin/restic -r ${rcloneRepository} -p ${passwordFile} snapshots --json | ${pkgs.jq}/bin/jq "length | . == 1"',
|
||||||
'${pkgs.restic}/bin/restic --repository-file ${repositoryFile} -p ${passwordFile} snapshots -c | grep -e "^1 snapshot"',
|
|
||||||
'${pkgs.restic}/bin/restic -r ${rcloneRepository} -p ${passwordFile} snapshots -c | grep -e "^1 snapshot"',
|
# test that custompackage runs both `restic backup` and `restic check` with reasonable commandlines
|
||||||
"systemctl start restic-backups-custompackage.service",
|
"systemctl start restic-backups-custompackage.service",
|
||||||
"grep 'backup .* /opt' /tmp/fake-restic.log",
|
"grep 'backup .* /opt' /tmp/fake-restic.log",
|
||||||
"grep 'check .* --some-check-option' /tmp/fake-restic.log",
|
"grep 'check .* --some-check-option' /tmp/fake-restic.log",
|
||||||
|
|
||||||
|
# test that we can create four snapshots in remotebackup and rclonebackup
|
||||||
"timedatectl set-time '2017-12-13 13:45'",
|
"timedatectl set-time '2017-12-13 13:45'",
|
||||||
"systemctl start restic-backups-remotebackup.service",
|
"systemctl start restic-backups-remotebackup.service",
|
||||||
"rm /opt/backupCleanupCommand",
|
"rm /opt/backupCleanupCommand",
|
||||||
"systemctl start restic-backups-rclonebackup.service",
|
"systemctl start restic-backups-rclonebackup.service",
|
||||||
|
|
||||||
"timedatectl set-time '2018-12-13 13:45'",
|
"timedatectl set-time '2018-12-13 13:45'",
|
||||||
"systemctl start restic-backups-remotebackup.service",
|
"systemctl start restic-backups-remotebackup.service",
|
||||||
"rm /opt/backupCleanupCommand",
|
"rm /opt/backupCleanupCommand",
|
||||||
"systemctl start restic-backups-rclonebackup.service",
|
"systemctl start restic-backups-rclonebackup.service",
|
||||||
|
|
||||||
"timedatectl set-time '2018-12-14 13:45'",
|
"timedatectl set-time '2018-12-14 13:45'",
|
||||||
"systemctl start restic-backups-remotebackup.service",
|
"systemctl start restic-backups-remotebackup.service",
|
||||||
"rm /opt/backupCleanupCommand",
|
"rm /opt/backupCleanupCommand",
|
||||||
"systemctl start restic-backups-rclonebackup.service",
|
"systemctl start restic-backups-rclonebackup.service",
|
||||||
|
|
||||||
"timedatectl set-time '2018-12-15 13:45'",
|
"timedatectl set-time '2018-12-15 13:45'",
|
||||||
"systemctl start restic-backups-remotebackup.service",
|
"systemctl start restic-backups-remotebackup.service",
|
||||||
"rm /opt/backupCleanupCommand",
|
"rm /opt/backupCleanupCommand",
|
||||||
"systemctl start restic-backups-rclonebackup.service",
|
"systemctl start restic-backups-rclonebackup.service",
|
||||||
|
|
||||||
"timedatectl set-time '2018-12-16 13:45'",
|
"timedatectl set-time '2018-12-16 13:45'",
|
||||||
"systemctl start restic-backups-remotebackup.service",
|
"systemctl start restic-backups-remotebackup.service",
|
||||||
"rm /opt/backupCleanupCommand",
|
"rm /opt/backupCleanupCommand",
|
||||||
"systemctl start restic-backups-rclonebackup.service",
|
"systemctl start restic-backups-rclonebackup.service",
|
||||||
'${pkgs.restic}/bin/restic -r ${repository} -p ${passwordFile} snapshots -c | grep -e "^4 snapshot"',
|
|
||||||
'${pkgs.restic}/bin/restic -r ${rcloneRepository} -p ${passwordFile} snapshots -c | grep -e "^4 snapshot"',
|
'${pkgs.restic}/bin/restic -r ${remoteRepository} -p ${passwordFile} snapshots --json | ${pkgs.jq}/bin/jq "length | . == 4"',
|
||||||
|
'${pkgs.restic}/bin/restic -r ${rcloneRepository} -p ${passwordFile} snapshots --json | ${pkgs.jq}/bin/jq "length | . == 4"',
|
||||||
|
|
||||||
|
# test that remoteprune brings us back to 1 snapshot in remotebackup
|
||||||
"systemctl start restic-backups-remoteprune.service",
|
"systemctl start restic-backups-remoteprune.service",
|
||||||
'${pkgs.restic}/bin/restic -r ${repository} -p ${passwordFile} snapshots -c | grep -e "^1 snapshot"',
|
'${pkgs.restic}/bin/restic -r ${remoteRepository} -p ${passwordFile} snapshots --json | ${pkgs.jq}/bin/jq "length | . == 1"',
|
||||||
|
|
||||||
)
|
)
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue