Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8492947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:52:16+00:00 2026-06-10T22:52:16+00:00

I have a small java application/service that watches a root folder and its subfolders

  • 0

I have a small java application/service that watches a root folder and its subfolders using Java 7’s new java.nio.file.WatchService. When a new event occurs (new files, modifies, deletes, etc…) I fire off an rsync execution to copy files from server A to server B (and vice versa). The command uses the –delete option to ensure that files deleted from A are also removed from B. However in order to use this feature, you have to enable -r (recurse subdirectories). Normally this wouldn’t be a big deal, but the root folder is 5GB of data (19000 files, 1500 folders). Rsync is great at what it does, but still takes several minutes to run.

The problem I have is that if files change on both servers at roughly the same time, there is the potential that a new file created on server A would get deleted by the process syncing B-> A, since --delete only compares source to destination and sees the destination has more files than the source.

Since I’m already recusively watching every directory with the Java application, I don’t have to use -r (recursive) with rsync. My first thought was to limit the depth of recursion with rsync, but I don’t think that is a feature of rsync. I also considered using --exclude but am not sure what the pattern might look like.
Anyone have any ideas?

For reference, here is a sample of the generated rsync command:

rsync -r --no-group --no-owner --no-perms --update --checksum --verbose --progress --stats --delete --ignore-errors "/media/server1files/" "/server2::server2"

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T22:52:17+00:00Added an answer on June 10, 2026 at 10:52 pm

    To exclude subfolders even when using -r the appropriate pattern to use is --exclude "/**/*".

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small application in java which searches images using bing image search.
I have a small Java program that reads list of IPs from text file
I have a small java program that reads a file in, in eclipse i
I have a small Java Swing application that I want to rewrite in WPF
I have been writing a small java application (my first!), that does only a
We have a small java application running on windows that needs to be able
I have a small Java/Gradle project. I'm using the Application plugin to create a
i have to write small java database application with several tables. With that i
I'm using Eclipse to write a small Java application that uses WLST to manage
I have a Java application that launches a small C# application on the client

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.