-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.nix
93 lines (77 loc) · 2.53 KB
/
scripts.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
{ config, lib, pkgs, ... }:
{
systemd.user.services.update-sky =
let config = pkgs.writeText "mapcrafter-config" ''
output_dir = /tmp/mapcrafter-output
[world:world]
input_dir = /tmp/skyexport/world
[map:world]
name = SkyMasons
world = world
rotations = top-left top-right bottom-right bottom-left
texture_size = 16
[map:world_top_down]
name = SkyMasons top down
world = world
render_view = topdown
texture_size = 16
'';
script = pkgs.writeScript "skycache-update.sh" ''
#!${pkgs.stdenv.shell}
set -e
function cleanup {
echo "Removing /tmp dirs"
rmdir --ignore-fail-on-non-empty $skycache
rm -r /tmp/skyexport /tmp/mapcrafter-output
}
trap cleanup EXIT
rsyncargs="-rpt" # recursive, perms, time
echo 'yay'
dirname="skycache-$(date +%s)"
skycache="/home/babbaj/skycache/$dirname"
mkdir $skycache
rsync $rsyncargs n:/opt/slave/skymason/ $skycache
rsync $rsyncargs $skycache ovh:/root/skycache/ #backup
mkdir /tmp/skyexport
echo "Running exporter with $skycache"
java -jar /home/babbaj/SkyCacheExporter/build/libs/SkyCacheExporter-1.0-SNAPSHOT-standalone.jar $skycache /tmp/skyexport # TODO: package the exporter
mkdir /tmp/mapcrafter-output
echo 'Running mapcrafter'
mapcrafter -c ${config} -j 24
rsync $rsyncargs -v --progress --delete /tmp/mapcrafter-output/ ovh:/root/skyrender/
'';
in {
enable = false;
description = "Download chunk cache and update mapcrafter render";
startAt = "hourly";
path = with pkgs; [ rsync openssh mapcrafter jdk11 ];
serviceConfig = {
ExecStart = "${script}";
};
};
systemd.user.services.backup-headless = {
description = "Backup headless database";
path = with pkgs; [ rsync openssh ];
startAt = "daily";
script = ''
mkdir /home/babbaj/headless-backup || true
rsync -v --progress b:/headless-1.20.1/headless.db /home/babbaj/headless-backup/headless-$(date +"%m-%d-%Y").db
'';
};
systemd.user.services.skycache-rsync = {
enable = false;
description = "Hourly skycache backup";
path = with pkgs; [ rsync openssh gb-backup ];
startAt = "hourly";
script = ''
set -e
set -x
dirname="skycache-$(date +%s)"
tmpdir=/tmp/$dirname
rsync -rpt n:/opt/slave/skymason/ $tmpdir
mkdir /home/babbaj/skycache || true
mv $tmpdir /home/babbaj/skycache/$dirname
gb --config-file='/home/babbaj/skycache/.gb.conf' backup /home/babbaj/skycache/$dirname
'';
};
}