Improve backup script

This commit is contained in:
Torjus Håkestad 2024-06-02 23:50:20 +02:00
parent 72a5468cb1
commit ff50a9b4a1

View File

@ -5,16 +5,26 @@ let
name = "restic-wrapper";
runtimeInputs = [
pkgs.restic
pkgs.systemd
];
text = ''
if [ -z "$BACKUP_HELPER_DIRS" ]; then
echo "BACKUP_HELPER_DIRS is not set";
echo "BACKUP_HELPER_DIRS is not set"
exit 1;
fi
exit_code=0;
for i in ''${BACKUP_HELPER_DIRS//,/ }; do
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
exit "$exit_code";
'';
};
in