Using rsync on Suse Linux

Peterson50
Peterson50 used Ask the Experts™
on
I have a few questions regarding rsync on SLES 10.  I have copied a directory using rsync to another remote server rsync *.* root@server:/directory name
My questions are:
Do I always have to put in the full path of the source server starting from its root directory?
What is the easiest way to setup a cron file to schedule this copy and only the changed files now that I have a full copy?
I already provided a key so I am not prompted for the password each time

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Source -- you can give a relative path.  Path relative to your current location.
Copy changed files -- rsync takes care of it-- it does that comparison and copies only the changed files.
From man page

Rsync is a fast and extraordinarily versatile file copying tool. It can copy locally, to/from another host over any remote shell, or to/from a remote rsync daemon. It offers a large number of options that control every aspect of its behavior and permit very flexible specification of the set of files to be copied. It is famous for its delta-transfer algorithm, which reduces the amount of data sent over the network by sending only the differences between the source files and the existing files in the destination. Rsync is widely used for backups and mirroring and as an improved copy command for everyday use
If you use -W option
-W, --whole-file            copy files whole (w/o delta-xfer algorithm)

This is default when source and destination are both local.
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Top Expert 2011

Commented:
crontab -e

0 1 * * * /usr/bin/rsync -azuv -e "ssh -i /path-to-key"  /source-path  root@server:/directory

It will schedule at 1:00AM everyday.

for rysnc
-a : archive
-u : skip files that are newer on the receiver
-z : compress
-v : verbose

Author

Commented:
Thanks,

When you say crontab -e, the rsync is part of that line, ie crontab -e 01 rsync /usr/bin.......... ?
Top Expert 2011

Commented:
On command line
 crontab -e  (Press Enter key, it will call your default editor, which is vi in most case )
Then in vi, you press "i" key to insert and type

1 * * * /usr/bin/rsync -azuv -e "ssh -i /path-to-key"  /source-path  root@server:/directory

Then "ESC" key and ":wq" to save and exit vi.

Author

Commented:
I understand now  btw what do the 3 astericks in front of /usr/bin/rsync stand for?

Thanks I'm finally starting to get the hang of linux
It is supposed to be 5 in total. * mean anything.  Or you could put specific numbers.

         field         allowed values
           -----         --------------
           minute        0-59
           hour          0-23
           day of month  1-31
           month         1-12 (or names, see below)
           day of week   0-7 (0 or 7 is Sun, or use names)
Top Expert 2011

Commented:
Sorry for the typo (actual copy and paste wrong)
Thanks fanzanj for the explanation.

Author

Commented:
Thanks for explanation, with the above what exactly is a recursive copy?  And using the rsync line above will that automatically sync the directories under the directory I am copying?  For example if the foler is called Dbase and it has two folders underneath called template, and data, will the above command actually sync the subdirectories also?

Thanks
Yes, the above command will sync the subdirectories as well and that is what recursive copy means--copy directory and its files then sub-directory and its files and then sub-sub-directory and so on
Top Expert 2011

Commented:
> if the foler is called Dbase
For active Database, rsync will copy everything because most of database files are updated frequently.

-a option for rsync include recursive for the subdirectories.

Author

Commented:
Can I put in multiple lines for multiple rsync jobs?
Also do I need to specify the user who is going to run the job, such as putting root prior to the rsync command
Top Expert 2011
Commented:
> Can I put in multiple lines for multiple rsync jobs?
Yes, if the destination are the same.


0 1 * * * /usr/bin/rsync -azuv -e "ssh -i /path-to-key"  /source1 /source2 /source3  root@server:/directory

If not, then put it into script
--- /root/backup.sh ---
#!/bin/sh

/usr/bin/rsync -azuv -e "ssh -i /path-to-key"  /source1  root@server:/directory1
/usr/bin/rsync -azuv -e "ssh -i /path-to-key"  /source2  root@server:/directory2
/usr/bin/rsync -azuv -e "ssh -i /path-to-key"  /source3  root@server:/directory3
------------
chmod +x /root/backup.sh

As root,
# crontab -e
0 1 * * * /root/backup.sh
Top Expert 2011

Commented:
> do I need to specify the user who is going to run the job, such as putting root prior to the rsync command
No, "ssh -i /path-to-key"  /path-to-key is the ssh_key for "root" user. You have specify "root" for "root@server".

Author

Commented:
In regard to the key, it was copied to the destination server (or perhaps the other way around don't remember), all I know is if I do a rsync ..... root@remote_server  it does not prompt for a password.

Also for the other lines the source directory and the destination directory are different as each job is backing up a different directory to a different directory on the backup server
Top Expert 2011

Commented:
> all I know is if I do a rsync ..... root@remote_server  it does not prompt for a password.
Then you don't need the ssh_key for that account. Change to

--- /root/backup.sh ---
#!/bin/sh

/usr/bin/rsync -azuv -e "ssh"  /source1  root@server:/directory1
/usr/bin/rsync -azuv -e "ssh"  /source2  root@server:/directory2
/usr/bin/rsync -azuv -e "ssh"  /source3  root@server:/directory3

Author

Commented:
I really appreciate this, each separate backup is for a different time just put the * * * * * in front of each line?
Top Expert 2011

Commented:
> for a different time just put the * * * * * in front of each line
You can do that.
But I would recommend you put it into a script so they run sequentially.
Make sure the previous job finish then run the next one.

As I mentioned in
http://www.experts-exchange.com/OS/Linux/Q_27043999.html?cid=1572#35827044
====
1. Create a script file /root/backup.sh (you can change the path)
2. Make it executable
   chmod +x /root/backup.sh
3. Setup cron job

Author

Commented:
I have followed all all of the excellent steps including the script, is there anywhere I can check to see what jobs cron has run and any error messages?

Thanks
Top Expert 2011

Commented:
> anywhere I can check to see what jobs cron has run and any error messages?
grep cron /etc/syslog.conf   ===> tell you where is the cron log

Usually, cron log file is /var/log/cron.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial