#!/bin/env python from ftplib import FTP from os import popen from getpass import getpass from ConfigParser import ConfigParser # Edit these entries to suit your setup backup_file = '/usr/local/backups.txt' ftphost = 'my.ftp.com' ftpuname = 'bubba' ftppass = 'beerbelly' duplicity_command = '/usr/bin/duplicity' p = ConfigParser() p.read(backup_file) backups = {} # keys are ftp filename, values are local directory path for ftpname,localname in p.items('Backups'): ....backups[ftpname] = localname def doublequote(s): ....return '"' + s + '"' ftp = FTP(ftphost) ftp.login(ftpuname,ftppass) l=ftp.nlst() for i in backups.keys(): ....if i not in l: ........print 'Directory "%s" is not on the FTP server.' % i ........print "Creating directory %s on server...\n" % i ........ftp.mkd(i) ftp.quit() print "Starting duplicity synchronization ...\n" gpg_passphrase = getpass("Enter your GPG passphrase: ") gpg_passphrase = 'PASSPHRASE="' + gpg_passphrase + '"' space = ' ' for ftpdir in backups.keys(): ....command = 'FTP_PASSWORD=' + doublequote(ftppass) + space \ ............ + gpg_passphrase + space + duplicity_command + space \ ............ + doublequote(backups[ftpdir]) + space + 'ftp://' \ ............ + ftpuname + '@' + ftphost + '/' + ftpdir ....print "\nStarting backup of directory:\n %s\n" % backups[ftpdir] ....popen(command).read() print "\nDone!"