2

I'm wondering if my scenario can actually be handled with rsync. Rsync working fine between my local and my remote.

htdocs/    
  folderswithfilesIneed/
    somefilesandfolders.jpg
    afolder/
      somefiles.png
  version/
    photofolder/
      photowithstupidname.jpg
      ...
   anotherfolderwithstupidname/
      photowithstupidname.jpg
      ...
   ...

I want to sync all this files and folders but exclude all files in 'photofolder' and 'anotherfolderwithstupidname'

Anyone have an idea to to that in one time ?

EDIT : To be clearer there's many folders in "version" so I can't exclude their content one by one.

2 Answers 2

2

Sure, this is simple to do with exclude rules. To exclude a directory and all of its contents, just exclude the directory itself, it won't even be traversed. To include a directory somedir but not its contents, i.e. transfer an empty directory, exclude somedir/*. When an exclude clause begins with a /, it's a path from the root of the directory you're synchronizing.

rsync -a --exclude='/version/photofolder/*' --exclude='anotherfolderwithstupidname/*' htdocs/ elsewhere/

If you want to include all subdirectories of …/version but not non-directory files in …/version and not the content of the subdirectories:

rsync -a --include='/version/*/' --exclude='/version/*' htdocs/ elsewhere/

If you want to include all subdirectories of …/version and their contents, but not non-directory files in …/version:

rsync -a --include='/version/*/' --include='/version/*/*' --exclude='/version/*' htdocs/ elsewhere/
5
  • Thanks for your answer, but I forgot to add an information, I have edit my post. To be clearer there's many folders in "version" so I can't exclude their content one by one.
    – Michael
    Jun 16, 2016 at 12:59
  • @elkoo How are the directories to exclude determined? Do you want to exclude all the subdirectories of version? Jun 16, 2016 at 13:08
  • I want only folder and subfolder in version, I want exclude all files.
    – Michael
    Jun 20, 2016 at 13:44
  • @elkoo See my edit Jun 20, 2016 at 15:44
  • thanks Gilles, that's sound good, i'll try this as soon as possible, merci !
    – Michael
    Jun 28, 2016 at 15:21
0

New command string which creates --included dirs and copies it's content dir and/or files, but ONLY 2 DIRS DEEP. Why?

rsync -avid --progress ~/MyDocuments/'Inet Publishing'/ --recursive --include='LandisTwo (2019)' --include='LandisTwo (2020) {backup}' --include='*.*' --exclude='**/' e6420:/home/landis/Media/2TBackup/Backups/MyDocuments/"Inet\ Publishing"/ | tee -a ~/logs/Backup-InetPublishing_2020.txt
  • I've descovered that the Directories are Created, but NO FILES are copied to them (no recursion). files in parent are copied, but Not sub dirs - working on it.

this works for me, from workstation to server, backing up (rysnc) my personal site to another server in addition to the whole directory w/ all sites when rysnc'ing parent ../Inet\ Publishing (the 'n' in -avin is 'Dry-Run', remove.).

The --exclude */ is all other directories in 'Inet Publishing/' and seems to have to be After --include per man rsync process order ( if before --include, then Everything is --excluded and no further tokens are processed, at least that's how i read it and in practice dry runs when coming up with this. ).

This is actually one line out of one of my scripts i run with cron. *obviously, the destination host can be an IP, i have the hosts defined in /etc/hosts and have ssh key pairs,,, so i use the host name.

rsync -avin --progress ~/MyDocuments/'Inet Publishing'/ --include='LandisTwo (2019)' --include='LandisTwo (2020) {backup}' --exclude='*/' e6420:/home/landis/Media/2TBackup/Backups/MyDocuments/ | tee -a ~/logs/Backup-InetPublishing_2020.txt

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .