tangled
alpha
login
or
join now
pyrox.dev
/
nixpkgs
0
fork
atom
lol
0
fork
atom
overview
issues
pulls
pipelines
Address @yegortimoshenko review
Michishige Kaito
8 years ago
c515f703
bde525aa
+21
-27
1 changed file
expand all
collapse all
unified
split
nixos
modules
services
backup
tarsnap.nix
+21
-27
nixos/modules/services/backup/tarsnap.nix
···
304
requires = [ "network-online.target" ];
305
after = [ "network-online.target" ];
306
307
-
path = [ pkgs.iputils pkgs.tarsnap pkgs.utillinux ];
308
309
# In order for the persistent tarsnap timer to work reliably, we have to
310
# make sure that the tarsnap server is reachable after systemd starts up
···
314
while ! ping -q -c 1 v1-0-0-server.tarsnap.com &> /dev/null; do sleep 3; done
315
'';
316
317
-
script =
318
-
let run = ''tarsnap --configfile "/etc/tarsnap/${name}.conf" \
319
-
-c -f "${name}-$(date +"%Y%m%d%H%M%S")" \
320
${optionalString cfg.verbose "-v"} \
321
${optionalString cfg.explicitSymlinks "-H"} \
322
${optionalString cfg.followSymlinks "-L"} \
···
329
if [ ! -e ${cfg.cachedir}/firstrun ]; then
330
( flock 10
331
flock -u 9
332
-
tarsnap --configfile "/etc/tarsnap/${name}.conf" --fsck
333
flock 9
334
) 10>${cfg.cachedir}/firstrun
335
fi
···
351
description = "Tarsnap restore '${name}'";
352
requires = [ "network-online.target" ];
353
354
-
path = [ pkgs.iputils pkgs.tarsnap pkgs.utillinux ];
355
-
356
-
##
357
-
preStart = ''
358
-
while ! ping -q -c 1 v1-0-0-server.tarsnap.com &> /dev/null; do sleep 3; done
359
-
'';
360
361
-
script =
362
-
let
363
tarsnap = ''tarsnap --configfile "/etc/tarsnap/${name}.conf"'';
364
lastArchive = ''$(${tarsnap} --list-archives | sort | tail -1)'';
365
run = ''${tarsnap} -x -f "${lastArchive}" ${optionalString cfg.verbose "-v"}'';
366
367
-
in if (cfg.cachedir != null) then ''
368
-
mkdir -p ${cfg.cachedir}
369
-
chmod 0700 ${cfg.cachedir}
370
371
-
( flock 9
372
-
if [ ! -e ${cfg.cachedir}/firstrun ]; then
373
-
( flock 10
374
-
flock -u 9
375
-
${tarsnap} --fsck
376
-
flock 9
377
-
) 10>${cfg.cachedir}/firstrun
378
-
fi
379
-
) 9>${cfg.cachedir}/lockf
380
381
-
exec flock ${cfg.cachedir}/firstrun ${run}
382
-
'' else "exec ${run}";
383
384
serviceConfig = {
385
Type = "oneshot";
···
304
requires = [ "network-online.target" ];
305
after = [ "network-online.target" ];
306
307
+
path = with pkgs; [ iputils tarsnap utillinux ];
308
309
# In order for the persistent tarsnap timer to work reliably, we have to
310
# make sure that the tarsnap server is reachable after systemd starts up
···
314
while ! ping -q -c 1 v1-0-0-server.tarsnap.com &> /dev/null; do sleep 3; done
315
'';
316
317
+
script = let
318
+
tarsnap = ''tarsnap --configfile "/etc/tarsnap/${name}.conf"'';
319
+
run = ''${tarsnap} -c -f "${name}-$(date +"%Y%m%d%H%M%S")" \
320
${optionalString cfg.verbose "-v"} \
321
${optionalString cfg.explicitSymlinks "-H"} \
322
${optionalString cfg.followSymlinks "-L"} \
···
329
if [ ! -e ${cfg.cachedir}/firstrun ]; then
330
( flock 10
331
flock -u 9
332
+
${tarsnap} --fsck
333
flock 9
334
) 10>${cfg.cachedir}/firstrun
335
fi
···
351
description = "Tarsnap restore '${name}'";
352
requires = [ "network-online.target" ];
353
354
+
path = with pkgs; [ iputils tarsnap utillinux ];
0
0
0
0
0
355
356
+
script = let
0
357
tarsnap = ''tarsnap --configfile "/etc/tarsnap/${name}.conf"'';
358
lastArchive = ''$(${tarsnap} --list-archives | sort | tail -1)'';
359
run = ''${tarsnap} -x -f "${lastArchive}" ${optionalString cfg.verbose "-v"}'';
360
361
+
in if (cfg.cachedir != null) then ''
362
+
mkdir -p ${cfg.cachedir}
363
+
chmod 0700 ${cfg.cachedir}
364
365
+
( flock 9
366
+
if [ ! -e ${cfg.cachedir}/firstrun ]; then
367
+
( flock 10
368
+
flock -u 9
369
+
${tarsnap} --fsck
370
+
flock 9
371
+
) 10>${cfg.cachedir}/firstrun
372
+
fi
373
+
) 9>${cfg.cachedir}/lockf
374
375
+
exec flock ${cfg.cachedir}/firstrun ${run}
376
+
'' else "exec ${run}";
377
378
serviceConfig = {
379
Type = "oneshot";