/etc/cron.daily scripts not running on Ubuntu
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()
I've disabled comments for now due to spam problems - I'll turn them back on when I've fixed it!