mirror of
https://github.com/kmein/niveum
synced 2026-03-16 10:11:08 +01:00
feat(hedgedoc): add backup script
This commit is contained in:
@@ -1,4 +1,11 @@
|
||||
{ pkgs, ... }:
|
||||
let
|
||||
backupLocation = "/var/lib/codimd-backup";
|
||||
stateLocation = "/var/lib/codimd/state.sqlite";
|
||||
in
|
||||
{
|
||||
imports = [ <stockholm/krebs/3modules/permown.nix> ];
|
||||
|
||||
services.nginx.virtualHosts."pad.xn--kiern-0qa.de" = {
|
||||
enableACME = true;
|
||||
addSSL = true;
|
||||
@@ -17,9 +24,51 @@
|
||||
allowFreeURL = true;
|
||||
db = {
|
||||
dialect = "sqlite";
|
||||
storage = "/var/lib/codimd/state.sqlite";
|
||||
storage = stateLocation;
|
||||
};
|
||||
port = 3091;
|
||||
};
|
||||
};
|
||||
|
||||
krebs.permown.${backupLocation} = { owner = "codimd"; group = "codimd"; umask = "0002"; };
|
||||
|
||||
systemd.services.hedgedoc-backup = {
|
||||
description = "Hedgedoc backup service";
|
||||
script = ''
|
||||
${pkgs.sqlite}/bin/sqlite3 -csv ${stateLocation} "select id, alias, ownerId, content from Notes" \
|
||||
| ${pkgs.writers.writePython3 "hedgedoc-csv-to-fs.py" {} ''
|
||||
import csv
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
reader = csv.reader(
|
||||
(line.decode("utf-8") for line in sys.stdin.buffer.readlines()),
|
||||
dialect="unix"
|
||||
)
|
||||
for row in reader:
|
||||
try:
|
||||
id, alias, ownerId, content = row
|
||||
|
||||
user_directory = pathlib.Path(ownerId)
|
||||
user_directory.mkdir(exist_ok=True)
|
||||
|
||||
file_path = user_directory / ((alias if alias else id) + ".md")
|
||||
file_path.write_text(content)
|
||||
|
||||
sys.stderr.write(f"✔ {file_path}\n")
|
||||
except ValueError:
|
||||
sys.stderr.write(
|
||||
f"row {reader.line_num} does not have the correct number of fields"
|
||||
)
|
||||
continue
|
||||
''}
|
||||
'';
|
||||
startAt = "hourly";
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
User = "codimd";
|
||||
Group = "codimd";
|
||||
WorkingDirectory = backupLocation;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -65,7 +65,13 @@ in
|
||||
boot.loader.grub.enable = true;
|
||||
boot.loader.grub.version = 2;
|
||||
|
||||
nixpkgs.config.allowUnfree = true;
|
||||
nixpkgs.config = {
|
||||
allowUnfree = true;
|
||||
packageOverrides = pkgs: {
|
||||
writeDashBin = pkgs.writers.writeDashBin;
|
||||
writeDash = pkgs.writers.writeDash;
|
||||
};
|
||||
};
|
||||
|
||||
networking.useDHCP = false;
|
||||
networking.interfaces.ens3.useDHCP = true;
|
||||
|
||||
Reference in New Issue
Block a user