lftp exclude syntax confusion
14,855
Solution 1
-x RX
is for matching using a Regular eXpression
, like in egrep()
, while -X GX
is used for Glob Pattern
matching, which is essentially just normal character matching, apart from *. So for example:
# To exclude .svn directories use:
mirror -e -x ^\.svn/$ /myhome/ /elsewhere
# To exclude all folders starting with a dot:
mirror -e -x /\..+/$ /myhome/ /elsewhere
# To exclude all *.bin AND *.so files:
mirror -e -X *.bin -X *.so /myhome/ /elsewhere
As you can see, you'll have to use the -X for each filetype, since you're not able to give a list, afaik.
Solution 2
Here's my (verified, working) take:
Excluding:
- hidden folders & files (also covers .git)
- the scripts/ - Folder (where I keep my
deploy.sh
) - various active / dangerous / preparation / superficious files ( nb: regExp with a pipe | operator make (her: inner, single) quotes necessary)
deploy.sh
#!/usr/bin/env bash
# switch to script parent dir == project dir
cd "$(dirname $(dirname $0))"
if ! [[ "$PWD" =~ \/myproject$ ]]; then
echo "you are not in the myproject folder!"
exit 1
fi
# a (relatively) good place to store your credits (outside repo, ...)
read FTPCREDITS < ~/.ssh/creds/FTPCREDITS
if [ -z "$FTPCREDITS" ]; then
echo "Could NOT read credits. Exiting."
exit 2
fi
ok, and finally:
lftp -c "set ftp:list-options -a; \
open $FTPCREDITS; \
lcd .; \
mirror --reverse --delete --use-cache --verbose --allow-chown \
--allow-suid --no-umask --parallel=2 \
-x '^\.' -x '^script\/' \
-x '\.(psd|rev|log|cmd|bat|pif|scr|exe|c?sh|reg|vb?|ws?)$' \
; \
close -a;"
good for testing:
--dry-run
(naturally)./script/deploy.sh | grep Transferring
to see more of the relevant
Author by
user50390
Updated on September 18, 2022Comments
-
user50390 over 1 year
I am confused with the syntax description given for lftp from their website:
-x RX, --exclude=RX exclude matching files -X GP, --exclude-glob=GP exclude matching files
How exactly do I exclude certain files during mirroring ??
--exclude filea --exclude fileb --exclude filec --exclude filea fileb filec --exclude ./filea ./fileb filec
I have also googled it and cannot find any examples of exclude statements ?!