mirror of
https://github.com/kmein/niveum
synced 2026-03-20 20:01:08 +01:00
fix(makanek): use sqlite json to simplify dump script
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
let
|
let
|
||||||
backupLocation = "/var/lib/codimd-backup";
|
backupLocation = "/var/lib/codimd-backup";
|
||||||
stateLocation = "/var/lib/codimd/state.sqlite";
|
stateLocation = "/var/lib/codimd/state.sqlite";
|
||||||
|
nixpkgs-unstable = import <nixpkgs-unstable> {};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
imports = [ <stockholm/krebs/3modules/permown.nix> ];
|
imports = [ <stockholm/krebs/3modules/permown.nix> ];
|
||||||
@@ -35,32 +36,22 @@ in
|
|||||||
systemd.services.hedgedoc-backup = {
|
systemd.services.hedgedoc-backup = {
|
||||||
description = "Hedgedoc backup service";
|
description = "Hedgedoc backup service";
|
||||||
script = ''
|
script = ''
|
||||||
${pkgs.sqlite}/bin/sqlite3 -csv ${stateLocation} "select shortid, alias, ownerId, content from Notes" \
|
${nixpkgs-unstable.sqlite}/bin/sqlite3 -json ${stateLocation} "select shortid, alias, ownerId, content from Notes" \
|
||||||
| ${pkgs.writers.writePython3 "hedgedoc-csv-to-fs.py" {} ''
|
| ${pkgs.writers.writePython3 "hedgedoc-json-to-fs.py" {} ''
|
||||||
import csv
|
import json
|
||||||
import pathlib
|
import pathlib
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
reader = csv.reader(
|
for note in json.load(sys.stdin):
|
||||||
(line.decode("utf-8") for line in sys.stdin.buffer.readlines()),
|
user_directory = pathlib.Path()
|
||||||
dialect="unix"
|
if note["ownerId"]:
|
||||||
)
|
user_directory = pathlib.Path(note["ownerId"])
|
||||||
for row in reader:
|
|
||||||
try:
|
|
||||||
id, alias, ownerId, content = row
|
|
||||||
|
|
||||||
user_directory = pathlib.Path(ownerId)
|
|
||||||
user_directory.mkdir(exist_ok=True)
|
user_directory.mkdir(exist_ok=True)
|
||||||
|
file_path = user_directory / (
|
||||||
file_path = user_directory / ((alias if alias else id) + ".md")
|
(note["alias"] if note["alias"] else note["shortid"]) + ".md"
|
||||||
file_path.write_text(content)
|
)
|
||||||
|
file_path.write_text(note["content"])
|
||||||
sys.stderr.write(f"✔ {file_path}\n")
|
print(f"✔ {file_path}", file=sys.stderr)
|
||||||
except ValueError:
|
|
||||||
sys.stderr.write(
|
|
||||||
f"row {reader.line_num} does not have the correct number of fields"
|
|
||||||
)
|
|
||||||
continue
|
|
||||||
''}
|
''}
|
||||||
'';
|
'';
|
||||||
startAt = "hourly";
|
startAt = "hourly";
|
||||||
|
|||||||
Reference in New Issue
Block a user