In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
How to write the code of the python10.4 backup script? for this problem, this article introduces the corresponding analysis and answer in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.
The code of version 4 is quite long, so many people feel helpless about it, but you have a better understanding of it through the following code, here is a detailed description of the relevant content. I hope you get something.
#! / usr/bin/python
# Filename: backup_ver4.py
Import os
Import time
# 1. The files and directories to be backed up are
Specified in a list.
Source = ['/ home/swaroop/byte','/ home/swaroop/bin']
# If you are using Windows, use source =
[ritual C:\ Documents'
, ringing D:\ Work'] or something like that
# 2. The backup must be stored in a main backup
Directory
Target_dir ='/ mnt/e/backup/' # Remember to change
This to what you will be using
# 3. The files are backed up into a zip file.
# 4. The current day is the name of the
Subdirectory in the main directory
Today = target_dir + time.strftime ('% Y% m% d')
# The current time is the name of the zip archive
Now = time.strftime ('% H% M% S')
# Take a comment from the user to create the name
Of the zip file
Comment = raw_input ('Enter a comment->')
If len (comment) = = 0: # check if a comment was entered
Target = today + os.sep + now + '.zip'
Else:
Target = today + os.sep + now +'_'+\
Comment.replace (','_') + '.zip'
# Notice the backslash!
# Create the subdirectory if it isn't already there
If not os.path.exists (today):
Os.mkdir (today) # make directory
Print 'Successfully created directory', today
# 5. We use the zip command (in Unix/Linux) to put the
Files in a zip archive
Zip_command = "zip-qr'% s"% (target,'
'.join (source))
# Run the backup
If os.system (zip_command) = = 0:
Print 'Successful backup to', target
Else:
Print 'Backup FAILED'
The article mentioned, "I also hope that one of the optimizations is to use the tar command instead of the zip command. One advantage of this is that backups are faster and smaller when you use the tar and gzip commands together. If you want to use these archives in Windows, WinZip can also easily handle these .tar.gz files. The tar command is available by default on most Linux/Unix systems. Windows users can also download and install it. The command string will now be:
Tar = 'tar-cvzf% s% s-X / home/swaroop/
Excludes.txt'% (target,''.join (srcdir))
What needs to be added is that Windows users install LibArchive after the command is bsdtar, and if you want to use the-z option, you also need to install gzip software. In the code
Target = today + os.sep + now + '.zip'
Change to
Target = today + os.sep + now + '.tar.gz'
Use
Bsdtar-cvzf% s% s-X / home/swaroop/
Excludes.txt'% (target,''.join (source))
This is the answer to the question about how to write the code for the python10.4 backup script. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.