Skip to main content

How to set-up a rsync server in Mac OS X / macOS

Source: https://www.jafdip.com/how-to-setup-rsyncd-on-mac-os-x/
One of the most versatile utilities developed is rsync, however; learning to effectively use the application can be a daunting task. Rsync is useful for conducting backups to remote file servers or even mirroring a local drive to a removable one. It supports transferring files over ssh as well as it’s own protocol. Unfortunately, to use the built in rsync protocol you need to set up an rsync server, which on a Mac can be quite tricky.

On the one hand, you can simply type rsync —daemon and it will start a rsync daemon running on TCP port 873. But without the appropriate rsyncd.conf things can get a little messy. In addition, if you reboot the ‘server’ the process will not restart automatically. The worst thing is to have a system that has been operational for several months suddenly stop because someone rebooted the hardware and no one remembered that the process needed to be relaunched. Personally, I think it is much better to have the system offer some more resiliency by automating this process.

On the Mac, unfortunately inetd is no longer a viable option, thus you need to use launchd and launchdctl to load your XML described process file. So, I created the following plist (property list) file that I installed as root into /Library/LaunchDaemon.

Those instructions were tested on all versions of Mac OS from 10.3 to 11.0.
  1. (Optional) Install  latest rsync and ignore Mac OS X rsync
    brew install rsync
  2. As privileged user, create a start-up configuration file
    1. First step is to open the file for edit...
      • If using rsync from brew:
        sudo vi /Library/LaunchDaemons/org.samba.rsync.plist
      • If using rsync shipped with macOS
        sudo vi /Library/LaunchDaemons/rsync.plist
    2. ...with the following contents
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
      <plist version="1.0">
      <dict>
          <key>Disabled</key>
          <false/>
          <key>Label</key>
          <string>org.samba.rsync</string>
          <key>Program</key>
          <string>/usr/local/bin/rsync</string>
          <key>ProgramArguments</key>
          <array>
              <string>/usr/local/bin/rsync</string>
              <string>--daemon</string>
              <string>--no-detach</string>
              <string>--verbose</string>
              <string>--config=/usr/local/etc/rsyncd.conf</string>
          </array>
          <key>RunAtLoad</key>
          <true/>
          <key>KeepAlive</key>
          <dict>
              <key>SuccessfulExit</key>
              <false/>
          </dict>
      </dict>
      </plist>
    3. Pay special  attention to the highlighted text. 
      1. Label (it appears twice)
        1. brew: org.samba.rsync
        2. Mac OS: rsync
      2. rsync path:
        1. brew: /usr/local/bin/rsync
        2. Mac OS: /usr/bin/rsync
      3. Configuration file
        1. brew: /usr/local/etc/rsyncd.conf
        2. Mac OS X: /etc/rsyncd.conf
  3. As privileged user, create a configuration file
    1. Open file for edit...
      • If using rsync from brew
        sudo vi /usr/local/etc/rsyncd.conf 
      • If using rsync shipped with macOS
        sudo vi /etc/rsyncd.conf
    2. with
      hosts allow = 192.168.0.0/16
      reverse lookup = false
      list = yes
      uid = nobody
      gid = wheel
      log file = /var/log/rsync.log
      motd file = /usr/local/etc/rsyncd.motd
      [Backup]
        path = /Volumes/BackupVolume/BACKUPS/
        comment = Backup area
        read only = false
        write only = false
        use chroot = false
      #  max verbosity = 100
      [vol014]
        path = /Volumes/vol014
        comment = Software area
        read only = false
        write only = false
        use chroot = false
      #  max verbosity = 100
    3. Pay attention to the highlighted text
      1. My rsync server is limited to my internal network
      2. There is a specific log file for my rsync server
      3. macOS is based on FreeBSD. The root group is wheel, not root (like Linux).
      4. On connecting, the user receives a large screen message
        1. brew: /usr/local/etc/rsyncd.motd
        2. Mac OS X: /etc/rsyncd.motd
  4. As privileged user, create a Message-Of-The-Day file (/usr/local/etc/rsyncd.motd
    1. My name:
      https://www.patorjk.com/software/taag/#p=display&f=Big&t=ANDREAS%0ABERENDSEN%0A
    2. Host name: 
      https://www.patorjk.com/software/taag/#p=display&f=Big&t=HG000005%0A
    3. brew:
      sudo vi /usr/local/etc/rsyncd.motd
    4. Mac OS X:
      sudo vi /etc/rsyncd.motd
    5. with
      ==================================================================== 2020-Oct-07
                 _   _ _____  _____  ______           _____
           /\   | \ | |  __ \|  __ \|  ____|   /\    / ____|
          /  \  |  \| | |  | | |__) | |__     /  \  | (___
         / /\ \ | . ` | |  | |  _  /|  __|   / /\ \  \___ \
        / ____ \| |\  | |__| | | \ \| |____ / ____ \ ____) |
       /_/__  \_\_|_\_|_____/|_|__\_\______/_/   _\_\_____/__ _   _
       |  _ \|  ____|  __ \|  ____| \ | |  __ \ / ____|  ____| \ | |
       | |_) | |__  | |__) | |__  |  \| | |  | | (___ | |__  |  \| |
       |  _ <|  __| |  _  /|  __| | . ` | |  | |\___ \|  __| | . ` |
       | |_) | |____| | \ \| |____| |\  | |__| |____) | |____| |\  |
       |____/|______|_|  \_\______|_| \_|_____/|_____/|______|_| \_|

      UNAUTHORIZED ACCESS TO THIS DEVICE IS PROHIBITED

      You must have explicit, authorized permission to access or configure this 
      device. Unauthorized attempts and actions to access or use this system may 
      result in civil and/or criminal penalties. All activities performed on this 
      device are logged and monitored.

      Name  : HG000007.local

          Model Name            : Mac mini
          Model Identifier      : Macmini7,1
          Processor Name        : Dual-Core Intel Core i5
          Processor Speed       : 1,4 GHz
          Number of Processors  : 1
          Total Number of Cores : 2
          L2 Cache (per Core)   : 256 KB
          L3 Cache              : 3 MB
          Boot ROM Version      : 249.0.0.0.0
          SMC Version (system)  : 2.24f32
          Serial Number (system): C07R11PZG1HV
          Hardware UUID         : F61F0D48-B3E7-5335-8EAB-5B93B8CF2BE0

      Memory: 4GB (BANK 0/DIMM0: 2GB DDR3 1600 MHz)
                  (BANK 1/DIMM0: 2GB DDR3 1600 MHz)

      Swap  :
      Disk  :
          /dev/disk0 (internal, physical):  2.0 TB
          /dev/disk1 (synthesized)       :  2.0 TB
          /dev/disk2 (external, physical):  2.0 TB
          /dev/disk3 (external, physical):  8.0 TB
          /dev/disk4 (external, virtual) : 10.0 TB

      Distro: Darwin Kernel Version 19.6.0 xnu-6153.141.1~1/RELEASE_X86_64 x86_64
              ProductName:    Mac OS X
              ProductVersion: 10.15.6
              BuildVersion:   19G2021

      Network:
          en0: 192.168.0.2/24   38:c9:86:30:35:8c  Ethernet
          en1: 192.168.1.28/24  bc:54:36:cd:a5:c4  Wi-fi

        _    _  _____  ___   ___   ___   ___   ___ ______
       | |  | |/ ____|/ _ \ / _ \ / _ \ / _ \ / _ \____  |
       | |__| | |  __| | | | | | | | | | | | | | | |  / /
       |  __  | | |_ | | | | | | | | | | | | | | | | / /
       | |  | | |__| | |_| | |_| | |_| | |_| | |_| |/ /
       |_|  |_|\_____|\___/ \___/ \___/ \___/ \___//_/
      ===================================================== /usr/local/etc/rsyncd.motd
  5. (Mac OS 10.15 & 10.14) Allow rsync to have access to the volumes. This is using the GUI. I am researching how to it form the command line.
    1. For Mac OS 10.15, 10.14
      1. System Preferences > Security & Privacy > Privacy > Full Disk Access
      2. Click the pad lock and type the admin (your user account) password
      3. Click the plus sign ("+") just below list box
      4. Navigate to /usr/local/bin/ and chose rsync
  6. Launch the rsync server
    • If using rsync from brew 
      sudo launchctl load /Library/LaunchDaemons/org.samba.rsync.plist
    • If using rsync shipped with macOS
      sudo launchctl load /Library/LaunchDaemons/rsync.plist
  7. Check rsync is up and running
    $ rsync --stats 192.168.0.5::
    ==================================================================== 2021-Jan-22
               _   _ _____  _____  ______           _____
         /\   | \ | |  __ \|  __ \|  ____|   /\    / ____|
        /  \  |  \| | |  | | |__) | |__     /  \  | (___
       / /\ \ | . ` | |  | |  _  /|  __|   / /\ \  \___ \
      / ____ \| |\  | |__| | | \ \| |____ / ____ \ ____) |
     /_/__  \_\_|_\_|_____/|_|__\_\______/_/   _\_\_____/__ _   _
     |  _ \|  ____|  __ \|  ____| \ | |  __ \ / ____|  ____| \ | |
     | |_) | |__  | |__) | |__  |  \| | |  | | (___ | |__  |  \| |
     |  _ <|  __| |  _  /|  __| | . ` | |  | |\___ \|  __| | . ` |
     | |_) | |____| | \ \| |____| |\  | |__| |____) | |____| |\  |
     |____/|______|_|  \_\______|_| \_|_____/|_____/|______|_| \_|

    UNAUTHORIZED ACCESS TO THIS DEVICE IS PROHIBITED

    You must have explicit, authorized permission to access or configure this
    device. Unauthorized attempts and actions to access or use this system may
    result in civil and/or criminal penalties. All activities performed on this
    device are logged and monitored.

    Name  : HG000005.local

        Model Name            : Mac mini
        Model Identifier      : Macmini7,1
        Processor Name        : Dual-Core Intel Core i5
        Processor Speed       : 1,4 GHz
        Number of Processors  : 1
        Total Number of Cores : 2
        L2 Cache (per Core)   : 256 KB
        L3 Cache              : 3 MB
        Boot ROM Version      : 249.0.0.0.0
        SMC Version (system)  : 2.24f32
        Serial Number (system): C07R11PZG1HV
        Hardware UUID         : F61F0D48-B3E7-5335-8EAB-5B93B8CF2BE0

    Memory: 4GB (BANK 0/DIMM0: 2GB DDR3 1600 MHz)
                (BANK 1/DIMM0: 2GB DDR3 1600 MHz)

    Swap  :
    Disk  :
        /dev/disk0 (internal, physical):  2.0 TB
        /dev/disk1 (synthesized)       :  2.0 TB
        /dev/disk2 (external, physical):  2.0 TB
        /dev/disk3 (external, physical):  8.0 TB
        /dev/disk4 (external, virtual) : 10.0 TB

    Distro: Darwin Kernel Version 19.6.0 xnu-6153.141.1~1/RELEASE_X86_64 x86_64
            ProductName:    Mac OS X
            ProductVersion: 10.15.6
            BuildVersion:   19G2021

    Network:
        en0: 192.168.0.2/24   38:c9:86:30:35:8c  Ethernet
        en1: 192.168.1.28/24  bc:54:36:cd:a5:c4  Wi-fi

      _    _  _____  ___   ___   ___   ___   ___ ______
     | |  | |/ ____|/ _ \ / _ \ / _ \ / _ \ / _ \____  |
     | |__| | |  __| | | | | | | | | | | | | | | |  / /
     |  __  | | |_ | | | | | | | | | | | | | | | | / /
     | |  | | |__| | |_| | |_| | |_| | |_| | |_| |/ /
     |_|  |_|\_____|\___/ \___/ \___/ \___/ \___//_/
    ===================================================== /etc/rsyncd.motd

    drwxrwxrwx         748 2021/01/01 16:38:50 .
    -rwxrwxrwx       24580 2021/01/22 14:44:36 .DS_Store
    -rw-r--r--           0 2020/10/17 01:34:43 .com.apple.timemachine.donotpresent
    -rw-r--r--           0 2020/11/17 09:49:17 .com.apple.timemachine.supported
    -rw-------   181585142 2020/12/25 19:15:02 Projetos-20201225T180620Z-001.zip
    -rw-r--r--      178322 2020/12/17 21:54:08 apple_power_list.txt
    drwxrwxrwx         272 2020/10/14 21:03:18 .DocumentRevisions-V100-bad-1
    drwx------         272 2020/11/27 19:54:09 .Spotlight-V100
    drwxrwxrwt         136 2019/10/10 03:15:08 .TemporaryItems
    d-wx--x--t         102 2020/12/23 06:08:41 .Trashes
    drwx------         238 2020/11/19 18:54:35 .finf
    drwxrwxrwx       21114 2020/12/23 06:08:44 .fseventsd
    drwxrwxrwx        1394 2020/10/29 12:57:15 Disc Images
    drwxrwxrwx        1292 2020/11/25 18:32:44 Internet Mirrors
    drwxr-xr-x         136 2020/11/03 18:27:23 Library
    drwxr-xr-x         306 2020/11/07 14:22:10 Software Repository
    drwxr-xr-x         136 2019/08/15 23:47:19 torrent_NB

    Number of files: 17
    Number of files transferred: 0
    Total file size: 181788044 bytes
    Total transferred file size: 0 bytes
    Literal data: 0 bytes
    Matched data: 0 bytes
    File list size: 481
    File list generation time: 0.001 seconds
    File list transfer time: 0.000 seconds
    Total bytes sent: 75
    Total bytes received: 3065

    sent 75 bytes  received 3065 bytes  6280.00 bytes/sec
    total size is 181788044  speedup is 57894.28
  8. Troubleshooting
    1. If not working, try to run the rsync from the command line while tailing the log files:
      1. In one terminal window (or tab), run
        tail -f /var/log/rsync.log
      2. In another terminal window (or tab), run the following command (the --port switch is to ensure that there are no security limitations on the server):
        sudo /usr/local/bin/rsync -v -v -v -v -v --daemon --no-detach --config=/usr/local/etc/rsync.conf --port=5678
      3. From another terminal window (or tab), or another computer, run
        rsync rsync://<your server-ip-or-name>:5678
    2. If you receive the motd message, then the problem can be the port or the plist file

Comments

Popular posts from this blog

TV Series - The Brokenwood Mysteries [NZ] (2014) - Season 10

 

Movie - Sin City: A Dame to Kill For (2014)

 

Movies - Deadpool & Wolverine (2024)