1

I wrote a simple bash script that makes backups with rdiff-backup on Mac OS X Yosemite. Here it is:

#!/bin/bash

MODIF=`stat -f '%m' backup-data.txt`
NOW=`date +%s`
DIFF=$(($NOW-$MODIF))
BACKTIME=$((3600*8))

# EVERY BACKTIME/3600 HOURS SHOULD BE BACKUP
if (($DIFF < $BACKTIME)) ; then
 echo "Last sync was not a long time ago - ${DIFF} sec. Need ${BACKTIME}."
 exit 0;
fi

echo "${MODIF} ${NOW} start" > backup-data.txt
echo "sync start"

rdiff-backup -v 4 --force --print-statistics --exclude **templates_c** --exclude ***sess_* --exclude **.svn** --exclude ***.log --exclude ***.tpl.php /WebServers /Temp/backup/WebServers >> backup-data.txt
rdiff-backup -v 4 --remove-older-than 2W /Temp/backup/WebServers >> backup-data.txt
rdiff-backup -l /Temp/backup/WebServers >> backup-data.txt


echo "${MODIF} ${NOW} stop" >> backup-data.txt

echo "sync end"

It works great from terminal, but once it's executed with crontab it only shows echo's and not even run rdiff-backup commands.

Dealing with it for two hours - No success (( Turning off all echoes - no success etc Could anyone help? Maybe i missed something...

Crontab line is

* * * * * ./backup-data.sh 2>&1 > /Temp/cron_log.txt;

and cronjob is working

  • the cron PATH is very limited. From your terminal, do `which rdiff-backup`. Then edit your script to include export PATH="/path/to/rdiff-backup:$PATH", or check your `man crontab` to see if your version supports setting a PATH=... at the top your your file. Good luck. – shellter Jun 03 '15 at 18:34
  • That's great! Exactly! The problem solved! ) – Zergey Zodin Jun 03 '15 at 19:21

1 Answers1

0

You should add PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin in crontab.