# Filename: backup_ver1.pyimport osimport time #1. the files and directories to be backed up are specified in a list. source = ['/home/anpan/python'] # If you are using Windows, use source = [R 'C: \ documents', r 'd: \ work'] or something like that #2. the backup must be stored in a main backup directorytarget_dir = '. /'# Remember to change this to what you will be using #3. the files are backed up into a zip file. #4. the name of the ZIP archive is the current date and timetarget = target_dir + time. strftime ('% Y % m % d % H % m % s') + '.zip' #5. we use the zip command (in Unix/Linux) to put the files in a zip archivezip_command = "Zip-QR '% s' % s" % (target ,''. join (source) # Run the backupif OS. system (zip_command) = 0: Print 'successful backup to ', targetelse: Print 'backup failed'
Running result: successful backup to./20130824211349.zip