#!/usr/bin/env bash # A script to perform incremental backups with rsync # Source: https://linuxconfig.org/how-to-create-incremental-backups-using-rsync-on-linux set -o errexit set -o nounset set -o pipefail readonly BACKUP_DIR="/mnt/backup" readonly DATETIME DATETIME="$(date '+%Y-%m-%d_%H:%M:%S')" readonly BACKUP_PATH="${BACKUP_DIR}/${DATETIME}" readonly LATEST_LINK="${BACKUP_DIR}/latest" readonly TEMP_DIR TEMP_DIR=$(mktemp -d || echo "Failed to make temp dir"; exit 1) chmod 700 "${TEMP_DIR}" trap 'rm -rf "${TEMP_DIR}"; exit 0' 0 1 2 3 15 mkdir -p "${BACKUP_DIR}" while read -r line; do rsync -aAX "$line" "${TEMP_DIR}"; done