Friends,
We all know rsync is a good tool to sync files/directories.
Every time your want to sync, you need to run rsync commands. But what if you want to run rsync as a daemon? Every change in the source will be synced to destination location manually?
Below is a small script to do this
On source location
We all know rsync is a good tool to sync files/directories.
Every time your want to sync, you need to run rsync commands. But what if you want to run rsync as a daemon? Every change in the source will be synced to destination location manually?
Below is a small script to do this
On source location
archival@cme103:~$ mkdir rsync-as-daemon ;cd rsync-as-daemon
archival@cme103:~$touch /home/archival/rsync-as-daemon/rsync.lock;touch /home/archival/rsync-as-daemon/rsync.log
archival@cme103:~$ cat rsyncd.conf
pid file = /home/archival/rsync-as-daemon/rsyncd.pid
lock file = /home/archival/rsync-as-daemon/rsync.lock
log file = /home/archival/rsync-as-daemon/rsync.log
use chroot = false
port = 15000
reverse lookup = no
[app_logs]
path = /home/archival/log/
comment = Logs Rsync
read only = true
timeout = 300
Now run rsync as a daemon
archival@cme103:~$ rsync --daemon --config=/home/archival/rsync-as-daemon/rsyncd.conf
On Destination Please configure as below
logmanager@ip-10-101-2-145:~ mkdir rsync-client;cd rsync-client logmanager@ip-10-101-2-145:~ cat rsync_client.sh #!/bin/bash SCRIPT_DIR=$(dirname $0) cd $SCRIPT_DIR TARGET_BASE_DIR="/opt/rsync_logs/" RSYNC_INCLUDES="$SCRIPT_DIR/rsync_includes.cfg" while true ; do SERVER_URL=($(cat "$SCRIPT_DIR/rsync_url.list" | xargs)) for URL in "${SERVER_URL[@]}" do IP=$(echo $URL | cut -d':' -f 1) TARGET_DIR="$TARGET_BASE_DIR/$IP" if [ ! -f $TARGET_DIR ]; then mkdir -p $TARGET_DIR fi rsync -rtm --append --include-from $RSYNC_INCLUDES --exclude '*' rsync://${URL} ${TARGET_DIR} done done logmanager@ip-10-101-2-145:~/rsync-client$ cat rsync_includes.cfg ### Directories and file that should be synced */ platform*.log logmanager@ip-10-101-2-145:~/ rsync-client$ cat rsync_url.list ## URL for Rsync 192.168.201.103:15000/app_logs/
Now run rsync client
logmanager@ip-10-101-2-145:~/rsync-client$/home/logmanager/rsync-client/rsync_client.sh
No comments:
Post a Comment