Improve backup script
This commit is contained in:
parent
72a5468cb1
commit
ff50a9b4a1
14
backup.nix
14
backup.nix
@ -5,16 +5,26 @@ let
|
|||||||
name = "restic-wrapper";
|
name = "restic-wrapper";
|
||||||
runtimeInputs = [
|
runtimeInputs = [
|
||||||
pkgs.restic
|
pkgs.restic
|
||||||
pkgs.systemd
|
|
||||||
];
|
];
|
||||||
text = ''
|
text = ''
|
||||||
if [ -z "$BACKUP_HELPER_DIRS" ]; then
|
if [ -z "$BACKUP_HELPER_DIRS" ]; then
|
||||||
echo "BACKUP_HELPER_DIRS is not set";
|
echo "BACKUP_HELPER_DIRS is not set"
|
||||||
exit 1;
|
exit 1;
|
||||||
fi
|
fi
|
||||||
|
exit_code=0;
|
||||||
for i in ''${BACKUP_HELPER_DIRS//,/ }; do
|
for i in ''${BACKUP_HELPER_DIRS//,/ }; do
|
||||||
echo "Starting backup of $i";
|
echo "Starting backup of $i";
|
||||||
|
output=$(restic backup "$i" && rc=$? || rc=$?);
|
||||||
|
if [ $rc -ne 0 ]; then
|
||||||
|
echo "Backup of $i failed with exit code $rc:"
|
||||||
|
echo "$output"
|
||||||
|
exit_code="$rc"
|
||||||
|
else
|
||||||
|
echo "Backup of $i successful:"
|
||||||
|
echo "$output"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
exit "$exit_code";
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
|
Loading…
Reference in New Issue
Block a user