Skip to content

Instantly share code, notes, and snippets.

@ibizaman
Created May 5, 2025 05:56
Show Gist options
  • Save ibizaman/302b6e562fb3a03c2dbaae9d8a8a434e to your computer and use it in GitHub Desktop.
Save ibizaman/302b6e562fb3a03c2dbaae9d8a8a434e to your computer and use it in GitHub Desktop.
backup nix function
(backupCfg {
shbOpt.backup.request = {
user = "root";
sourceDirectories = [
"/var/lib/private/lldap"
];
}; } "lldap")
(backupCfg {} "vaultwarden")
(backupCfg { shbOpt = config.shb.home-assistant; } "homeassistant")
(backupCfg {} "jellyfin")
(backupCfg { enable = true; } "nextcloud")
(lib.optionalAttrs true (backupCfg {
shbOpt.backup.request = {
user = "nextcloud";
sourceDirectories = [
"/srv/nextcloud/data"
];
};
} "nextcloud-data"))
backupCfg = { enable ? true, shbOpt ? null }: name: let
bck = (if shbOpt != null then shbOpt else config.shb.${name}).backup.request;
in {
shb.restic.instances."${name}-local" = {
request = bck;
settings = {
enable = if enable then true else shbOpt.enable;
passphrase.result = config.shb.sops.secret."restic/passphrases/${name}".result;
repository = {
path = "/srv/backup/restic/${name}";
timerConfig = {
OnBootSec = "15min";
OnUnitActiveSec = "1h";
RandomizedDelaySec = "7min";
FixedRandomDelay = true;
};
};
retention = {
keep_within = "1d";
keep_hourly = 24;
keep_daily = 7;
keep_weekly = 4;
keep_monthly = 6;
};
limitUploadKiBs = 8000;
limitDownloadKiBs = 8000;
};
};
shb.restic.instances."${name}-s3" = {
request = bck;
settings = {
enable = if enable then true else shbOpt.enable;
passphrase.result = config.shb.sops.secret."restic/passphrases/${name}".result;
repository = {
path = "s3:s3.us-west-000.backblazeb2.com/my-backup/${name}";
timerConfig = {
OnCalendar = "*-*-* 03:00:00";
RandomizedDelaySec = "1h";
FixedRandomDelay = true;
};
secrets = {
AWS_ACCESS_KEY_ID.source = config.sops.secrets."backup/b2/access_key_id/${name}".path;
AWS_SECRET_ACCESS_KEY.source = config.sops.secrets."backup/b2/secret_access_key/${name}".path;
};
};
retention = {
keep_within = "1d";
keep_hourly = 24;
keep_daily = 7;
keep_weekly = 4;
keep_monthly = 6;
};
limitUploadKiBs = 3000;
limitDownloadKiBs = 3000;
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment