#!/bin/bash SRC="/data_to_backup/" # Replace with the source directory you want to back up DEST="/backup/" # Replace with your ZFS pool mount point on the USB drive # Use rsync with hard links to save space and make incremental backups rsync -aAXHv --delete --progress \ --link-dest="$DEST/latest" \ "$SRC" "$DEST/backup-$(date +%F)" # Update the "latest" symlink to point to the newest backup rm -rf "$DEST/latest" ln -s "$DEST/backup-$(date +%F)" "$DEST/latest" # Delete backups older than 7 days find "$DEST" -maxdepth 1 -type d -name "backup-*" -mtime +7 -exec rm -rf {} \;