Python uses 7z decompression software to back up files script share _python

Source: Internet
Author: User

Installation Required:

1.Python
2.7z Decompression Software

backup_2.py

Copy Code code as follows:

# Filename:backup_2.py

"Backup files."
Version:v2, based on Python 3.3
Usage:backup.py-s: "dir1|dir2| ..."-T: "Target_dir" [-C: "Comment"]
-s:the source directories.
-t:the target directory.
-c:optional, any comment.
Examples:
Backup.py-s: "C:\\src\\f1|c:\\src\\f2|c:\\src\\f 3"-T: "C:\\backup"
Backup.py-s: "C:\\src\\f 3"-T: "C:\\backup"-C: "For Sample" "

Import OS
Import Sys
Import time

# Read SYS.ARGV
Print (SYS.ARGV)
If Len (SYS.ARGV) < 2:
Print (__doc__)
Sys.exit ()

Source=[]
Target_dir= '
Comment= '
For Arg in SYS.ARGV:
If Arg.startswith (' s: '):
Source=arg[3:].split (' | ')
Print (source)
Elif Arg.startswith ('-t: '):
Target_dir=arg[3:]+os.sep
Print (Target_dir)
Elif Arg.startswith ('-C: '):
Comment=arg[3:]
Print (comment)

For I in range (0, Len (source)):
Source[i] = "\" "+ source[i] +" \ "
Print (Source[i])

# make the ' file name with the ' time ' and comment
Today=target_dir+time.strftime ('%y%m%d ')
Now=time.strftime ('%h%m%s ')

If Len (comment) ==0: # Check if a comment was entered
target=today+os.sep+now+ '. 7z '
Else
target=today+os.sep+now+ ' _ ' +\
Comment.replace (', ' _ ') + '. 7z '

# Create the subdirectory by day
If not os.path.exists (today):
Os.mkdir (today) # Make Directory
Print (' Successfully created directory ', today)

# Zip command
Zip_command= "7z a%s%s"% (target, '. Join (source))
Print (Zip_command)

# Run The Backup
If Os.system (Zip_command) ==0:
Print (' Successful backup to ', target)
Else
Print (' Backup FAILED ')

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.