A. Vreeswijk
A. Vreeswijk

Reputation: 954

rsync Include/Exclude specific file type

I have a problem. I am trying to use rsync to copy all the .php files from my /var/www to another server, except for website1 and website2, so I created this command:

rsync -avz -e 'ssh -p 28' --relative --exclude={'website1.com','website2.com'} --include='*.php' --delete-during --backup --backup-dir=/mnt/usb/shares/me/ubuntu_backup/ --suffix=".""201911261032" /var/www [email protected]:/mnt/usb/shares/me/ubuntu/

I would like to see that all the .php files are being rsynced, but when I run this command, not only the .php files are being coppied, but also .jpg, .csv, etc.

How can I make this work?

Upvotes: 0

Views: 537

Answers (1)

chepner
chepner

Reputation: 531055

--include really means "don't exclude"; everything is implicitly included to begin with, so --include is used to override a previous --exclude.

You want something like

options=(
   -avz
   -e 'ssh -p -28'
   --relative
   --exclude '*'           # Don't transfer *anything* ...
   --include '*.php'       # ... except for the .php files ...
   --exclude website1.com  # ... in a directory other than website1.com ...
   --exclude website2.com  # ... or website2.com
   --delete-during
   --backup
   --backup-dir=/mnt/usb/shares/me/ubuntu_backup/
   --suffix=".""201911261032"
)
rsync "${options[@]}" \
   /var/www \
   [email protected]:/mnt/usb/shares/me/ubuntu/

Upvotes: 2

Related Questions