Python Backup program code implementation example

Source: Internet
Author: User
A backup program for Python

This is a backup script. Please change the path yourself.

This is a backup script, according to the current date of the directory, the time as the file name, and can be added to the file name Note information.

Zip as a compression method, there are special needs can be changed.

Instance code:


#! /usr/bin/python#coding=utf-8 #这是一个备份脚本, according to the current date of the directory, the time as the file name, and you can add notes information in the file name. #以zip方式作为压缩方式, there are special needs that can be changed. Import Osimport Time Source = ['/home/leeicoding/workspace/j2ee ', '/home/leeicoding/workspace/python '] target_dir = '/home/leeicoding /bak ' #获取系统时间today = target_dir + time.strftime ('%y%m%d ') now  = Time.strftime ('%h%m%s ') # Enter Comment comment = raw_input ('  Please enter remark: ') if len (comment) = = 0:  print (' no Notes ')  target = today + Os.sep + now + '. Zip ' else  : target = today + OS.SEP + Now + comment.replace (", ' _ ') + '. zip ' if not os.path.exists (today):  Os.mkdir (today)  print (' Create directory ' +today+ ' success '  # Backup Command # Q silent mode r recursive directory Zip_command = ' zip-qr '%s '%s '% (target, '. Join (source) ') if Os.system (zip_command) = = 0:
 
  print (' Backup succeeded, stored in: ' +target)
 


Thank you for reading, hope to help everyone, thank you for the support of this site!

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.