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";
|
backupConfigFile = "/etc/misskey-backup/conf";
|
||||||
s3Cfg = "/etc/misskey-backup/s3cfg";
|
s3Cfg = "/etc/misskey-backup/s3cfg";
|
||||||
backupScript = pkgs.writeShellApplication {
|
in {
|
||||||
name = "misskey-backup";
|
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
|
gzip
|
||||||
config.services.postgresql.package
|
config.services.postgresql.package
|
||||||
s3cmd
|
s3cmd
|
||||||
|
@ -23,21 +39,18 @@ let
|
||||||
age
|
age
|
||||||
];
|
];
|
||||||
|
|
||||||
text = ''
|
script = ''
|
||||||
configFile="$1"
|
|
||||||
s3cfg="$2"
|
|
||||||
|
|
||||||
ageRecipient="age17ckyc69njpryytc63ynn545jswyucg28k5xg3043g3j6q38dxqwq0wzhm2"
|
ageRecipient="age17ckyc69njpryytc63ynn545jswyucg28k5xg3043g3j6q38dxqwq0wzhm2"
|
||||||
bucket="$(grep 'bucket=' < "$configFile" | sed 's/bucket \?= \?')"
|
bucket="$(grep 'bucket=' < "${backupConfigFile}" | sed 's/bucket \?= \?')"
|
||||||
prefix="$(grep 'prefix=' < "$configFile" | sed 's/prefix \?= \?')"
|
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'"
|
echo "Uploading backups to '$s3Dir'"
|
||||||
|
|
||||||
function upload () {
|
function upload () {
|
||||||
name="$1"
|
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"
|
echo "Uploading config"
|
||||||
|
@ -51,20 +64,11 @@ let
|
||||||
|
|
||||||
echo "Backup complete to '$s3Dir'"
|
echo "Backup complete to '$s3Dir'"
|
||||||
'';
|
'';
|
||||||
};
|
|
||||||
in {
|
|
||||||
users.users."${user}" = {
|
|
||||||
isSystemUser = true;
|
|
||||||
inherit group;
|
|
||||||
};
|
|
||||||
users.groups."${group}" = { };
|
|
||||||
services.postgresql.ensureUsers = [{ name = user; }];
|
|
||||||
|
|
||||||
services.cron = {
|
after = [ "network-online.target" ];
|
||||||
enable = true;
|
wants = [ "network-online.target" ];
|
||||||
systemCronJobs = [
|
requires = [ "postgresql.service" ];
|
||||||
# run every monday at ass in the morning, EST"
|
|
||||||
"0 8 0 0 1 ${user} ${backupScript} ${backupConfigFile} ${s3Cfg}"
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
systemd.timers.misskey-backup = { timerConfig.Persistent = true; };
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue