-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add rbbackup service, configure LDAP backups
- Loading branch information
Showing
5 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,6 +71,35 @@ with lib; | |
example = "zbackup/nfs"; | ||
type = types.str; | ||
}; | ||
|
||
rbbackup = with types; { | ||
destination = mkOption { | ||
description = "Where to rsync the backup data to."; | ||
default = "[email protected]:/zbackup/generic/${config.networking.hostName}/"; | ||
type = str; | ||
}; | ||
|
||
sources = mkOption { | ||
description = "Paths on the current system to be backed up."; | ||
default = []; | ||
type = listOf str; | ||
}; | ||
|
||
commands = mkOption { | ||
description = ( | ||
"Commands to run before commencing copy of backups. Files created" | ||
+ " in the current working directory will be deleted after backups are completed." | ||
); | ||
default = ""; | ||
type = str; | ||
}; | ||
|
||
extraPackages = mkOption { | ||
description = "Packages to make available in the backup commands scripts."; | ||
default = []; | ||
type = listOf path; | ||
}; | ||
}; | ||
}; | ||
|
||
config.assertions = [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ pkgs, config, lib, ... }: | ||
with config.redbrick.rbbackup; | ||
let | ||
# Quote and join paths for arguments to rsync | ||
sourcePaths = lib.concatStringsSep " " (builtins.map | ||
(srcPath: "'${srcPath}'") | ||
sources); | ||
|
||
in lib.mkIf (sources != []) { | ||
systemd.services.redbrick-backup = { | ||
aliases = [ "rbbackup.service" "redbrick-backups.service" ]; | ||
description = "Redbrick backup script. Copies data to ${destination}"; | ||
wants = [ "multi-user.target" ]; | ||
requires = [ "local-fs.target" "network-online.target" ]; | ||
path = with pkgs; [ rsync openssh ] ++ extraPackages; | ||
script = '' | ||
set -euxo pipefail | ||
echo "Backup starting" | ||
rsync -a --progress --delete ${sourcePaths} ${destination} | ||
echo "Backup successful" | ||
''; | ||
preStart = commands; | ||
postStart = '' | ||
rm -rf $CACHE_DIRECTORY | ||
''; | ||
serviceConfig = { | ||
Type = "oneshot"; | ||
CacheDirectory = "redbrick-backups"; | ||
WorkingDirectory = "/var/cache/redbrick-backups"; | ||
}; | ||
}; | ||
|
||
systemd.timers.redbrick-backup = { | ||
description = "Start Redbrick backup script"; | ||
wantedBy = [ "timers.target" ]; | ||
timerConfig = { | ||
OnCalendar = "hourly"; | ||
RandomizedDelaySec = 60 * 30; | ||
}; | ||
}; | ||
} |