Rsync-based multi-platform backup scripts with rotation support.
Two backup strategies are provided:
- Generic — SSH-based remote backup with automatic hourly/daily/weekly rotation
- ZFS — Local or mounted filesystem sync (designed for use with ZFS snapshots)
Pulls data from a remote host over SSH using rsync with hard-link-based deduplication. Backups are automatically rotated into hourly, daily, and weekly tiers.
Generic/SSHBackup.sh <source host> <source path> <target path>- source host — hostname or IP of the remote machine (must have SSH key auth configured)
- source path — path on the remote machine to back up
- target path — local directory to store backups (must end with
/)
- Acquires a PID-based lockfile (stale locks from crashed processes are detected and removed)
- Verifies SSH connectivity to the remote host
- Runs
rsyncwith--link-destto deduplicate unchanged files against the previous backup - Moves the completed backup into
hourly/and atomically updates thecurrentsymlink - Promotes the oldest hourly backup to
daily/if no recent daily exists - Promotes the oldest daily backup to
weekly/if no recent weekly exists - Cleans up old backups (hourly: >1 day, daily: >7 days, incomplete: >2 hours)
All output is logged to <target>/backup.log.
| Tier | Kept For |
|---|---|
| Hourly | 1 day |
| Daily | 7 days |
| Weekly | No automatic deletion |
<target>/
current -> symlink to latest backup
lockfile -> PID-based lock to prevent concurrent runs
backup.log -> append-only log of all backup runs
hourly/
2024-01-15T10_00_00/
2024-01-15T11_00_00/
daily/
2024-01-14T10_00_00/
weekly/
2024-01-07T10_00_00/
Edit Generic/Wrapper.sh to set your source host, source path, and target path, then schedule it with cron:
# Run every hour
0 * * * * /path/to/Generic/Wrapper.shSyncs a local or mounted filesystem to a target directory using rsync. Designed for use with ZFS, where snapshots provide the versioning layer.
ZFS/SyncBackup.sh <source path> <target path>- source path — local directory to back up (must contain a
lastbackup.txtfile) - target path — local directory to sync to
- Checks for
lastbackup.txtin the source to verify the filesystem is mounted and valid - Timestamps the source with the current date
- Runs
rsyncwith--delete-afterand--delete-excludedfor a clean mirror
All output is logged to <target>/backup.log.
Edit ZFS/Wrapper.sh to set your source and target paths, then schedule it with cron:
# Run every hour
0 * * * * /path/to/ZFS/Wrapper.shExclusions are managed via excludes.txt files alongside each script — one pattern per line. Edit these to add or remove exclusions without modifying the scripts.
Default exclusions:
DoNotBackup— user-designated exclusion markerBBC iPlayer,Final Cut Events,Final Cut Projects,iMovie Events.localized— large media caches$RECYCLE.BIN,System Volume Information— Windows system directories (ZFS only)
Each script has configurable variables at the top:
| Variable | Default | Description |
|---|---|---|
rsync_timeout |
3600 |
Seconds before rsync aborts a stalled transfer |
rsyncsshwith key-based authentication (Generic only)- POSIX-compatible shell (
/bin/sh) findwith-printfsupport (GNU findutils)