Write a Python script for a backup file
#!/usr/bin/env python#-*- coding:utf-8 -*-import osimport zipfileimport timestart_dir = '/home/dragon/python/' #需要压缩的文件或目录路径List_1 = ['. Git ', '. SVN ', ' temp '] #不需要备份的目录target_zip = '/home/dragon/' # ZIP file storage location times = time.strftime ('%y%m%d%h%m%s ') #显示时间zip_name = '%sbackup_% S.zip '% (target_zip,times) f = zipfile. ZipFile (Zip_name, ' W ', ZipFile. zip_deflated) For root, dirs, files in os.walk (start_dir): a= root.split ('/') if a[4] in List_1: #不压缩的目录 continue else: for filename in files: # All files under the root of the currently traversed directory         &NBsp; f.write (Os.path.join (root,filename)) #print dirs #当前遍历到的目录的根下的所有目录 #print files #当前遍历到的目录的根下的所有文件f. Close () #关闭zip文件
This article is from the "obsessed" blog, make sure to keep this source http://dragondragon.blog.51cto.com/6170889/1754726
Write a Python script for a backup file