tangled
alpha
login
or
join now
dunkirk.sh
/
dots
3
fork
atom
Kieran's opinionated (and probably slightly dumb) nix config
3
fork
atom
overview
issues
pulls
pipelines
feat: more logs
dunkirk.sh
2 months ago
19ca97e3
d127dfa4
verified
This commit was signed with the committer's
known signature
.
dunkirk.sh
SSH Key Fingerprint:
SHA256:DqcG0RXYExE26KiWo3VxJnsxswN1QNfTBvB+bdSpk80=
+38
-29
1 changed file
expand all
collapse all
unified
split
modules
nixos
services
restic
cli.nix
+38
-29
modules/nixos/services/restic/cli.nix
···
132
132
exit 1
133
133
fi
134
134
135
135
+
run_backup() {
136
136
+
local svc_name=$1
137
137
+
138
138
+
# Check if already running
139
139
+
if systemctl is-active --quiet "restic-backups-$svc_name.service"; then
140
140
+
style --foreground 214 "! $svc_name backup already in progress"
141
141
+
style --foreground 117 " Use: journalctl -u restic-backups-$svc_name.service -f"
142
142
+
return 1
143
143
+
fi
144
144
+
145
145
+
style --foreground 117 "Backing up $svc_name..."
146
146
+
147
147
+
# Start following journal before starting service
148
148
+
journalctl -u "restic-backups-$svc_name.service" -f -n 0 --output=cat &
149
149
+
journal_pid=$!
150
150
+
151
151
+
# Small delay to ensure journalctl is attached
152
152
+
sleep 0.2
153
153
+
154
154
+
systemctl start "restic-backups-$svc_name.service"
155
155
+
156
156
+
while systemctl is-active --quiet "restic-backups-$svc_name.service"; do
157
157
+
sleep 1
158
158
+
done
159
159
+
160
160
+
kill $journal_pid 2>/dev/null || true
161
161
+
162
162
+
if systemctl is-failed --quiet "restic-backups-$svc_name.service"; then
163
163
+
style --foreground 196 "✗ $svc_name failed"
164
164
+
return 1
165
165
+
else
166
166
+
style --foreground 35 "✓ $svc_name complete"
167
167
+
return 0
168
168
+
fi
169
169
+
}
170
170
+
135
171
if [ "$svc" = "all" ]; then
136
172
for s in $SERVICES; do
137
137
-
style --foreground 117 "Backing up $s..."
138
138
-
systemctl start "restic-backups-$s.service"
139
139
-
journalctl -u "restic-backups-$s.service" -f -n 0 --output=cat &
140
140
-
journal_pid=$!
141
141
-
while systemctl is-active --quiet "restic-backups-$s.service"; do
142
142
-
sleep 1
143
143
-
done
144
144
-
kill $journal_pid 2>/dev/null || true
145
145
-
if systemctl is-failed --quiet "restic-backups-$s.service"; then
146
146
-
style --foreground 214 "! Failed to backup $s"
147
147
-
else
148
148
-
style --foreground 35 "✓ $s complete"
149
149
-
fi
173
173
+
run_backup "$s" || true
150
174
echo
151
175
done
152
176
else
153
153
-
style --foreground 117 "Backing up $svc..."
154
154
-
systemctl start "restic-backups-$svc.service"
155
155
-
journalctl -u "restic-backups-$svc.service" -f -n 0 --output=cat &
156
156
-
journal_pid=$!
157
157
-
while systemctl is-active --quiet "restic-backups-$svc.service"; do
158
158
-
sleep 1
159
159
-
done
160
160
-
kill $journal_pid 2>/dev/null || true
177
177
+
run_backup "$svc"
161
178
fi
162
179
163
163
-
if [ "$svc" != "all" ]; then
164
164
-
if systemctl is-failed --quiet "restic-backups-$svc.service"; then
165
165
-
style --foreground 196 "✗ Backup failed"
166
166
-
exit 1
167
167
-
else
168
168
-
style --foreground 35 "✓ Backup complete"
169
169
-
fi
170
170
-
fi
171
180
}
172
181
173
182
cmd_restore() {