Jan 14

/etc/cron.daily scripts not running on Ubuntu

My Subversion backup cron job in /etc/cron.daily wasn't running. Finally I figured out why.

For a while, I've had a problem where a script that I'd dropped into my /etc/cron.daily directory on my Ubuntu Linux box stubbonly refused to run. It was a Python script, called backup-svn.py (guess what it does), and ran absolutely fine when called from the commandline.

I was scratching my head about this again last night, staring at the list of jobs in that directory. Why were all running but that one? There was a #! line at the top of the script, it had executable permissions. However, it was the only script in the directory which had a dot (period) in its filename.

mv backup-svn.py backup-svn

... and then the job starts running.

If anyone knows what the rationale behind not allowing job names, I'd love to know - leave a comment below.

For those interested, here's the script. Feel free to use and customise it. It looks for every repo under /var/repos, backs it up, and packs the lot into a tar.bz2 file to be transferred offsite.

 

#!/usr/bin/python

import os
import subprocess
import tarfile
import bz2
import shutil

REPO_PARENT_DIR = '/var/repos'
BACKUP_LOCATION = '/var/backups'

def backup():
    repos = os.listdir(REPO_PARENT_DIR)
    for repo in repos:
        repo_path = os.path.join(REPO_PARENT_DIR, repo)
        backup_path = BACKUP_LOCATION
        if not os.path.exists(backup_path):
            os.mkdir(backup_path)
        ret = subprocess.call(['svn-hot-backup', repo_path, backup_path])
        if ret:
            raise ValueError, 'Error executing backup, exit code was ' + str(ret)
    repo_backups = [ dirname for dirname in os.listdir(BACKUP_LOCATION)
                     if dirname[:dirname.find('-')] in repos ]
    tarname = os.path.join(BACKUP_LOCATION, 'svn-backup.tar.bz2')
    tar = tarfile.open(tarname, 'w:bz2')
    for repo in repo_backups:
        tar.add(os.path.join(BACKUP_LOCATION, repo), arcname=repo)
    tar.close()
    for repo in repo_backups:
        shutil.rmtree(os.path.join(BACKUP_LOCATION, repo))

if __name__ == '__main__':
    backup()

Comments

1 ugg boots shoes says...

Ugg boots shoes <a href= http://www.uggsmall.com>Ugg boots shoes</a> five finger shoes <a href= http://www.acevibram.com/>five finger shoes</a> Uggs outlet <a href= http://www.uggsmall.com>Uggs outlet</a> cheap ugg boots <a href= http://www.uggsmall.com>cheap ugg boots</a> Ugg on sale <a href= http://www.uggsmall.com>Uggs on sale</a> Uggs australia <a href= http://www.uggsmall.com>Uggs australia</a> ugg bailey button boots <a href= http://www.uggsmall.com/ugg-bailey-button-boots-c-19.html... bailey button boots</a> ugg classic cardy boots <a href= http://www.uggsmall.com/ugg-classic-cardy-boots-c-2.html>ugg classic cardy boots</a> ugg nightfall boots <a href= http://www.uggsmall.com/ugg-nightfall-boots-c-4.html>ugg nightfall boots</a> ugg sundance ii boots <a href= http://www.uggsmall.com/ugg-sundance-ii-boots-c-5.html>ugg sundance ii boots</a> ugg classic mini boots <a href= http://www.uggsmall.com/ugg-classic-mini-boots-c-6.html>ugg classic mini boots</a> ugg kids boots <a href= http://www.uggsmall.com/ugg-kids-boots-c-20.html>ugg kids boots</a>

Posted at 3:46 a.m. on July 31, 2010

This won't be published anywhere, it's just in case I need to contact you.

You can use Markdown in your comments. Be sensible!

Sorry about this, but I don't want spam comments.