From 78ab2930b365fecf4b7b685ce81632917259c094 Mon Sep 17 00:00:00 2001 From: taoky Date: Sat, 28 Dec 2024 16:49:00 +0800 Subject: [PATCH] rsync: Make --delete-excluded an option --- README.md | 35 ++++++++++++++++++----------------- rsync/sync.sh | 4 +++- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 77a130a..501725a 100644 --- a/README.md +++ b/README.md @@ -387,23 +387,24 @@ ref: [![rsync](https://img.shields.io/docker/image-size/ustcmirror/rsync/latest)](https://hub.docker.com/r/ustcmirror/rsync "rsync") [![rsync](https://img.shields.io/docker/pulls/ustcmirror/rsync)](https://hub.docker.com/r/ustcmirror/rsync "rsync") -| Parameter | Description | -| --------------------- | ---------------------------------------------------------------- | -| `RSYNC_HOST` | The hostname of the remote server. | -| `RSYNC_USER` | (Optional) No defaults. | -| `RSYNC_PASSWORD` | (Optional) No defaults. | -| `RSYNC_PATH` | The destination path on the remote server. | -| `RSYNC_BW` | Bandwidth limit. Defaults to `0`. | -| `RSYNC_EXTRA` | Extra options. Defaults to empty. | -| `RSYNC_EXCLUDE` | Files to be excluded. Defaults to `--exclude .~tmp~/`. | -| `RSYNC_FILTER` | Filter rules. More convenient for larger lists. | -| `RSYNC_BLKSIZE` | Defaults to `8192`. | -| `RSYNC_TIMEOUT` | Defaults to `14400`. | -| `RSYNC_SPARSE` | Defaults to `true`. | -| `RSYNC_DELAY_UPDATES` | Defaults to `true`. | -| `RSYNC_DELETE_DELAY` | Defaults to `true`. Use `--delete-delay` rather than `--delete` | -| `RSYNC_MAXDELETE` | Maximum number of files that can be removed. Defaults to `4000`. | -| `RSYNC_RSH` | Specify the remote shell, e.g. `ssh -i /path/to/key`. | +| Parameter | Description | +| ---------------------- | --------------------------------------------------------------------- | +| `RSYNC_HOST` | The hostname of the remote server. | +| `RSYNC_USER` | (Optional) No defaults. | +| `RSYNC_PASSWORD` | (Optional) No defaults. | +| `RSYNC_PATH` | The destination path on the remote server. | +| `RSYNC_BW` | Bandwidth limit. Defaults to `0`. | +| `RSYNC_EXTRA` | Extra options. Defaults to empty. | +| `RSYNC_EXCLUDE` | Files to be excluded. Defaults to `--exclude .~tmp~/`. | +| `RSYNC_FILTER` | Filter rules. More convenient for larger lists. | +| `RSYNC_BLKSIZE` | Defaults to `8192`. | +| `RSYNC_TIMEOUT` | Defaults to `14400`. | +| `RSYNC_SPARSE` | Defaults to `true`. | +| `RSYNC_DELAY_UPDATES` | Defaults to `true`. | +| `RSYNC_DELETE_DELAY` | Defaults to `true`. Use `--delete-delay` rather than `--delete` | +| `RSYNC_DELETE_EXCLUDED`| Defaults to `true`. Use `--delete-excluded` to delete excluded files. | +| `RSYNC_MAXDELETE` | Maximum number of files that can be removed. Defaults to `4000`. | +| `RSYNC_RSH` | Specify the remote shell, e.g. `ssh -i /path/to/key`. | ### rubygems diff --git a/rsync/sync.sh b/rsync/sync.sh index d7580bd..4c592f0 100755 --- a/rsync/sync.sh +++ b/rsync/sync.sh @@ -22,11 +22,13 @@ RSYNC_RSH=${RSYNC_RSH:-''} RSYNC_DELAY_UPDATES="${RSYNC_DELAY_UPDATES:-true}" RSYNC_SPARSE="${RSYNC_SPARSE:-true}" RSYNC_DELETE_DELAY="${RSYNC_DELETE_DELAY:-true}" +RSYNC_DELETE_EXCLUDED="${RSYNC_DELETE_EXCLUDED:-true}" -opts="-pPrltvH --partial-dir=.rsync-partial --timeout ${RSYNC_TIMEOUT} --safe-links --delete-excluded" +opts="-pPrltvH --partial-dir=.rsync-partial --timeout ${RSYNC_TIMEOUT} --safe-links" [[ -n $RSYNC_USER ]] && RSYNC_HOST="$RSYNC_USER@$RSYNC_HOST" +[[ $RSYNC_DELETE_EXCLUDED = true ]] && opts+=' --delete-excluded' [[ $RSYNC_DELETE_DELAY = true ]] && opts+=' --delete-delay' || opts+=' --delete' [[ $RSYNC_DELAY_UPDATES = true ]] && opts+=' --delay-updates' [[ $RSYNC_SPARSE = true ]] && opts+=' --sparse'