Friday, September 27, 2013

[SOLVED] - RSYNC not executing via CRON



The below error was faced and tried for online answers, made my head to heat for couple of days and finally i was able to crack the solution for the below issue.

umasarath@ubuntu:~$ tail -50 cron_alc.log
Cronjob started for back-up files
+ rsync -v umasarath@xx.xx.xx.xx:/tmp/compressed_logfiles/*.zip /home/umasarath/archive/
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
rsync: connection unexpectedly closed (0 bytes received so far) [Receiver]
rsync error: unexplained error (code 255) at io.c(601) [Receiver=3.0.7]

umasarath@ubuntu:~$

Please follow the below steps inorder to avoid the above error.

My script contains the below code.

umasarath@ubuntu:~$ cat transfer_files.sh
#!/bin/sh
set -xv
echo "Cronjob started for back-up files" `date`
/usr/bin/rsync -vv umasarath@xx.xx.xx.xx:/tmp/compressed_logfiles/*.zip /home/umasarath/archive/
echo "Cronjob ended for back-up files from PROD to CI" `date`
The above script contains 2 echo commands and one rsync command. Just wanted to have timestamps before and after rsync command. 

  • Please use the steps to configure SSH keys in source and destination server.
  • Give the full path of the rsync(/usr/bin/rsync) command in the script.
  • Don't give the SOURCE directory with ssh command. Most of the blogs recommended to use the below syntax which didn't work for me.
    /usr/bin/rsync -vv "ssh -i umasarath@xx.xx.xx.xx:/tmp/compressed_logfiles/*.zip" /home/umasarath/archive

Placing my file in cron.


umasarath@ubuntu:~$ crontab -e
# m h  dom mon dow   command
00 00 * * * cd /home/umasarath/autotransfer;/bin/sh transfer_files.sh >>/home/umasarath/autotransfer/log/cron.log 2>&1
umasarath@ubuntu:~$
The above entry in cronjob was to run the transfer_files.sh on every Wednesday at 12AM.

When my script was executed via cron, there is no error message displayed in cron_alc.log and the script ran successfully without any issues.


Please try and explore yourselves. Kindly provide your feedback on this article.



6 comments:

  1. GSCopy Pro v6.0 (RoboCopy Alternative) with Open File Agent
    GSCopyPro is a single command-line tool (CLI) that can copy, replicate and move files from one folder to another. This folder can be on the same machine/ server or another server elsewhere. What makes GSCopyPro stand out from other competitors is the fact it works on 32-bit as well as 64-bit systems and has no restrictions. It can easily be scheduled to run as a scheduled task and fully automated. GSCopyPro also comes with an open file agent which can copy files that are locked/ opened by other processes. This feature is supported in all windows vSCersions from widows XP/ 2003 and later.
    Go To:>> http://www.gurusquad.com/GOPYPRO

    ReplyDelete
    Replies
    1. are you here under a quota system ?

      Delete
  2. Worked like a charm!. Thank you!

    ReplyDelete
  3. I still got this:
    Permission denied (publickey).
    rsync: connection unexpectedly closed (0 bytes received so far) [sender]
    rsync error: unexplained error (code 255) at io.c(226) [sender=3.1.0]

    I can log in using public keys from the command line so I do have access. But I'm using root as the ssh password while I'm not logged as root, can that be the problem?

    ReplyDelete
    Replies
    1. Hey. I'm getting the same error. Did you get a fix?
      Permission denied (publickey).
      rsync: connection unexpectedly closed (0 bytes received so far) [sender]
      rsync error: unexplained error (code 255) at /SourceCache/rsync/rsync-42/rsync/io.c(452) [sender=2.6.9]

      Delete
  4. thank you!! follow your instructions and work fantastic!

    ReplyDelete