Required Installation:
1.Python
2.7z Decompression Software
backup_2.py
Copy the 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 ')