欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

Python中10.4備份腳本代碼中需注意的地方有哪些

這篇文章給大家介紹Python中10.4 備份腳本代碼中需注意的地方有哪些,內(nèi)容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。

創(chuàng)新互聯(lián)公司專業(yè)為企業(yè)提供金華網(wǎng)站建設(shè)、金華做網(wǎng)站、金華網(wǎng)站設(shè)計、金華網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計與制作、金華企業(yè)網(wǎng)站模板建站服務(wù),十多年金華做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡(luò)服務(wù)。

在例10.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’  

關(guān)于Python教程的相關(guān)代碼,文中提到“我還希望有的一個優(yōu)化是使用tar命令替代zip命令。這樣做的一個優(yōu)勢是在你結(jié)合使用tar和gzip命令的時候,備份會更快更小。如果你想要在Windows中使用這些歸檔,WinZip也能方便地處理這些.tar.gz文件。tar命令在大多數(shù)Linux/Unix系統(tǒng)中都是默認可用的。Windows用戶也可以下載安裝它。

命令字符串現(xiàn)在將成為:

  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’

使用

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

英文原版已經(jīng)沒有用tar替換zip的內(nèi)容了,提出建議用Python標準庫中zipfile和tarfile來重寫ver5。

關(guān)于Python中10.4 備份腳本代碼中需注意的地方有哪些就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

本文標題:Python中10.4備份腳本代碼中需注意的地方有哪些
文章路徑:http://aaarwkj.com/article20/peiico.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供營銷型網(wǎng)站建設(shè)、建站公司、做網(wǎng)站、商城網(wǎng)站、響應(yīng)式網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設(shè)
亚洲精品一区二区99| 日韩精品一区伦理视频| 欧美色精品人妻在线最新| 精品人妻av中文字幕| 亚洲欧美极品一区色婷婷| 91超碰这里只有精品国产| 欧美日韩精品福利一区二区| 国产精品日韩经典中文字幕| 久久精品国产亚洲av不丁香| 国产三级传媒在线观看| 99热在线播放精品观看| 97人妻精品一区二区三区六| 亚洲女优中文字幕在线免费| 热久久青草精品欧美一区| 国产在线播放精品视频| 日韩国产欧美亚洲一区| 在线高清中文字幕三区| 国产美女口爆吞精久久| 国产亚洲美女在线视频视频| 欧美日韩精品视频网站| 日本a级片免费在线观看| 在线天堂一区二区三区| 91九色在线视频观看| 亚洲少妇插进去综合网| 亚洲精品国产精品粉嫩| 麻豆看片高清在线播放| 日本免费一区二区三区四区视频| 国产精品青青在线观看爽香蕉| 日本理论午夜三级在线观看| 国产亚洲一区二区日韩欧美| 色哟哟网站之中文字幕| 欧美日韩另类综合91| 日韩一二三四区免费观看| 国产欧美精品久久三级| 国产精品女人毛片在线看| 亚洲午夜天堂在线a毛片| 在线看日本一区二区| 日本乱码中文字幕在线观看| 国产国语网站在线观看| 四虎永久精品国产毛片| 精品中文字幕欧美区一区|