Created
March 17, 2023 07:26
-
-
Save Yan-Daojiang/d1aa67669fddeb9cf880b7acb0300b2b to your computer and use it in GitHub Desktop.
rsync备份用户主目录
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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