[mythtv-users] Why is my cron job not backing up my database?

Michael T. Dean mtdean at thirdcontact.com
Thu May 10 14:51:53 UTC 2012


On 05/10/2012 12:47 AM, Igor Cicimov wrote:
> On Thu, May 10, 2012 at 2:05 PM, Gabe Rubin<gaberubin at gmail.com>  wrote:
>
>>
>> On May 9, 2012, at 8:48 PM, "Michael T. Dean"<mtdean at thirdcontact.com>
>> wrote:
>>
>>> On 05/09/2012 11:43 PM, Bill Meek wrote:
>>>> On 05/09/2012 10:33 PM, Gabe Rubin wrote:
>>>> ...
>>>>> [mythtv at localhost backup]$ more /home/mythtv/.mythtv/backuprc
>>>>> DBBackupDirectory=/home/mythtv/.mythtv/backup
>>>>>
>>>>> And the command works from the command line.  It just seems that none
>>>>> of my cronjobs are functioning.
>>>> But isn't your cron job running as root? If so, there
>>>> should be a similar entry in ~root/.mythtv.
>>>>
>>>> At least that would explain why cron fails and command line works.
>>>>
>> This is my mythtv cron job.  What I pasted in my first email was from
>> running crontab -e as the mythtv user.
>>
>>> And/or you need to specify a value for HOME to point to /home/mythtv
>>>
>>> (without a valid HOME, nearly all things MythTV will fail--including
>>> optimize_mythdb.pl and mythconverg_backup.pl)
>> I am not sure I understand what this means. And does it change anything
>> that the cron job is running as mythtv?
> It's a shell thing. So have in mind that when you run the cronjob it runs
> without shell so it doesn't inherit your environment settings which
> explains why it is successful from the shell command line and fails from
> cron.
>
> You need to source your /home/mythtv/.mythtv/backuprc file first. So try
> putting the cron like this:
>
> 30 3 * * * . /home/mythtv/.mythtv/backuprc&&  /usr/bin/mythconverg_backup.pl
>                 ^
> (yes, that's a dot then a space then the rest of the line here)
>

Actually, the backup/restore scripts don't use environment variables for 
determining the information, so sourcing the backuprc won't help.  Also, 
the backuprc only contains a small amount of information that's used 
along with $HOME/.mythtv/config.xml to figure out how to back up the 
database.

Some cron implementations will set a HOME (based on the /etc/password 
HOME for the user executing the crontab), but it's still worth verifying 
it's set.

So, you could just try setting HOME inside the crontab:

export HOME=/home/mythtv

and see if it changes (and/or use one of the approaches suggested by 
others to log the environment/results of the run).

Mike


More information about the mythtv-users mailing list