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:
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 Code:
rsync -rav /root /media/defineIt/ Regards Alex |
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] |
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 |
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. |
yes you will need the trailing / on the destination and source.
Code:
rsync -aviS /path/to/source/ /path/to/destination/ |
Thanks and
what happens when trailing / is missing? as rsync -aviS /path/to/source /path/to/destination |
Quote:
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. |
On my debian-wheezy system, I get following error if /* is not used:
Code:
$ rsync ./tmp2/ ./tmp3 Code:
$ rsync -v ./tmp2/* ./tmp3 |
Quote:
|
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 |
All times are GMT -5. The time now is 01:30 PM. |