At the very least, you should have a basic linux installation. This how-to assumes you have set up a CentOS 6 x86_64 VPS with 1GB RAM, but it should be applicable to most setups with minimal tweaks. All the commands and changes below should be done as the root user.
Interesting way to backup files from one server to another. This is script is running all the time so you should have a better current backup with this setup.
Install these files on server you want synced.
# yum install lsyncd
Create username on server you want to sync too.
# useradd username
# passwd username (Enter a good password.)
On server that is going to be backed up. Create ssh public keys.
# ssh-keygen -t rsa
# cat /root/.ssh/id_rsa.pub
Copy public key to server that you setup earlier.
# vi ~/.ssh/authorized_keys
Create the main Lsyncd.conf file. Add the information below. Of course you will need to change the ip address (192.168.1.20) to your server ip address. You will also need to change username to the user you created.
#vi /etc/lsyncd.conf
settings {
logfile = "/var/log/lsyncd/lsyncd.log",
statusFile = "/var/log/lsyncd/lsyncd-status.log",
statusInterval = 20
}-- Slave server configuration
sync {
default.rsync,
source="/usr/share/nginx/html/",
target="192.168.1.20:/home/username/html/",
excludeFrom="/etc/lsyncd-excludes.txt",rsync = {
compress = true,
acls = true,
verbose = true,
owner = true,
group = true,
perms = true,
rsh = "/usr/bin/ssh -l username -p 22 -o StrictHostKeyChecking=no"
}
}sync {
default.rsync,
source="/etc/nginx/conf.d/",
target="192.168.1.20:/home/username/nginxconf/",
rsync = {
compress = true,
acls = true,
verbose = true,
owner = true,
group = true,
perms = true,
rsh = "/usr/bin/ssh -l username -p 22 -o StrictHostKeyChecking=no"
}
}
Now add an exclude file and add the two entries below. This should stop the sync of the cache directory and tmp directory.
# vi
/etc/lsyncd-excludes.txt
cache/
tmp/
Make sure there isn't any empty spaces because then you will exclude everything. No new lines at top etc.
References:
http://www.nginxtips.com/lsyncd-live-file-syncronization-linux/