From 71288332e85f993628439cecfbaa6ee207d01f46 Mon Sep 17 00:00:00 2001 From: Franck Cuny Date: Fri, 11 Mar 2022 19:31:26 -0800 Subject: rclone: synchronize restic repo to GCS Add a couple of secrets to store the configuration and the service account, and add a timer to synchronize the restic repository to a GCS bucket once a day. --- hosts/common/server/rclone.nix | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 hosts/common/server/rclone.nix (limited to 'hosts/common/server') diff --git a/hosts/common/server/rclone.nix b/hosts/common/server/rclone.nix new file mode 100644 index 0000000..5e1a4d6 --- /dev/null +++ b/hosts/common/server/rclone.nix @@ -0,0 +1,29 @@ +{ config, pkgs, lib, ... }: + +{ + environment.systemPackages = with pkgs; [ rclone ]; + + age.secrets.rclone-gcs-sa.file = + ../../../secrets/rclone/gcs_service_account.json.age; + + age.secrets.rclone-config.file = ../../../secrets/rclone/config.ini.age; + + systemd = { + timers.rclone-sync = { + wantedBy = [ "timers.target" ]; + partOf = [ "rclone-sync.service" ]; + timerConfig = { OnCalendar = "02:00"; }; + }; + services.rclone-sync = let rcloneOptions = "--fast-list --verbose"; + in { + serviceConfig.Type = "oneshot"; + serviceConfig.Environment = { + RCLONE_GCS_SERVICE_ACCOUNT_CREDENTIALS = + config.age.secrets.rclone-gcs-sa.path; + }; + script = '' + ${pkgs.rclone}/bin/rclone --config=${age.secrets.rclone-config.path} sync ${rcloneOptions} /data/slow/backups gbackup:fcuny-backups + ''; + }; + }; +} -- cgit 1.4.1