Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

cron rsync , how to redirect to a file on desktop

I would like a regular backup of files on my disk to a backup server. Since I have lots of files (millions) I want to use rsync so only the differences are sent.

from Ubuntu 18.04 terminal, this produces output to a file:

rsync -av  /Disk2/ 192.168.1.80:/mnt/jjg-z2/39x-disk2/ &> /home/john/Desktop/nightly_disk2_logs.txt

But when I use crontab -e, for the 16 minute mark of the hour (to test)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

16 * * * * rsync -av  /Disk2/ 192.168.1.80:/mnt/jjg-z2/39x-disk2/ &> /home/john/Desktop

I did not see the output in this file on my desktop.
In the comments, steeldriver suggested the fix to problem 1. The crontab -e now looks like:

SHELL=/bin/bash
52 * * * * rsync -av  /Disk2/ 192.168.1.80:/mnt/jjg-14TB-z2/3970x-disk2/ &> /home/john/Desktop/nightly_disk2_logs.txt

Problem 2: Now I have output in the file but rsync has permissions issues. Is crontab’s environment with respect to SSH keys not the same as the terminal’s environment? Here is the output in the file:

Permission denied, please try again.
Permission denied, please try again.
john@192.168.1.80: Permission denied (publickey,password).
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(235) [sender=3.1.2]

>Solution :

youtube describes the process.

My key takeaways:

  • no passphrase on ssh keys
  • add SHELL=/bin/bash as the first line of crontab -e
  • &> /home/john/Desktop/backup_disk2_logs.txt to create a log file too look at

My crontab -e looks like :

SHELL=/bin/bash
00 * * * * rsync -av  /Disk2/ 192.168.1.80:/mnt/jjg-z2/disk2/ &> /home/john/Desktop/disk2_logs.txt
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading