First, feasibility analysis:
Generally from the economic, technical, social, human four direction analysis.
Second, demand analysis:
Requirements analysis is what needs to be implemented, and this is clear-file backup
Several questions:
Where is our backup?
What time is the backup?
What files are backed up?
How do I store backups (file types)?
What is the name of the backup file? (Need to be plain, usually named at the current time)
Third, the implementation process:
Programme one:
#!/usr/lib/env python
Import OS
Import time
backlist=['/etc ', '/root ']
To= '/mnt/'
Target=to+time.strftime ('%y%m%d%h%m%s ') + '. tar.gz '
Gz_command= "Tar-czf%s%s"% (target, '. Join (backlist))
If Os.system (Gz_command) ==0:
print ' successfull '
Else
print ' failed '
Improvement Programme II:
Scenario two focuses on the multi-build date subdirectory, which is more clear
Today = Target_dir + time.strftime ('%y%m%d ')
now = Time.strftime ('%h%m%s ')
If not os.path.exists (today):
Os.mkdir (today) # Make Directory
print ' Successfully created directory ', today
target = today + Os.sep + now + '. Zip '
Zip_command = "Zip-qr '%s '%s"% (target, ". Join (source))
Note: OS.SEP representative/or \
Improvement Scenario Three: You can add annotations to the backup file name:
#!/usr/bin/env python
Import OS
Import time
source=['/var/log ', '/etc/ssh ']
target= '/mnt/'
Today=target+time.strftime ('%y%m%d ')
Now=time.strftime ('%h%m%s ')
Comment=raw_input (' pls input the comment--> ')
If Len (comment) ==0:
target1=today+os.sep+now+ '. tar.gz '
Else
target1=today+os.sep+now+ ' _ ' +comment.replace (', ' _ ') + '. tar.gz '
If not os.path.exists (today):
Os.mkdir (today)
Comm= "Tar-czf%s%s"% (Target1, ". Join (source))
If Os.system (comm) ==0:
print ' successfull '
Else
print ' failed '
Scenario Four: increasing interactivity
The ideal way to create these archives is to use the ZipFile and Tarfile modules separately. They are part of the Python standard library and can be
For your use. Using these libraries avoids the use of os.system, the deprecated function.
On the other hand, you can interactively input the directories that need to be backed up and add them to the list by using the Extend method.
This article is from the "Victor's Struggle" blog, please be sure to keep this source http://victor2016.blog.51cto.com/6768693/1875945
Concise Python tutorial reading notes (ii) for important file backup