Rsync

Support for security such as Firewalls and securing linux
Post Reply
cgkevrek
Posts: 2
Joined: 2011/11/08 10:00:55
Contact:

Rsync

Post by cgkevrek » 2011/11/08 10:24:09

Hi there!

I am trying to set up two servers to sync one each other with rsync.
One is going to react as a slave server (backup server) running rsync daemon and the other one is going to be the live server where the job is done.

Trying to find information on the net for doing so I ended up with some crucial questions.
1. How can I add rsync to operate in certain intervals (e.g. hourly)? Do i need to use crontab, and if so how am i going to do this? it's a little bit difficult to set up such a job, isn't it? Is there any other way to do the job?
2. In order one server to sync to the other do i need to setup the slave one to run rsync in daemon, right? What about the other one (live server). How rsync is going to operate in this server?
3. Is it possible with rsync to get a full system image from the live server to the backup server?

Thank you all in advance.

I shall be waiting soon for your answer.

Harris G

kwk_sa
Posts: 3
Joined: 2011/11/09 17:01:05
Location: South Africa

Re: Rsync

Post by kwk_sa » 2011/11/09 18:37:23

Hi!

I use rsync for backup purposes - not sure if my method is best practise but it works for me.

1) Cronjob = Scheduled task in Linux. It is actually pretty easy - just need to add the command to the crontab file with your time interval options preceding the command.


#nano /etc/crontab


Place this line at the end of the file. Change "livefolder" to the folder you would like to backup.


0 21 * * * root rsync -arvh -e "ssh -i /path-to-key/the-rsync-key" /livefolder root@192.168.XXX.XXX:/backup_location/


My time parameters are set to 9pm every day ( 0 21 * * * )

My command runs as the root user, not best practice.

Change root@192.168.XXX.XXX/backup_location/ to username@BACKUP_SERVER_IPADDRESS:/backup_location/
Not best practise to use root for this, but you must setup a user with valid permissions so I test with root then setup a production user for live use.

-e "ssh -i /path-to-key/the-rsync-key" -> This is so that if you have setup ssh keys so that no password is required to ssh between the machines. You can get info on this from
here

2) Rsync is configured as a master and slave by default as I understand. Just need to be sure it is installed and running on both machines.


yum list rsync*


Should how rsync as installed other run to install


#yum install rsync*


Could be wrong - but I havent had to change any rsync settings before. Other thing to make sure is that both machines firewalls will allow connections on port 22.

3) Very difficult to achieve a full system backup. I personally backup data (files/databases/etc) and then keep records of the configs. That way if the machine crashes, you are forced to review the config :lol:
There are ways though, but I dont think you would achieve it easily using rsync directly...

Hope that helps a bit...

:-D

pschaff
Retired Moderator
Posts: 18276
Joined: 2006/12/13 20:15:34
Location: Tidewater, Virginia, North America
Contact:

Rsync

Post by pschaff » 2011/11/10 22:36:26

Welcome to the CentOS fora. Please see the recommended reading for new users linked in my signature.

[quote]
cgkevrek wrote:
Hi there!

I am trying to set up two servers to sync one each other with rsync.
One is going to react as a slave server (backup server) running rsync daemon and the other one is going to be the live server where the job is done.

Trying to find information on the net for doing so I ended up with some crucial questions.
1. How can I add rsync to operate in certain intervals (e.g. hourly)? Do i need to use crontab, and if so how am i going to do this? it's a little bit difficult to set up such a job, isn't it? Is there any other way to do the job?[/quote]
There's [b]always[/b] another way :-) but I'd go with cron.
[code]man cron
man -a crontab[/code]

[quote]
2. In order one server to sync to the other do i need to setup the slave one to run rsync in daemon, right? What about the other one (live server). How rsync is going to operate in this server?[/quote]
It is not necessary to set up an rsync daemon as a service. Note that to run rsync over ssh via cron you must use an empty passphrase - not necessarily a great idea, but may be OK on a LAN.

[quote]
3. Is it possible with rsync to get a full system image from the live server to the backup server?[/quote]
No. Reliable full system backup must be done off-line. See [url=https://www.centos.org/modules/newbb/viewtopic.php?topic_id=34071&forum=37&post_id=146572#forumpost146572]this thread[/url] for some more discussion.

gulikoza
Posts: 188
Joined: 2007/05/06 20:15:23

Re: Rsync

Post by gulikoza » 2011/11/11 06:01:48

If you're looking for some sort of HA (high availability) setup I suggest to take a look at DRBD as well. I had 2 servers doing rsync in the times of Centos4. Although it worked ok (and really needed it 1 or 2 times!) there's always the question of how old the slave data is and syncing it back after the slave has been used. The rsync process itself can put strain on the servers, using precious i/o and cpu resources.
Last year after upgrading the servers, we switched to DRBD. Now I know that data is always up-to-date on the slave, there is no more manual syncing and DRBD verify is done once a week during night hours.
The only tricky thing is making sure DRBD starts up after reboot. I found that existing HA solutions were too compicated for my case (I don't need automatic switchover and heartbeat, I'll know when the server is down and act accordingly) so I wrote my own "failover" scripts :-D

Post Reply