Where is the ignore pattern written?

Synchronization between mobile phone and computer. I found that the ignore mode works no matter whether it is written on the mobile phone or the computer.

Do I need to write this repeatedly on both the mobile phone and the computer?

What is the difference between writing in both mobile phone and computer locations, and writing only in mobile phone or computer?

Let’s assume that both your phone and computer are sharing just a single folder “Sync” in “Send & Receive” mode on both sides.

The computer has 4 files:

Sync/
├── doc.txt
├── image.jpg
├── music.mp3
└── video.mp4

If you wanted to sync everything but the video file to your phone, your ignore pattern might be something simple like this:

*.mp4

The .stignore could be only on your computer, only on your phone, or both. Regardless, video.mp4 wouldn’t be copied from your computer to your phone. But from a convenience point of view, if you need to update the ignore patterns regularly, it might be more convenient to edit them on your computer.

However, what to do if there are two computers syncing to the same phone? You could maintain separate .stignore files on each computer to prevent video files from being pushed out to your phone – or instead have just one .stignore file on your phone to prevent downloading of video files from any linked device.

So it’s really a per-user preference where to put the .stignore file(s) depending on the use case.

Personally, I have a bare bones ignore pattern that chain loads all of the other patterns intended for that particular device, e.g. on my phone .stignore might look like this:

#include .stignore.phone

(Note that there’s a bit of a catch-22 in that you’ll have to provide a temporary .stignore.phone so that Syncthing has something to load during the initial start otherwise it’ll cause an error.)

Then from my desktop I can conveniently maintain all of my .stignore files from one place:

Syncthing/
├── .stignore.laptop
├── .stignore.phone
├── .stignore.tablet
└── notes.txt
2 Likes

gadget,thanks for the reply. I tried to understand #include, but I still have a question.

As for me, I only have two nodes synchronized between PC and mobile phone. For convenience, I only maintain one .stignore file on PC. I tested that this can also achieve my purpose.

How is this different than creating a copy of .stignore on both PC and mobile phone? If only one copy of .stignore is created in the PC, will the mobile phone increase the scanning range and increase power consumption?

I don’t think it really makes any real difference in your setup since the ignore filter isn’t directional. And since you’re talking about copying .stignore, you’d end up with the same ignore patterns on both PC and phone. No advantage or disadvantages that come to mind. In a sense, you’d just have a “backup” filter – i.e. if one of the .stignore files were accidentally deleted you’d still be filtering as expected.

From a purely technical standpoint, in theory having .stignore on the phone would require Syncthing to consume extra CPU cycles and RAM for the pattern matching, but I highly doubt it would be noticeable at unless your ignore patterns were thousands of lines and there were tens of thousands of files/folders to compare against.

What I synchronize is the root directory of the mobile phone user. Both the mobile phone and the computer are receiving and sending. The negation and ignore rules are used. The total number of files currently is 30,000, about 6G in size.

Ignore rules:

/Android
!/DCIM
!/Pictures
*

I don’t know much about the technical aspects, but I understand that Syncthing will first read the ignore rules, then filter out the files/folders to be synchronized, and then perform change detection and regular scanning. If there is no such ignore rule (or only /Android), will all files on the phone be monitored and scanned regularly?

I know that monitoring does not seem to consume much CPU, so regular scans require all files to be scanned and then sent to the PC.

After the PC receives the data message sent by the mobile phone, it rejects the unnecessary data according to its own ignore rules, so it can be synchronized as expected.

This step is just my own guess. If this is really the case, I don’t feel any obvious slowdown based on the current amount of data.

I’m just curious if the process is like this. As time goes by, the amount of data will increase.

If the execution process on the mobile phone is as I guessed, when setting the ignore rule in the inverse mode on the mobile phone: How much CPU loss will there be if the regular scan operation detects all data rather than the method of detecting limited data?

Given the ignore patterns above, Syncthing will only scan /DCIM and /Pictures.

/Android isn’t necessary because it’s covered by the wildcard pattern (*) at the bottom.

If you mean .stignore contains only this…

/Android

… then yes, Syncthing will monitor and scan everything else around it.

Correct, file watching relies on the OS filesystem events system. The OS is aware of every filesystem event so it’s just tapping into that with minimal overhead (low CPU plus RAM – more files watched = more RAM used).

Note that whenever Syncthing is notified by the OS of a change, it triggers a rescan. It’s why there’s a default 10-second countdown window before rescanning to allow for bunching of multiple events.

It’s just metadata that’s initially sent. After filtering, the PC then asks the phone for the missing blocks it needs (and vice versa).

The number of files watched doesn’t really impact the filesystem event watcher much. The bigger impact is in memory usage. If I recall correctly, every file/directory watched requires 1KB of RAM (i.e. 1 million files = 1GB). However, even budget phones made within the past 5 years have 2, 3 or more gigabytes of RAM.

A 30-megapixel camera might produce an average of 3MB JPEG files. So 1 million photos is 3×10¹² bytes (3TB). My current phone’s SD card slot supports up to 1TB, so I’ve got a storage problem long before Syncthing needs to monitor one million files. :smile:

Thanks for the serious answer. I now know that the performance problem is mainly RAM usage. Currently, I don’t need to consider this issue at all with my storage capacity.

Next I will use the #include pattern I learned recently to design my own ignore scheme.

Synchronization of two devices: mobile phone and computer. As long as you create an ignore rule in one device, you can maintain synchronization according to the plan.

For convenience, you can only create the ignore file in the computer node so it is easy to edit. Keep the ignore rule blank in the mobile phone.

What you gain is what you lose. This makes it easier to ignore the editing of files, but it will also lead to an increase in the memory usage of the phone and the inconsistency between the “global status” and “local status” in the synchronized folder display information, which looks very uncomfortable.

Finally, the #include method was used to create a directory “stignore/” and a shareable ignore file “/stignore/default.stignore” was created here. This way, the ignore file can be easily edited on the computer, and the status is displayed. Consistent

You only need to manually edit .stignore on your computer and mobile phone and write #include /stignore/default.stignore, and then you can use it happily.

So happy to have learned and implemented such useful tips.

Record my ignored files

!/stignore
!/_Files
/Pictures/.*
!/Pictures
!/data
!/backups
!/afwall
!/Tasker
!/Record
!/yong
!/voix
!/XEdgePro
!/Recordings
!/longshot
*