Skip to content

Instantly share code, notes, and snippets.

@Yan-Daojiang
Created March 17, 2023 07:26
Show Gist options
  • Save Yan-Daojiang/d1aa67669fddeb9cf880b7acb0300b2b to your computer and use it in GitHub Desktop.
Save Yan-Daojiang/d1aa67669fddeb9cf880b7acb0300b2b to your computer and use it in GitHub Desktop.
rsync备份用户主目录
#!/bin/bash
# A script to perform incremental backups using rsync
set -o errexit
set -o nounset
set -o pipefail
readonly SOURCE_DIR="${HOME}"
readonly BACKUP_DIR="/Volumes/Passport/Backup/Backup"
readonly DATETIME="$(date '+%Y-%m-%d_%H:%M:%S')"
readonly BACKUP_PATH="${BACKUP_DIR}/${DATETIME}"
readonly LATEST_LINK="${BACKUP_DIR}/latest"
mkdir -p "${BACKUP_DIR}"
rsync -av --delete --append \
--link-dest "${LATEST_LINK}" \
-e "ssh -p 20012" \
root@10.254.1.150:"${SOURCE_DIR}/" \
--exclude-from=exclude-file.txt \
"${BACKUP_PATH}"
rm -rf "${LATEST_LINK}"
ln -s "${BACKUP_PATH}" "${LATEST_LINK}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment