mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-13 21:50:33 +03:00
nixos/restic: fix #264696 and add a regression test
Make sure that preStart and postStop are included in all cases when they are nonempty.
This commit is contained in:
parent
9ec80ed610
commit
536401e90a
2 changed files with 14 additions and 3 deletions
|
@ -345,7 +345,7 @@ in
|
||||||
} // optionalAttrs (backup.environmentFile != null) {
|
} // optionalAttrs (backup.environmentFile != null) {
|
||||||
EnvironmentFile = backup.environmentFile;
|
EnvironmentFile = backup.environmentFile;
|
||||||
};
|
};
|
||||||
} // optionalAttrs (backup.initialize || backup.dynamicFilesFrom != null || backup.backupPrepareCommand != null) {
|
} // optionalAttrs (backup.initialize || doBackup || backup.backupPrepareCommand != null) {
|
||||||
preStart = ''
|
preStart = ''
|
||||||
${optionalString (backup.backupPrepareCommand != null) ''
|
${optionalString (backup.backupPrepareCommand != null) ''
|
||||||
${pkgs.writeScript "backupPrepareCommand" backup.backupPrepareCommand}
|
${pkgs.writeScript "backupPrepareCommand" backup.backupPrepareCommand}
|
||||||
|
@ -360,12 +360,12 @@ in
|
||||||
${pkgs.writeScript "dynamicFilesFromScript" backup.dynamicFilesFrom} >> ${filesFromTmpFile}
|
${pkgs.writeScript "dynamicFilesFromScript" backup.dynamicFilesFrom} >> ${filesFromTmpFile}
|
||||||
''}
|
''}
|
||||||
'';
|
'';
|
||||||
} // optionalAttrs (backup.dynamicFilesFrom != null || backup.backupCleanupCommand != null) {
|
} // optionalAttrs (doBackup || backup.backupCleanupCommand != null) {
|
||||||
postStop = ''
|
postStop = ''
|
||||||
${optionalString (backup.backupCleanupCommand != null) ''
|
${optionalString (backup.backupCleanupCommand != null) ''
|
||||||
${pkgs.writeScript "backupCleanupCommand" backup.backupCleanupCommand}
|
${pkgs.writeScript "backupCleanupCommand" backup.backupCleanupCommand}
|
||||||
''}
|
''}
|
||||||
${optionalString (backup.dynamicFilesFrom != null) ''
|
${optionalString doBackup ''
|
||||||
rm ${filesFromTmpFile}
|
rm ${filesFromTmpFile}
|
||||||
''}
|
''}
|
||||||
'';
|
'';
|
||||||
|
|
|
@ -4,6 +4,7 @@ import ./make-test-python.nix (
|
||||||
let
|
let
|
||||||
remoteRepository = "/root/restic-backup";
|
remoteRepository = "/root/restic-backup";
|
||||||
remoteFromFileRepository = "/root/restic-backup-from-file";
|
remoteFromFileRepository = "/root/restic-backup-from-file";
|
||||||
|
remoteNoInitRepository = "/root/restic-backup-no-init";
|
||||||
rcloneRepository = "rclone:local:/root/restic-rclone-backup";
|
rcloneRepository = "rclone:local:/root/restic-rclone-backup";
|
||||||
|
|
||||||
backupPrepareCommand = ''
|
backupPrepareCommand = ''
|
||||||
|
@ -64,6 +65,11 @@ import ./make-test-python.nix (
|
||||||
find /opt -mindepth 1 -maxdepth 1 ! -name a_dir # all files in /opt except for a_dir
|
find /opt -mindepth 1 -maxdepth 1 ! -name a_dir # all files in /opt except for a_dir
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
remote-noinit-backup = {
|
||||||
|
inherit passwordFile exclude pruneOpts paths;
|
||||||
|
initialize = false;
|
||||||
|
repository = remoteNoInitRepository;
|
||||||
|
};
|
||||||
rclonebackup = {
|
rclonebackup = {
|
||||||
inherit passwordFile paths exclude pruneOpts;
|
inherit passwordFile paths exclude pruneOpts;
|
||||||
initialize = true;
|
initialize = true;
|
||||||
|
@ -114,6 +120,7 @@ import ./make-test-python.nix (
|
||||||
"cp -rT ${testDir} /opt",
|
"cp -rT ${testDir} /opt",
|
||||||
"touch /opt/excluded_file_1 /opt/excluded_file_2",
|
"touch /opt/excluded_file_1 /opt/excluded_file_2",
|
||||||
"mkdir -p /root/restic-rclone-backup",
|
"mkdir -p /root/restic-rclone-backup",
|
||||||
|
"restic-remote-noinit-backup init",
|
||||||
|
|
||||||
# test that remotebackup runs custom commands and produces a snapshot
|
# 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'",
|
||||||
|
@ -130,6 +137,10 @@ import ./make-test-python.nix (
|
||||||
"systemctl start restic-backups-remote-from-file-backup.service",
|
"systemctl start restic-backups-remote-from-file-backup.service",
|
||||||
'restic-remote-from-file-backup snapshots --json | ${pkgs.jq}/bin/jq "length | . == 1"',
|
'restic-remote-from-file-backup snapshots --json | ${pkgs.jq}/bin/jq "length | . == 1"',
|
||||||
|
|
||||||
|
# test that remote-noinit-backup produces a snapshot
|
||||||
|
"systemctl start restic-backups-remote-noinit-backup.service",
|
||||||
|
'restic-remote-noinit-backup snapshots --json | ${pkgs.jq}/bin/jq "length | . == 1"',
|
||||||
|
|
||||||
# test that restoring that snapshot produces the same directory
|
# test that restoring that snapshot produces the same directory
|
||||||
"mkdir /tmp/restore-2",
|
"mkdir /tmp/restore-2",
|
||||||
"${pkgs.restic}/bin/restic -r ${remoteRepository} -p ${passwordFile} restore latest -t /tmp/restore-2",
|
"${pkgs.restic}/bin/restic -r ${remoteRepository} -p ${passwordFile} restore latest -t /tmp/restore-2",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue