Fabric 應(yīng)用案例
示例1:文件打包,上傳與校驗(yàn)
我們時(shí)常做一些文件包分發(fā)的工作,實(shí)施步驟一般是先壓縮打包,在批量上傳至目標(biāo)服務(wù)器,最后做一致性校驗(yàn),本案例通過(guò)put()方法實(shí)現(xiàn)文件的上傳,通過(guò)對(duì)比本地與遠(yuǎn)程主機(jī)文件的md5,最終實(shí)現(xiàn)文件一致性校驗(yàn)。
#!/usr/bin/env python from fabric.api import * from fabric.context_managers import * from fabric.contrib.console import confirm env.user = 'root' env.hosts = ['192.168.1.23','192.168.1.24'] env.password = '123456' @runs_once def tar_task(): #本地打包任務(wù)函數(shù),只限執(zhí)行一次 with lcd('/'): local("tar zcvf auto.tar.gz auto") def put_task(): run('mkdir /data') #上傳任務(wù)函數(shù) with cd("/data"): with settings(warn_only=True): result = put("/auto.tar.gz","/data") #put上傳出現(xiàn)異常時(shí)繼續(xù)執(zhí)行,非中止 if result.failed and not confirm("put file failed, Continue[Y/N]?"): abort('Aboring file put task!') #出現(xiàn)異常時(shí),確認(rèn)用戶是否繼續(xù) def check_task(): with settings(warn_only=True): lmd5 = local("md5sum /auto.tar.gz",capture=True).split(' ')[0] rmd5 = run("md5sum /data/auto.tar.gz").split(' ')[0] if lmd5 == rmd5: #對(duì)比本地及遠(yuǎn)程文件MD5信息 print "ok" else: print ERROR def go(): tar_task() put_task() check_task()
相關(guān)文章
解決pytorch讀取自制數(shù)據(jù)集出現(xiàn)過(guò)的問(wèn)題
這篇文章主要介紹了解決pytorch讀取自制數(shù)據(jù)集出現(xiàn)過(guò)的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-05-05Python基于pandas實(shí)現(xiàn)json格式轉(zhuǎn)換成dataframe的方法
這篇文章主要介紹了Python基于pandas實(shí)現(xiàn)json格式轉(zhuǎn)換成dataframe的方法,結(jié)合實(shí)例形式分析了Python使用pandas模塊操作json數(shù)據(jù)轉(zhuǎn)換成dataframe的相關(guān)操作技巧與注意事項(xiàng),需要的朋友可以參考下2018-06-06OpenCV實(shí)現(xiàn)相機(jī)標(biāo)定
這篇文章主要為大家詳細(xì)介紹了OpenCV實(shí)現(xiàn)相機(jī)標(biāo)定,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-08-08