#!/usr/bin/python import glob import os import os.path import shlex import statvfs import subprocess import sys def ExecBackup(source, target, skipit): try: if skipit == True: print "Skipped " + source else: if not os.path.exists(target): os.makedirs(target) if os.path.exists(source): procName = 'rsync -lrt --delete "' + source + '" "' + target + '"' myarg = shlex.split (procName) myarg = myarg[:-1] + glob.glob(myarg[-1]) p = subprocess.Popen(myarg) p.communicate() print "Synced " + source else: print "Invalid source path: " + source except Exception as ex: print 'Call to ' + procName + ' failed: ' + str(ex) ### Main() starts here ### # NOTE: The newTarget setting and ExecBackup calls are examples. Modify to suit your needs. # Target folder for synchronized copies. newTarget = '/media/HD2/fullsync' # Each call to ExecBackup synchronizes a single directory and all of its subdirectories ExecBackup('/home/jdoe/Documents',newTarget,False) ExecBackup('/home/jdoe/Music',newTarget,False) # Show free space remaining on target drive f = os.statvfs(newTarget) totalSize = (f[statvfs.F_BSIZE] * f[statvfs.F_BFREE]) / 1024/1024/1024 print '\nSpace remaining: ' + str(totalSize) + 'G' print '\nFinished successfully.'