网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

python10.4备份脚本的代码怎么写

python10.4备份脚本的代码怎么写,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:域名与空间、虚拟主机、营销软件、网站建设、安阳县网站维护、网站推广。

版本四的代码是相当长的,所以很多人对其有束手无策之感,但是你通过以下的代码对其,有更好的了解,以下就是相关内容的详细介绍。希望你会有所收获。

  1. #!/usr/bin/python  

  2. # Filename: backup_ver4.py  

  3. import os  

  4. import time  

  5. # 1. The files and directories to be backed up are 
    specified in a list.  

  6. source = [‘/home/swaroop/byte’, ‘/home/swaroop/bin’]  

  7. # If you are using Windows, use source =
     [r'C:\Documents'
    , r'D:\Work'] or something like that  

  8. # 2. The backup must be stored in a main backup
     directory  

  9. target_dir = ‘/mnt/e/backup/’ # Remember to change 
    this to what you will be using  

  10. # 3. The files are backed up into a zip file.  

  11. # 4. The current day is the name of the 
    subdirectory in the main directory  

  12. today = target_dir + time.strftime(‘%Y%m%d’)  

  13. # The current time is the name of the zip archive  

  14. now = time.strftime(‘%H%M%S’)  

  15. # Take a comment from the user to create the name 
    of the zip file  

  16. comment = raw_input(‘Enter a comment –> ‘)  

  17. if len(comment) == 0: # check if a comment was entered  

  18. target = today + os.sep + now + ‘.zip’  

  19. else:  

  20. target = today + os.sep + now + ‘_’ + \  

  21. comment.replace(‘ ‘, ‘_’) + ‘.zip’  

  22. # Notice the backslash!  

  23. # Create the subdirectory if it isn’t already there  

  24. if not os.path.exists(today):  

  25. os.mkdir(today) # make directory  

  26. print ‘Successfully created directory’, today  

  27. # 5. We use the zip command (in Unix/Linux) to put the 
    files in a zip archive  

  28. zip_command = "zip -qr ‘%s’ %s" % (target, ‘ 
    ‘.join(source))  

  29. # Run the backup  

  30. if os.system(zip_command) == 0:  

  31. print ‘Successful backup to’, target  

  32. else:  

  33. print ‘Backup FAILED’ 

文中提到“我还希望有的一个优化是使用tar命令替代zip命令。这样做的一个优势是在你结合使用tar和gzip命令的时候,备份会更快更小。如果你想要在Windows中使用这些归档,WinZip也能方便地处理这些.tar.gz文件。tar命令在大多数Linux/Unix系统中都是默认可用的。Windows用户也可以下载安装它。命令字符串现在将成为:

  1. tar = ‘tar -cvzf %s %s -X /home/swaroop/
    excludes.txt’ % (target, ‘ ‘.join(srcdir)) 

需要补充的是Windows用户安装完LibArchive后命令为bsdtar,而且若想使用-z这个选项,还需安装gzip软件。代码中的

target = today + os.sep + now + ‘.zip’

改为

target = today + os.sep + now + ‘.tar.gz’

使用

  1. bsdtar -cvzf %s %s -X /home/swaroop/
    excludes.txt’ % (target, ‘ ‘.join(source)) 

关于python10.4备份脚本的代码怎么写问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注创新互联行业资讯频道了解更多相关知识。


网页题目:python10.4备份脚本的代码怎么写
分享链接:http://bjjierui.cn/article/jssjgi.html

其他资讯