9

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 ?!

2 Answers 2

9

-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.

3

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
1
  • What's in FTPCREDITS? Maybe explain a bit more what that lftp command does. Commented Sep 5, 2023 at 21:43

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.