backup-incremental.sh 598 B

12345678910111213141516171819202122232425
  1. #!/usr/bin/env bash
  2. set -euo pipefail # bash strict mode
  3. # A script to perform incremental backups using rsync
  4. set -o errexit
  5. set -o nounset
  6. set -o pipefail
  7. readonly SOURCE_DIR="${HOME}"
  8. readonly BACKUP_DIR="${BACKUPS:-/mnt/crucial_nvme/Backups}"
  9. readonly DATETIME="$(date '+%Y-%m-%d-%H%M%S')"
  10. readonly BACKUP_PATH="${BACKUP_DIR}/${DATETIME}"
  11. readonly LATEST_LINK="${BACKUP_DIR}/latest"
  12. mkdir -p "${BACKUP_DIR}"
  13. rsync -av --delete \
  14. "${SOURCE_DIR}/" \
  15. --link-dest "${LATEST_LINK}" \
  16. --exclude=".cache" \
  17. "${BACKUP_PATH}"
  18. rm -rf "${LATEST_LINK}"
  19. ln -s "${BACKUP_PATH}" "${LATEST_LINK}"