Ignore patterns in the form of "include only these" and "exclude" everything else inside a given root folder

I went through couple of posts here and I still have doubts.

I will be syncing from Mac folder /Users/user(this is the single common root folder of all the folders I want to sync) – but I want to include ONLY the listed folders and ONLY THESE; nothing else.

My intended sync/include set:

BLOCK A

!/Users/user/.ssh
!/Users/user/.notes
!/Users/user/.dotfiles
!/Users/user/Pictures
!/Users/user/Movies
!/Users/user/Data/Audio
!/Users/user/Dropbox/Doc Backup
!/Users/user/Dropbox/Office Docs
!/Users/user/Dropbox/Config
!/Users/user/Dropbox/Archive
!/Users/user/Dropbox/Apps
!/Users/user/Library/Mail
!/Users/user/Library/Mobile Documents/com~apple~CloudDocs
!/Users/user/Library/Messages/Archive
!/Users/user/Library/Application Support/AddressBook/Sources
!/Users/user/iCloud Drive (Archive)

Do I need to do anything else? Maybe something like this? Or what I have done above it sufficient?

BLOCK B

/Users/user/Data/*
!/Users/user/Data

/Users/user/Dropbox/*
!/Users/user/Dropbox

/Users/user/Library/Mobile Documents/*
!/Users/user/Library/Mobile Documents

/Users/user/Library/Messages/*
!/Users/user/Library/Messages

/Users/user/Library/Application Support/AddressBook/*
!/Users/user/Library/Application Support/AddressBook

/Users/user/Library/Application Support/*
!/Users/user/Library/Application Support

/Users/user/Library/*
!/Users/user/Library

/Users/user/*
!/Users/user

Now do I even need to do this as well? Since my root/sync folder will be “/Users/user” I think it won’t even scan anything outside it, right?

BLOCK C

/Users/*
!/Users
*

I also want to ignore these no matter where they are - so I have kept there at top - these might be inside my include folders as well

BLOCK D

.DS_Store
*.swp
.Trash
.Xauthority
.bash_sessions
/Users/user/Pictures/Photos Library.photoslibrary
*.cache
.cache
/Users/user/Music/iTunes
build/
gradle/
.idea/
*.iml

Do I need all A, B, C, D?

Also, does the order matter? Do I need to keep certain include/exclude patters above/below one another in certain order for them to work or for them to be optimised?

Essentially what will be the simplest/cleanest way to achieve this?

Syncthing ignore patterns are folder-relative not absolute, and first match wins. I suggest starting with small and simple and using trial and error, instead of building a castle on paper up front.

This is not castle on paper! This is my trial and error. I tried many ways but I am not able to figure it out. I have this specific use case so instead of trying to type some other example and then again getting confused I presented the entire folder hierarchy as it is.

I went through the doc as well but it was not helpful (yes, I have seen couple of posts where commenders have have just replied “it’s in the doc”).

So I posted here hoping someone might have gone through a similar use case and can help me.

Sorry, I presumed this was “on paper” since none of the patterns would work as written. As said, think “first match wins” and “folder relative paths”. If your folder root is /Users/user and you want to sync only /Users/user/Movies, start with

!Movies
*

(“Don’t ignore Movies; Ignore everything else”)

Build from there, adding patterns as required.

1 Like

Well, just that worked like a charm! I think I was unnecessarily thinking more complex rules.

  • Exclude only root folder (no other sub-root-folder ignore rules required)
  • And then invert the exclusion for each folders/files you want to be included.

I will share my test/dummy example (in case others have this use case):

I created this test file/folder hierarchy inside my root folder (i.e. the added folder for sync).

image

And then I only wanted to backup these out of the heirarchy above.

Library/Application Support/AddressBook/Sources

Library/Messages/Archive

Library/Mail

Dropbox/db_d_2
Dropbox/db big d_3
Dropbox/db_d_1

Data/data_dir_1
Data/data_dir_1

Pictures
Movies
.dotfiles
.ssh
a

All I had to do was add this in Ignore Patterns:

!Library/Application Support/AddressBook/Sources
!Library/Messages/Archive
!Library/Mail
!Dropbox/db_d_2
!Dropbox/db big d_3
!Dropbox/db_d_1
!Data/data_dir_1
!Data/data_dir_1
!Pictures
!Movies
!.dotfiles
!.ssh
!a
# then just like done above ^ we invert ignoring/exclusion of everything we want to sync/include listing each path

# ignores everything in root folder
*

That’s it - ignore everything and then invert (with !) path of what you do not want to ignore.

I could verify and I could get exactly what I wanted on my iPhone (except hidden files/folders as I could not see them on iPhone)

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.