Link to home
Start Free TrialLog in
Avatar of Peterson50
Peterson50Flag for United States of America

asked on

Using rsync on Suse Linux

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
Avatar of farzanj
farzanj
Flag of Canada image

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.
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
Avatar of Peterson50

ASKER

Thanks,

When you say crontab -e, the rsync is part of that line, ie crontab -e 01 rsync /usr/bin.......... ?
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.
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
ASKER CERTIFIED SOLUTION
Avatar of farzanj
farzanj
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry for the typo (actual copy and paste wrong)
Thanks fanzanj for the explanation.
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
> 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.
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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
> 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".
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
> 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
I really appreciate this, each separate backup is for a different time just put the * * * * * in front of each line?
> 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
https://www.experts-exchange.com/questions/27043999/Using-rsync-on-Suse-Linux.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
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
> 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.