Files

26 lines
623 B
Bash
Raw Permalink Normal View History

2022-10-28 17:16:24 +00:00
#!/usr/bin/env bash
2023-05-28 18:28:18 +00:00
readonly RSYNC_USER="${RSYNC_USER}"
readonly RSYNC_SERVER="${RSYNC_SERVER}"
2022-10-28 17:16:24 +00:00
main() {
2023-02-01 20:11:39 +00:00
local filepath="$1"
local name
name="$(basename "${filepath}")"
2026-10-22 12:50:01 +00:00
# Stagger transfers to avoid congestion at the hour mark.
sleep $((RANDOM % 180))
# Limit bandwidth so the backup does not saturate the connection.
rsync --archive --verbose --bwlimit=4096 \
2023-05-28 18:28:18 +00:00
"${HOME}/timelapse/${name}" \
"${RSYNC_USER}@${RSYNC_SERVER}:/timelapse/${name}"
2022-10-28 17:16:24 +00:00
# Delete outdated files.
# This assumes the timelapse is created on an hourly basis.
2023-02-01 19:51:01 +00:00
rm -f "$1"
2022-10-28 17:16:24 +00:00
find "${HOME}/timelapse/" -mmin +60 -delete
}
main "$@"