Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: Getting rsync to work with cron

  1. #1
    Join Date
    Nov 2007
    Beans
    20

    Unhappy Getting rsync to work with cron

    Trying to build a very simple file server. As I learn the basics I will fancy it up a little more. So this is what I have done.

    I created a folder: /ppp <-- Works
    I changed the permissions on the folder to 0777 <---Works
    I run the following line in terminal: rsync -r -v -z -t /ppp <my username>@<my ip>::ibackup <--- Works. THIS CREATES A BACKUP
    I created a shell script called daily.sh in the /ibackup folder with a single line: rsync -r -v -z -t /ppp <my username>@<my ip>::ibackup <--- Works
    While in the /ibackup folder I run: sudo ./daily.sh <--- Works. THIS CREATES A BACKUP

    This is where things start to not work.

    I edit /etc/crontab and add the following line:
    15 10 * * * /ibackup/daily.sh

    I check /var/log/syslog and I see this line:
    Aug 22 10:15:01 unbuntu cron[839]: (*system*) RELOAD (/etc/crontab) <-- NOTHING BACKUP UP

    So then I edit /etc/crontab and add the following line (adding . before /ibackup):
    29 10 * * * ./ibackup/daily.sh

    I check /var/log/syslog and I see this line:
    Aug 22 10:29:01 unbuntu CRON[24599]: (root) CMD ( ./ibackup/daily.sh)
    Aug 22 10:29:01 unbuntu CRON[24599]: (CRON) info (No MTA installed, discarding output) <-- NOTHING BACKUP UP

    So then I edit /etc/crontab and add the following line:
    43 10 * * * ./ibackup/daily.sh >/dev/null 2>&1

    I check /var/log/syslog and I see this line:
    Aug 22 10:29:01 unbuntu CRON[24610]: (root) CMD ( ./ibackup/daily.sh >/dev/null 2>&1) <-- NOTHING BACKUP UP

    So then I edit /etc/crontab and add the following line (removing space between sh and >/dev):
    43 10 * * * ./ibackup/daily.sh>/dev/null 2>&1

    I check /var/log/syslog and I see this line:
    Aug 22 10:29:01 unbuntu CRON[24610]: (root) CMD ( ./ibackup/daily.sh>/dev/null 2>&1) <-- NOTHING BACKUP UP

    Not sure what to do at this point.

    Thanks in advance for any help.

  2. #2
    Join Date
    Apr 2008
    Location
    LOCATION=/dev/random
    Beans
    5,767
    Distro
    Ubuntu Development Release

    Re: Getting rsync to work with cron

    Edit your /ibackup/daily.sh script so it looks like this...
    Code:
    #!/bin/sh
    /usr/bin/rsync -r -v -z -t /ppp <my username>@<my ip>::ibackup
    Then change your crontab back to your first attempt...
    Code:
    15 10 * * * /ibackup/daily.sh
    You need the shebang (#!) line at the start of your script to specify what sort of script it is (in this case it's a shell script).

    Also crontab doesn't have the same environment set up as a normal user so it might not know where rsync is, so use the full path.
    Cheesemill

  3. #3
    Join Date
    Nov 2007
    Beans
    20

    Re: Getting rsync to work with cron

    I made the changes and checked /var/log/syslog and I see this:
    Aug 22 12:35:01 unbuntu cron[839]: (*system*) RELOAD (/etc/crontab)
    Aug 22 12:35:01 unbuntu CRON[24670]: (root) CMD ( /ibackup/daily.sh)
    Aug 22 12:35:12 unbuntu CRON[24669]: (CRON) info (No MTA installed, discarding output) <-- NOTHING BACKUP UP

  4. #4
    Join Date
    Jul 2013
    Location
    Wisconsin
    Beans
    1,199

    Re: Getting rsync to work with cron

    Cron is working. There is a problem in your script.

    The "No MTA installed" line means that your job has output -like the error message-, and cron tried to e-mail you that output. Since you don't have an MTA installed to handle the e-mail from cron, the system discards the undeliverable mail.

    You don't need -v (verbose flag) in a cron job unless you are saving the output to a file, or getting it mailed to you.

    If you are backing up to another machine, make sure the cron environment (which is different from your login environment) has access to the appropriate ssh key.

    You can install an MTA to read the error messages. That's handy for servers. It stinks when you go through the trouble of installing an MTA, configuring cron to send to the right e-mail address...and then the message isn't helpful.

    For troubleshooting, I recommend redirecting your script output to a file instead of STDOUT or STDERR. You can do this through cron, or simply put in debugging lines within your script.

  5. #5
    Join Date
    Nov 2007
    Beans
    20

    Re: Getting rsync to work with cron

    If I type this line into terminal it works:

    /usr/bin/rsync -r -v -z -t /ppp <my username>@<my ip>::ibackup

    The files get backed up to ibackup everytime. It works perfect.

    My script is called daily.sh and looks like this:
    #!/bin/sh
    /usr/bin/rsync -r -v -z -t /ppp <my username>@<my ip>::ibackup

    If I manually run this script the files get backed up to ibackup everytime. It works perfect. All I want to do to automate the process.

    I have added the script to /etc/cron.hourly. It does not backup.

    I have added the following line to /etc/crontab:

    15 10 * * * /ibackup/daily.sh

    It does not backup.

    Summerize:
    Type line in terminal = works
    Manually run script = works
    Add to cron = no worky

  6. #6
    Join Date
    Nov 2008
    Location
    Metro Boston
    Beans
    8,544
    Distro
    Kubuntu 14.04 Trusty Tahr

    Re: Getting rsync to work with cron

    Take a look in /var/log/syslog and see what errors cron reports.
    If you ask for help, please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

  7. #7
    Join Date
    Feb 2009
    Location
    Dallas, TX
    Beans
    6,593
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Getting rsync to work with cron

    Hi rgfrancis.

    A few thoughts:
    • Call your script from cron using an absolute path, for instance, /home/youruser/ibackup/daily.sh (if it's in your home).
    • Also use absolute paths for your source and destination on your script.
    • Instead of using the verbose option and redirecting rsync output, use the --log-file option instead, e.g.:
      Code:
      rsync -a --log-file=/path/to/rsync.log /path/to/source/  /path/to/destination/
    • Note that if nothing changes, subsequents runs of rsync would do, well, nothing (because there's nothing to sync).
    • If you need to run 'sudo rsync...' in order for the script to run properly, then you need to create a crontab entry for root by running:
      Code:
      sudo crontab -e

    Hope it helps. Let us know how it goes.
    Regards.

  8. #8
    Join Date
    Nov 2007
    Beans
    20

    Re: Getting rsync to work with cron

    I restarted the cron daemon

    I added the following to the end of my line in crontab:

    /ibackup/cron.log 2>&1

    I then reviewed the log and got this:

    Password: rsync: connection unexpectedly closed (o bytes received so far) [sender]
    rsync error: error in rsync protocol data stream (code 12) as io.c(605) [sender=3.0.9]

  9. #9
    Join Date
    Nov 2007
    Beans
    20

    Re: Getting rsync to work with cron

    Confused about the crontab -e. If I type that in terminal it brings up a /tmp/crontab.03oj7y/crontab and doesn't have any of the modifications I have made to the /etc/crontab. How does that work?

    I am running the script using the absolute path. It is located in a folder called ibackup in the root. Am I missing something there?

    Thanks

  10. #10
    Join Date
    Feb 2009
    Location
    Dallas, TX
    Beans
    6,593
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Getting rsync to work with cron

    Quote Originally Posted by rgfrancis View Post
    I run the following line in terminal: rsync -r -v -z -t /ppp <my username>@<my ip>::ibackup
    In this example, the directory ibackup is not referenced using an absolute path. Is that the current command on your script?
    Quote Originally Posted by rgfrancis View Post
    Confused about the crontab -e
    If all this time you were editing /etc/crontab then you are missing the user field. Having said that, I would leave /etc/crontab 'as is' and creating a separate user crontabs. That could be personal user crontab by running:
    Code:
    crontab -e
    or for root by running:
    Code:
    sudo crontab -e
    Regards.

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •