LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 02-27-2013, 07:23 AM   #1
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,133

Rep: Reputation: 45
Rsync and Crontab Setting up


Dear all,
I would like to use rsync for my backups (Actually copying the files to an external hard disk. Keep in mind that this is not a discussion if this is an efficient way of keeping backups but is morely for rsync mechanisms)

I have written a small script that contains the followings

Code:
rsync  -rav /home/ /media/defineIt
rsync -rav /etc/ /media/defineIt
rsync -rav /root /media/defineIt
1. Is the -rav for copying the files from the one folder to the another?

2. The script will run with root permissions... how can I see that the execution failed. Let's say that I have a typo in crontab -e, how can I find out that the script never run?

3. If I want inside the destination folder /media/defineIt/ to have the three subfolders /home, /etc, /root, exactly as the three rsync commands provided above, how should I have the / in the rsync. Should it be as it is
Code:
rsync -rav /root /media/defineIt
or change to
Code:
rsync -rav /root /media/defineIt/
I would like to thank you in advance for your replies

Regards
Alex
 
Old 02-27-2013, 07:53 AM   #2
yowi
Member
 
Registered: Dec 2002
Location: Au
Distribution: Debian
Posts: 209

Rep: Reputation: 52
First I'd suggest you check the man pages for rsync and cron. I say this because -a includes -r, implying you haven't checked the switches.

cron on my system (Debian) logs it's activity to syslog, not sure how Opensuse does things but there will be a log somewhere. If desired your script can use whatever logging or notification mechanism you want. A conditional test and the "mail" command on failure is effective, for example:
Code:
rsync [some params] || mail [message to someone]
And lastly don't believe anything anyone tells you until you've tested it for yourself, which is not at all difficult with shell scripts.
 
Old 02-28-2013, 01:28 AM   #3
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,133

Original Poster
Rep: Reputation: 45
I would like to thank you for your answer.
I would like to ask you about the last / , in the paths, when is needed or not in rsync.

Regards
Alex
 
Old 02-28-2013, 07:21 AM   #4
rng
Member
 
Registered: Aug 2011
Posts: 747

Rep: Reputation: 23
For rsync, it is easiest to use /source/folder/name1/* /target/folder/name2/ , so that it is clear that all files in source folder name1 need to be copied to folder name2.

Also -r is included in -a. So using -av is enough.

Last edited by rng; 02-28-2013 at 07:22 AM.
 
Old 02-28-2013, 07:22 AM   #5
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora
Posts: 2,523

Rep: Reputation: 448Reputation: 448Reputation: 448Reputation: 448Reputation: 448
yes you will need the trailing / on the destination and source.

Code:
rsync -aviS /path/to/source/ /path/to/destination/
 
Old 02-28-2013, 10:26 AM   #6
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,133

Original Poster
Rep: Reputation: 45
Thanks and
what happens when trailing / is missing?

as

rsync -aviS /path/to/source /path/to/destination
 
Old 02-28-2013, 10:51 AM   #7
suicidaleggroll
Senior Member
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 2,749

Rep: Reputation: 977Reputation: 977Reputation: 977Reputation: 977Reputation: 977Reputation: 977Reputation: 977Reputation: 977
Quote:
Originally Posted by alaios View Post
Thanks and
what happens when trailing / is missing?

as

rsync -aviS /path/to/source /path/to/destination
Why don't you try it and see? Make two dummy directories, try various combinations of trailing slashes, and see what happens.


IIRC:
rsync -a /path/to/source /path/to/dest
will copy the folder source into dest (so you'll now have /path/to/dest/source)

rsync -a /path/to/source/ /path/to/dest
will copy the contents of source into dest

rsync -a /path/to/source /path/to/dest/
will copy the folder source into dest (so you'll now have /path/to/dest/source)

rsync -a /path/to/source/ /path/to/dest/
will copy the contents of source into dest

So basically, the only trailing slash that matters is the one on the source directory. That tells rsync whether it should copy the source folder itself into dest, or the contents of source into dest.


But, the only way to know for sure is to try it and see what happens.

Last edited by suicidaleggroll; 02-28-2013 at 10:59 AM.
 
1 members found this post helpful.
Old 02-28-2013, 07:57 PM   #8
rng
Member
 
Registered: Aug 2011
Posts: 747

Rep: Reputation: 23
On my debian-wheezy system, I get following error if /* is not used:
Code:
$ rsync ./tmp2/ ./tmp3
skipping directory .
and the file from tmp2 is not copied to tmp3
Code:
$ rsync -v ./tmp2/* ./tmp3
file1

sent 65 bytes  received 31 bytes  192.00 bytes/sec
total size is 0  speedup is 0.00
The file in tmp2 is copied properly.
 
Old 02-28-2013, 08:16 PM   #9
suicidaleggroll
Senior Member
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 2,749

Rep: Reputation: 977Reputation: 977Reputation: 977Reputation: 977Reputation: 977Reputation: 977Reputation: 977Reputation: 977
Quote:
Originally Posted by rng View Post
On my debian-wheezy system, I get following error if /* is not used:
Code:
$ rsync ./tmp2/ ./tmp3
skipping directory .
and the file from tmp2 is not copied to tmp3
Code:
$ rsync -v ./tmp2/* ./tmp3
file1

sent 65 bytes  received 31 bytes  192.00 bytes/sec
total size is 0  speedup is 0.00
The file in tmp2 is copied properly.
It's because you didn't set the recursive flag.
 
Old 02-28-2013, 08:33 PM   #10
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 3,409

Rep: Reputation: 835Reputation: 835Reputation: 835Reputation: 835Reputation: 835Reputation: 835Reputation: 835
If you are going to use rsync in a script to be run as a cron job, I suggest that you:
- specify the full path to rsync so that the rsync binary can be found (the path in the shell started to execute the cron job may not include the path to rsync)
- use the options '-aq' to rsync otherwise you will get very long emails if you are backing up lots of files.
e.g.
Code:
/usr/bin/rsync -aq /path/to/sourcefiles/ /path/to/destinationfiles
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
notifications for rsync's done via crontab rjo98 Linux - Server 10 01-19-2012 03:24 AM
[SOLVED] rsync execution issue with crontab - Have given full path to rsync too!! Prabagaran Linux - Server 6 04-15-2011 01:39 AM
rsync's in crontab not running, not sure why rjo98 Linux - Newbie 47 07-17-2009 08:00 AM
Rsync and Crontab not playing well together phillc Linux - Newbie 9 11-08-2007 10:22 AM
rsync in crontab loonykroons Linux - Software 3 11-28-2006 03:08 AM


All times are GMT -5. The time now is 02:06 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration