Python file backup

Source: Internet
Author: User
# 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.