Python backup program code implementation example

Source: Internet
Author: User
This article describes how to implement the Python backup program code. For more information, see A Python backup program

This is a backup script. Change the path.

This is a backup script, which is divided into directories based on the current date and uses the time as the file name. you can add remarks to the file name.

Use zip as the compression mode. you can change it if you have special requirements.

Instance code:


#! /Usr/bin/python # coding = UTF-8 # This is a backup script, which divides directories by the current date and uses time as the file name. you can add remarks to the file name. # use zip as the compression mode. you can change it if you have special requirements. import osimport time source = ['/home/leeicoding/workspace/j2ee ', '/home/leeicoding/workspace/Python'] target_dir ='/home/leeicoding/bak' # obtain the system time today = target_dir + time. strftime ('% Y % m % d') now = time. strftime ('% H % M % S') # enter comment = raw_input ('Enter remarks:') if len (comment) = 0: print ('No note') 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 + 'successfully ') # 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 successful, stored in: '+ target)


Thank you for reading this article. I hope it will help you. thank you for your support for this site!

For more articles about Python backup program code implementation examples, refer to PHP!

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.