PIDFile = /run/syncservice/syncservice.pidĮxecStartPre = /bin/mkdir /run/syncserviceĮxecStartPre = /bin/chown -R root:root /run/syncserviceĮxecStopPost = /bin/rm -rf /run/syncserviceĬhmod this service file and reload the systemd daemon: chmod 755 /etc/systemd/system/sync. To finish things off, lets create the systemd service file that can stop, start, and reset the script on demand or on specific events like a system bootup.Ĭreate a file called rvice in the directory /etc/systemd/system/ and put the following contents in it: Rsync -avz -e "ssh -i /root/rsync-key -o StrictHostKe圜hecking=no“ /opt/syncfiles/ saved this script in the /opt directory as file-sync.sh. You can create folders in your home directory, and keep the contents of those. Inotifywait -r -e modify,attrib,close_write,move,create,delete /opt/syncfiles The Nextcloud Desktop Sync Client enables you to connect to your Nextcloud Server. # Supposed to run on rsync-host01, change rsync-host02 to rsync-host01 to make a script that is meant to run on rsync-host02. Now that you have got all the pre-configuration work done, it's about time to write a script that goes through an infinite loop with inotifywait in it: #!/bin/bash # Remember to execute this script on all servers separately! Then, copy the output of the script in all of your servers' authorized_keys files. # Removing public key for security purposes. # Paste the output in your destination servers' ~/.ssh/authorized_keys file: Let's call it SyncFiles: mkdir /opt/syncfilesĪnd for secure file transfer, we want a public-private key link for the transfer link that rsync uses, this is how to configure it: ssh-keygen -t rsa -f ~/rsync-key -N '' Backup/failover servers with the need for constant replicationįirst things first: we need to get all the dependencies installed on the 3 servers with this one-line command: apt update & apt -y install openssh-server rsync inotify-toolsĪfter that, let's create a specific folder that we want to sync.Load balanced file storage clusters/servers.A development environment, where constant file transfers are taking up a lot and/or too much time.I could see some potential for workflow improvement on these situations: All rsync traffic is supposed to be worked out over SFTP. All these 3 machines needed to be setup with the following software packages:Īlso noteworthy is that these machines are absolutely not connected through a private network. I needed to get myself a nice development environment at first so I started off 3 virtual servers which all run Ubuntu 16.04, my personal favourite. Rsync is a great solution, but having to run rsync manually would take a lot of unnecessary time away, right? And that is where inotify is for: real-time monitoring of your filesystem so that your files can be synced between multiple machines with the power of rsync! Well, I got the solution for you: with a little bit of thinking in an innovative way I have found the solution that might bring you onto the right path as well. They contain files that you want to have automatically synced when possible, because that would save a lot of time. So: you've got two or more clients and/or servers. Sync folders and files on Linux with rsync and inotify
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |