成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

python教程在例10.4 備份腳本的代碼的介紹

開(kāi)發(fā) 后端
以下文章主要是通過(guò)代碼的相關(guān)介紹的方式來(lái)引出python教程的實(shí)際應(yīng)用方案的相關(guān)介紹,以下是文章的詳細(xì)內(nèi)容,望你會(huì)有所收獲。

python教程在例10.4 備份腳本——版本四的代碼是相當(dāng)長(zhǎng)的,所以很多人對(duì)其有束手無(wú)策之感,但是你通過(guò)以下的代碼對(duì)其,有更好的了解,以下就是相關(guān)內(nèi)容的詳細(xì)介紹。希望你會(huì)有所收獲。

  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’ 

文中提到“我還希望有的一個(gè)優(yōu)化是使用tar命令替代zip命令。這樣做的一個(gè)優(yōu)勢(shì)是在你結(jié)合使用tar和gzip命令的時(shí)候,備份會(huì)更快更小。如果你想要在Windows中使用這些歸檔,WinZip也能方便地處理這些.tar.gz文件。tar命令在大多數(shù)Linux/Unix系統(tǒng)中都是默認(rèn)可用的。Windows用戶也可以下載安裝它。命令字符串現(xiàn)在將成為:

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

 

需要補(bǔ)充的是Windows用戶安裝完LibArchive后命令為bsdtar,而且若想使用-z這個(gè)選項(xiàng),還需安裝gzip軟件。代碼中的

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

改為

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

使用

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

以上的內(nèi)容就是對(duì)簡(jiǎn)明python教程在例10.4 備份腳本——版本四的代碼中有些需要注意的地方的詳細(xì)介紹。

【編輯推薦】

  1. Python字符串與轉(zhuǎn)義序列的相關(guān)內(nèi)容的介紹
  2. python隨機(jī)數(shù)生成的代碼的詳細(xì)解析
  3. Python字符和字符串的相關(guān)代碼示例解析
  4. Python對(duì)象以C語(yǔ)言實(shí)現(xiàn)其相關(guān)功能的介紹
  5. Python VIM 注釋掉代碼的具體方案的描述
責(zé)任編輯:佚名 來(lái)源: 博客園
相關(guān)推薦

2010-03-25 17:53:39

Python教程

2010-03-10 13:42:44

Python腳本

2010-05-31 10:55:08

Nagios mysq

2010-03-26 16:35:29

Python open

2010-04-08 09:27:44

Oracle 安裝腳本

2010-03-19 14:59:00

python Stri

2010-03-17 17:06:10

python腳本語(yǔ)言

2010-03-25 12:33:14

Python腳本文件

2010-03-25 10:13:03

Python代碼

2010-03-19 09:26:52

Python編程

2023-10-25 18:18:10

Python腳本代碼

2010-03-26 15:28:05

Python編寫

2010-02-02 16:40:34

Python 腳本

2011-08-09 09:54:02

Exchange 20備份

2021-07-07 05:53:23

PythonPython 語(yǔ)法加密源代碼

2010-03-30 11:29:24

Oracle備份

2010-03-26 15:14:26

Python編寫

2010-02-23 10:32:20

Python 腳本

2010-09-10 13:25:22

2011-05-16 09:32:33

mysql數(shù)據(jù)庫(kù)備份
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)

主站蜘蛛池模板: 天天操人人干 | 4h影视| 国产1区在线 | 亚洲视频一区在线观看 | 亚洲一区高清 | 亚洲精品视频在线观看视频 | 国产精品99久久久久久宅男 | 色欧美片视频在线观看 | 99免费在线观看 | 伊人精品在线视频 | 久久精品国产久精国产 | 中文字幕国产 | 亚洲国产一区二区三区, | 中文字幕1区2区3区 日韩在线视频免费观看 | 免费一看一级毛片 | 黄片毛片在线观看 | 成人精品一区二区 | 美日韩一区二区 | 黄网免费 | 国产色婷婷精品综合在线手机播放 | 久久av一区 | 亚洲国产福利视频 | 国产精品99久久久久 | 日韩在线小视频 | 精品中文字幕视频 | 高清久久久 | 欧美亚洲日本 | 黑人精品欧美一区二区蜜桃 | 亚洲免费一 | h视频在线观看免费 | 精品乱码一区二区三四区视频 | 日本精品一区二区三区在线观看视频 | 国产一二区视频 | 国产69精品久久久久777 | 国产高清精品在线 | 亚洲国产精品视频 | 天堂中文在线播放 | 成人久草 | 天天操操 | 99精品国产一区二区三区 | 亚洲九色 |