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
LinuxLinux Networking

Avatar of undefined
Last Comment
wesly_chen
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.
Avatar of farzanj
farzanj
Flag of Canada image

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

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.
Avatar of wesly_chen
wesly_chen
Flag of United States of America image

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
Peterson50
Flag of United States of America image

ASKER

Thanks,

When you say crontab -e, the rsync is part of that line, ie crontab -e 01 rsync /usr/bin.......... ?
Avatar of wesly_chen
wesly_chen
Flag of United States of America image

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.
Avatar of Peterson50
Peterson50
Flag of United States of America image

ASKER

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

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of wesly_chen
wesly_chen
Flag of United States of America image

Sorry for the typo (actual copy and paste wrong)
Thanks fanzanj for the explanation.
Avatar of Peterson50
Peterson50
Flag of United States of America image

ASKER

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

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
Avatar of wesly_chen
wesly_chen
Flag of United States of America image

> 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.
Avatar of Peterson50
Peterson50
Flag of United States of America image

ASKER

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
Avatar of wesly_chen
wesly_chen
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of wesly_chen
wesly_chen
Flag of United States of America image

> 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".
Avatar of Peterson50
Peterson50
Flag of United States of America image

ASKER

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
Avatar of wesly_chen
wesly_chen
Flag of United States of America image

> 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
Avatar of Peterson50
Peterson50
Flag of United States of America image

ASKER

I really appreciate this, each separate backup is for a different time just put the * * * * * in front of each line?
Avatar of wesly_chen
wesly_chen
Flag of United States of America image

> 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
Avatar of Peterson50
Peterson50
Flag of United States of America image

ASKER

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
Avatar of wesly_chen
wesly_chen
Flag of United States of America image

> 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.

Linux
Linux

Linux is a UNIX-like open source operating system with hundreds of distinct distributions, including: Fedora, openSUSE, Ubuntu, Debian, Slackware, Gentoo, CentOS, and Arch Linux. Linux is generally associated with web and database servers, but has become popular in many niche industries and applications.

71K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo