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 3456014
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:41:05+00:00 2026-05-18T09:41:05+00:00

I have a backup server which receives many rsync connections every hour. Since having

  • 0

I have a backup server which receives many rsync connections every hour. Since having too many open rsync instances might crash it, I want to limit the number of concurrent instances using a Semaphore. What I have in mind is something like:

ssh root@backup_server "get_semaphore"     #Will hold until semaphore released
rsync -avzrL --super --delete local_directory root@backup_server:`localhost`

Any ideas?

  • 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-05-18T09:41:06+00:00Added an answer on May 18, 2026 at 9:41 am

    In my opinion, you should be looking at limiting the number of concurrent connections directly on the server side, so that you don’t have to do anything extreme on the client side:

    (1) If you run rsync in daemon mode, there is a max connections option for rsyncd.conf.

    (2) On Linux, you can use iptables and its connlimit module to limit the number of concurrent connections to a port from one or more remote hosts. You may have to force any rsync clients to use a different port than your normal ssh users and have an sshd instance listen to that as well.

    (3) Replace your rsync binary on the server with a wrapper script that will catch the –server parameter that is used internally by rsync and stall until a slot is available. Said wrapper script should make sure that no more than N instances of itself are executed at the same time. E.g.

    #!/bin/bash
    
    N=5
    
    mutex_hold() {
        while ! mkdir /var/lock/rsync/mutex 2>/dev/null; do
           sleep 1
        done
    }
    
    mutex_release() {
        rmdir /var/lock/rsync/mutex
    }
    
    if [[ "$1" = "--server" ]]; then
        shopt -s nullglob
    
        while mutex_hold && A=(/var/lock/rsync/[0-9]*) && [[ "${#A[@]}" -ge "$N" ]] && mutex_release; do
           sleep 1
        done
    
        touch /var/lock/rsync/$$
    
        mutex_release
    
        rsync.bin "$@"
    
        rm -f /var/lock/rsync/$$
    else
        rsync.bin "$@"
    fi
    

    Please note that this script is mostly untested and that it lacks the necessary trap code to remove the lockfile even if interrupted. It also does not take care of any stale lock files etc or creating the lock directory.

    If you are set on making your own semaphore implementation, you might be interested in the mutex I used above, in order to avoid the race condition between counting the number of lockfiles and creating a new lockfile, which might allow two (or more) instances to run in a single slot.

    In all of these cases you should make sure that your clients can handle connection timeouts or rejected connections gracefully.

    If you really want to use a semaphore-style system as you proposed, the script above might serve with a few modifications.

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

Sidebar

Related Questions

I have a tar backup from an old subversion server which has long since
I have a backup server that automatically backs up my live site, both files
We have customers who, for unassailable reasons, cannot use SQL Server's built-in backup features
I have a WCF client/server app which is communicating over HTTP using the WSHttpBinding.
The situation at the moment is that we have a sharepoint server which started
I have: SQL Server 2008 Database Name: database1 I had taken backup from database1
I have encapsulated a backup database command in a Try/Catch and it appears that
I have an Oracle database backup file (.dmp) that was created with expdp .
I have this idea for a free backup application. The largest problem I need
I have a full MS SQL Backup file that I would like to extract

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.