use systemd timer
This commit is contained in:
parent
b814af9ac3
commit
374fb3a756
1 changed files with 29 additions and 25 deletions
54
backup.nix
54
backup.nix
|
@ -12,10 +12,26 @@ let
|
|||
|
||||
backupConfigFile = "/etc/misskey-backup/conf";
|
||||
s3Cfg = "/etc/misskey-backup/s3cfg";
|
||||
backupScript = pkgs.writeShellApplication {
|
||||
name = "misskey-backup";
|
||||
in {
|
||||
users.users."${user}" = {
|
||||
isSystemUser = true;
|
||||
inherit group;
|
||||
};
|
||||
users.groups."${group}" = { };
|
||||
services.postgresql.ensureUsers = [{ name = user; }];
|
||||
|
||||
runtimeInputs = with pkgs; [
|
||||
systemd.services.misskey-backup = {
|
||||
description = "Misskey backup";
|
||||
|
||||
restartIfChanged = false;
|
||||
unitConfig.X-StopOnRemoval = false;
|
||||
unitConfig.User = user;
|
||||
|
||||
serviceConfig.Type = "oneshot";
|
||||
|
||||
startAt = "weekly";
|
||||
|
||||
path = with pkgs; [
|
||||
gzip
|
||||
config.services.postgresql.package
|
||||
s3cmd
|
||||
|
@ -23,21 +39,18 @@ let
|
|||
age
|
||||
];
|
||||
|
||||
text = ''
|
||||
configFile="$1"
|
||||
s3cfg="$2"
|
||||
|
||||
script = ''
|
||||
ageRecipient="age17ckyc69njpryytc63ynn545jswyucg28k5xg3043g3j6q38dxqwq0wzhm2"
|
||||
bucket="$(grep 'bucket=' < "$configFile" | sed 's/bucket \?= \?')"
|
||||
prefix="$(grep 'prefix=' < "$configFile" | sed 's/prefix \?= \?')"
|
||||
bucket="$(grep 'bucket=' < "${backupConfigFile}" | sed 's/bucket \?= \?')"
|
||||
prefix="$(grep 'prefix=' < "${backupConfigFile}" | sed 's/prefix \?= \?')"
|
||||
|
||||
s3Dir="s3://$bucket/$prefix""misskey-$(date --iso-8601)"
|
||||
s3Dir="s3://$bucket/$prefix""misskey-$(date +'%d-%m-%YT%H.%M.%S')"
|
||||
echo "Uploading backups to '$s3Dir'"
|
||||
|
||||
function upload () {
|
||||
name="$1"
|
||||
|
||||
age -r "$ageRecipient" | s3cmd put --config "$s3cfg" - "$s3Dir/$name.age"
|
||||
age -r "$ageRecipient" | s3cmd put --config "${s3Cfg}" - "$s3Dir/$name.age"
|
||||
}
|
||||
|
||||
echo "Uploading config"
|
||||
|
@ -51,20 +64,11 @@ let
|
|||
|
||||
echo "Backup complete to '$s3Dir'"
|
||||
'';
|
||||
};
|
||||
in {
|
||||
users.users."${user}" = {
|
||||
isSystemUser = true;
|
||||
inherit group;
|
||||
};
|
||||
users.groups."${group}" = { };
|
||||
services.postgresql.ensureUsers = [{ name = user; }];
|
||||
|
||||
services.cron = {
|
||||
enable = true;
|
||||
systemCronJobs = [
|
||||
# run every monday at ass in the morning, EST"
|
||||
"0 8 0 0 1 ${user} ${backupScript} ${backupConfigFile} ${s3Cfg}"
|
||||
];
|
||||
after = [ "network-online.target" ];
|
||||
wants = [ "network-online.target" ];
|
||||
requires = [ "postgresql.service" ];
|
||||
};
|
||||
|
||||
systemd.timers.misskey-backup = { timerConfig.Persistent = true; };
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue