Write a Python script for a backup file

Source: Internet
Author: User
Tags python script

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

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.