1

I want to use rsync to synchronise my home folder with a "backup" copy on another drive on an Ubuntu 11.10 machine. And I want it to happen every 15 minutes.

If I manually run:

rsync -ar --delete /home/user/ /backupdrive/

in the CLI, it works just fine - everything in in sync.

But I've added:

*/15 * * * * rsync -ar --delete /home/user/ /backupdrive/

to sudo crontab -e and whilst it adds new files, it doesn't delete the old ones.

Any ideas?

Edit

The first three lines of the cron out.txt are:

sending incremental file list
./
IO error encountered -- skipping file deletion

This doesn't happen with the CLI version.

4
  • 2
    Try running the same command after adding -v option and redirect the output to a file. Then, check the file.
    – Khaled
    Apr 18, 2012 at 11:56
  • Okay, so I added '> out.txt' in both cases. For the CLI version it's clearly adding and deleting files. On the crontab version, I can't find the out.txt file anywhere in the filesystem!!! But it is adding files - just not deleting them...?!?
    – user114671
    Apr 18, 2012 at 15:03
  • @user114671 you need to specify an absolute path to out.txt. So > /tmp/out.txt for example. Otherwise its going to put out.txt in whatever directory cron is running from.
    – phemmer
    Apr 19, 2012 at 1:31
  • Thanks Patrick, completely forgot that. I'll edit the entry above to show the output...
    – user114671
    Apr 19, 2012 at 7:38

1 Answer 1

0

If you're using SSH authentication in your interactive shell implicitly for rsync, you'll need to set that up explicitly for use in cron. This can be tricky to lock down with SSH keys that need to work without passphrases, since ideally one would want to constrain where the rsync output can end up the far end.

You can use the ~/.ssh/authorized_keys file to configure the key to only run a given specific command when someone connects to the host. If rsync in daemon mode can be forced to put everything under a target directory specified in the /.ssh/authorized_keys file "command" entry, it'd even be fairly secure. The rsyncd.conf(5) page has some relevant options for this kind of thing.

1
  • Thanks Alex. My apologies for not being clearer - both /home/user and /backupdrive are on the same machine
    – user114671
    Apr 18, 2012 at 12:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .