The first backup script in a concise Python tutorial

Source: Internet
Author: User

The first time to learn python written script 650) this.width=650; "src=" Http://img.baidu.com/hi/tsj/t_0015.gif "alt=" T_0015.gif "/>

The original script of the first script in the concise Python tutorial is as follows


#!/usr/bin/python# filename: backup_ver1.pyimport osimport time# 1. the  Files and directories to be backed up are specified in a  list.source = ['/home/swaroop/byte ',  '/home/swaroop/bin ']# 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 =  '/mnt/e/backup/'  # 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 '

Because the original script is under Linux, the individual modifies the script under Windows

#coding =utf-8import osimport timeimport sysreload (SYS) sys.setdefaultencoding (' GBK ') Source = ' f:\\movie\\ text effect \ \ ' Target_dir = ' f:\\backup\\ ' target = target_dir + time.strftime ('%y%m%d%h%m%s ') + '. zip ' Un_source = Unicode (source, ' UTF8 ') ) Zip_command = "7z a-tzip%s%s-r"% (target,un_source) print zip_commandif os.system (zip_command) = = 0:print ' Succes Sful backup to ', Targetelse:print ' backup FAILED '

The following code is available because the folder path to be backed up exists in Chinese

Import sysreload (SYS) sys.setdefaultencoding (' GBK ')---------------------------------------------Unicode (source, ' UTF8 ')

The packaged compression program uses a 7zip call to

7z a-tzip Packaging to a file needs to be packaged in the directory-R (-R includes subdirectories and sub-directory files)

This article is from the "Canyu's PYTHON" blog, so be sure to keep this source http://canyuexiang.blog.51cto.com/8871379/1556391

The first backup script in a concise Python tutorial

Related Article

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.