Python, subprocess, dump, gzip and Cron

Aidan aweraw at gmail.com
Tue Jun 10 00:37:53 EDT 2008


Hi,

I'm having a bit of trouble with a python script I wrote, though I'm not 
sure if it's related directly to python, or one of the other software 
packages...

The situation is that I'm trying to create a system backup script that 
creates an image of the system, filters the output though gzip, and then 
uploads the data (via ftp) to a remote site.

The problem is that when I run the script from the command line, it 
works as I expect it, but when it is run by cron I only get a 20 byte 
file where the compressed image should be...  does anyone have any idea 
as to why this might be happening?  Code follows

<code>

#!/usr/bin/python

from subprocess import PIPE, Popen
from ftplib import FTP

host = 'box'

filename = '%s.img.gz' % host
ftp_host = '192.168.1.250'
ftpuser, ftppass = 'admin', 'admin'
dest_dir = '/share/%s' % host

dump = Popen('dump 0uaf - /',shell=True,stdout=PIPE)
gzip = Popen('gzip',shell=True,stdin=dump.stdout,stdout=PIPE)

ftp = FTP(ftp_host)
ftp.login(ftpuser,ftppass)
ftp.cwd(dest_dir)
ftp.storbinary('STOR %s' % filename,gzip.stdout)
ftp.quit()

print "Image '%s' created" % filename

</code>

I appreciate all feedback.  Thanks in advance.



More information about the Python-list mailing list