Improve backup script
This commit is contained in:
parent
ad9656072c
commit
0360a994c9
@ -6,6 +6,7 @@ let
|
|||||||
export RESTIC_PASSWORD="gunter.home.2rjus.net"
|
export RESTIC_PASSWORD="gunter.home.2rjus.net"
|
||||||
export RESTIC_REPOSITORY="rest:http://10.69.12.52:8000/gunter.home.2rjus.net"
|
export RESTIC_REPOSITORY="rest:http://10.69.12.52:8000/gunter.home.2rjus.net"
|
||||||
|
|
||||||
|
# Send start notification
|
||||||
${pkgs.libnotify}/bin/notify-send -e -t 3000 "Backup started" "Backup of /home/torjus started"
|
${pkgs.libnotify}/bin/notify-send -e -t 3000 "Backup started" "Backup of /home/torjus started"
|
||||||
retval=$?
|
retval=$?
|
||||||
if [ $retval -ne 0 ]; then
|
if [ $retval -ne 0 ]; then
|
||||||
@ -13,6 +14,7 @@ let
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Do the backup
|
||||||
SECONDS=0
|
SECONDS=0
|
||||||
${pkgs.restic}/bin/restic backup /home/torjus \
|
${pkgs.restic}/bin/restic backup /home/torjus \
|
||||||
--exclude '/home/torjus/.cache' \
|
--exclude '/home/torjus/.cache' \
|
||||||
@ -23,9 +25,26 @@ let
|
|||||||
notify-send -u critical "Backup failed" "Backup of /home/torjus failed"
|
notify-send -u critical "Backup failed" "Backup of /home/torjus failed"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
${pkgs.restic}/bin/restic forget -d 7 -w 4 -m 6 --prune
|
|
||||||
|
|
||||||
${pkgs.libnotify}/bin/notify-send -e -t 3000 "Backup completed" "Backup of /home/torjus completed in $SECONDS seconds."
|
# Remove old snapshots and prune
|
||||||
|
${pkgs.restic}/bin/restic forget -d 7 -w 4 -m 6 --keep-within 1d --prune
|
||||||
|
|
||||||
|
# Gather statistics
|
||||||
|
stats=$(${pkgs.restic}/bin/restic stats --json)
|
||||||
|
stats_raw=$(${pkgs.restic}/bin/restic stats --mode=raw-data --json)
|
||||||
|
|
||||||
|
raw_size=$(${pkgs.jq}/bin/jq -r '.total_size' <<< $stats_raw \
|
||||||
|
| ${pkgs.coreutils}/bin/numfmt --to=iec --suffix=B --format="%.2f")
|
||||||
|
total_size=$(${pkgs.jq}/bin/jq -r '.total_size' <<< $stats \
|
||||||
|
| ${pkgs.coreutils}/bin/numfmt --to=iec --suffix=B --format="%.2f")
|
||||||
|
total_files=$(${pkgs.jq}/bin/jq -r '.total_file_count' <<< $stats \
|
||||||
|
| ${pkgs.coreutils}/bin/numfmt --to=iec)
|
||||||
|
total_snapshots=$(${pkgs.jq}/bin/jq -r '.snapshots_count' <<< $stats)
|
||||||
|
message="$total_files files\n$total_snapshots snapshots\n$raw_size ($total_size)"
|
||||||
|
|
||||||
|
# Send completion notification
|
||||||
|
${pkgs.libnotify}/bin/notify-send -i checkmark -e -t 10000 \
|
||||||
|
"Backup of /home/torjus completed in ''${SECONDS}s" "$message"
|
||||||
retval=$?
|
retval=$?
|
||||||
if [ $retval -ne 0 ]; then
|
if [ $retval -ne 0 ]; then
|
||||||
echo "Failed to send notification"
|
echo "Failed to send notification"
|
||||||
@ -50,7 +69,7 @@ in
|
|||||||
After = [ "network.target" ];
|
After = [ "network.target" ];
|
||||||
};
|
};
|
||||||
Timer = {
|
Timer = {
|
||||||
OnCalendar = "*-*-* 0,6,12,18:00:00";
|
OnCalendar = "*-*-* *:00:00";
|
||||||
Persistent = true;
|
Persistent = true;
|
||||||
};
|
};
|
||||||
Install = {
|
Install = {
|
||||||
|
Loading…
Reference in New Issue
Block a user