Synchronisation of data between NASs

From LinnDocs
Jump to: navigation, search

This describes the means of synchronising data between several Mac mini NASs.

We have a single master NAS on the main plant network, and 3 NASs in the South Wing area, one for each of the isolated networks.

  • Linn Home
  • Dem Rooms
  • Welcome Area

Due to the network topology, the isolated networks can access the main plant network, but access the other way round is not available (without some non-default reconfiguration of network components). Hence a pull synchronisation method was required, so that changes from the master NAS are pulled in by the slave NASs in a regular manner.

This has been achieved using the standard OS/X tools rsync, launchctl and ssh. As this uses an SSH connection the synchronisation method described below should be extensible to any setup where the NASs can be connected using SSH, including remotely across the internet (although bandwidth requirements are likely to be a major factor in this case).

Configure Remote Access on Server

On the server (master), remote (ssh) access must be enabled

  • System Preferences -> Internet & Wireless -> Sharing
  • Check the Remote Login service

Configure SSH access from Clients

For every client (slave), it is necessary to configure SSH access to the server. The method described here includes steps to remove the requirement for a password to be entered (so that the synchronisation can be executed automatically.) As described this leaves a security hole in that anyone with access to the client machine can access the server machine without any further restrictions.

On client

  • Open terminal window and execute ssh-keygen -t rsa
    • Accept defaults for all prompts (file location and blank passkey)
  • Open the file ~/.ssh/ and copy the entire (one line) contents
  • Open another terminal window and connect to the server
    • ssh <user>@<address>
    • Answer yes if prompted to accept new connection
    • Enter password for server to connect
  • In the server window create (or open) the file ~/.ssh/authorized_keys
  • Append the contents of the clients to this file and save it
  • Exit the server, and try reconnecting
    • ssh <user>@<address>
    • This time should connect without requiirement to enter password

Note: macOS Sierra uses OpenSSH 7.0 which deprecates the use of DSA keys. It's now recommended to use RSA, so the above has been edited accordingly.

Configure timed auto-execute of rsync on Clients

The rsync command line which is required (to sync between 2 USB drives both called USBDrive1) is

rsync --quiet --update --recursive --whole-file --delete-during <user>@<address>:/Volumes/USBDrive1/Music /Voumes/USBDrive1

This can be made to auto-execute at regular time intervals using launchctl on Mac

  • On every client
    • Create the plist file ~/Library/LaunchAgents/com.user.sync.plist
    • Ensure this is created under the same user that the SSH keys setup above
    • Update name and address in the file below
    • This gives a repetition interval of 1/2 hour (1800 secs) as defined at end
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" ""> 
<plist version="1.0">
  • Add this file to the launchctl executor
launchctl load ~/Library/LaunchAgents/com.user.sync.plist

To test:

launchctl start com.user.sync

Any time changes are made to the plist file, launchctl must be reloaded

launchctl unload ~/Library/LaunchAgents/com.user.sync.plist
<update plist>
launchctl load ~/Library/LaunchAgents/com.user.sync.plist