Skip to content

Commit

Permalink
Add RSYNC_FILTER for rsync (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
iBug authored Jul 21, 2024
1 parent ee5b7ea commit d8e8dd0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
-e RSYNC_HOST=rsync.archive.ubuntu.com \
-e RSYNC_PATH=ubuntu/ \
-e RSYNC_EXTRA='--dry-run --no-r --dirs' \
-e RSYNC_FILTER='- .trace' \
--tmpfs /data \
--tmpfs /log \
ustcmirror/rsync
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ ref:
| `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`. |
Expand Down
31 changes: 11 additions & 20 deletions rsync/sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,6 @@
#LOGDIR=
#LOGFILE=

## SET IN ENVIRONMENT VARIABLES
#BIND_ADDRESS=

#RSYNC_PATH=
#RSYNC_HOST=

#RSYNC_USER=
#RSYNC_PASSWORD=
#RSYNC_RSH=
#RSYNC_BW=
#RSYNC_EXCLUDE=
#RSYNC_MAXDELETE=
#RSYNC_TIMEOUT=
#RSYNC_BLKSIZE=
#RSYNC_EXTRA=
#RSYNC_DELAY_UPDATES=
#RSYNC_SPARSE=

set -eu
[[ $DEBUG = true ]] && set -x

Expand All @@ -31,6 +13,7 @@ BIND_ADDRESS=${BIND_ADDRESS:-''}
RSYNC_USER=${RSYNC_USER:-''}
RSYNC_BW=${RSYNC_BW:-0}
RSYNC_EXCLUDE=${RSYNC_EXCLUDE:-' --exclude .~tmp~/'}
RSYNC_FILTER=${RSYNC_FILTER:-}
RSYNC_MAXDELETE=${RSYNC_MAXDELETE:-4000}
RSYNC_TIMEOUT="${RSYNC_TIMEOUT:-14400}"
RSYNC_BLKSIZE="${RSYNC_BLKSIZE:-8192}"
Expand All @@ -57,8 +40,16 @@ if [[ -n $BIND_ADDRESS ]]; then
fi
fi

filter_file=/tmp/rsync-filter.txt
echo '- .~tmp~/' > "$filter_file"
if [ -n "$RSYNC_FILTER" ]; then
echo "$RSYNC_FILTER" >> "$filter_file"
fi

if [[ -n $RSYNC_RSH ]]; then
exec rsync $RSYNC_EXCLUDE --bwlimit "$RSYNC_BW" --max-delete "$RSYNC_MAXDELETE" $opts $RSYNC_EXTRA "$RSYNC_HOST:$RSYNC_PATH" "$TO"
RSYNC_URL="$RSYNC_HOST:$RSYNC_PATH"
else
exec rsync $RSYNC_EXCLUDE --bwlimit "$RSYNC_BW" --max-delete "$RSYNC_MAXDELETE" $opts $RSYNC_EXTRA "$RSYNC_HOST::$RSYNC_PATH" "$TO"
RSYNC_URL="rsync://$RSYNC_HOST/$RSYNC_PATH"
fi

exec rsync $RSYNC_EXCLUDE --filter="merge $filter_file" --bwlimit "$RSYNC_BW" --max-delete "$RSYNC_MAXDELETE" $opts $RSYNC_EXTRA "$RSYNC_URL" "$TO"

0 comments on commit d8e8dd0

Please sign in to comment.