黑松山资源网 Design By www.paidiu.com
示例1:文件打包,上传与校验
我们时常做一些文件包分发的工作,实施步骤一般是先压缩打包,在批量上传至目标服务器,最后做一致性校验,本案例通过put()方法实现文件的上传,通过对比本地与远程主机文件的md5,最终实现文件一致性校验。
#!/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(): #本地打包任务函数,只限执行一次 with lcd('/'): local("tar zcvf auto.tar.gz auto") def put_task(): run('mkdir /data') #上传任务函数 with cd("/data"): with settings(warn_only=True): result = put("/auto.tar.gz","/data") #put上传出现异常时继续执行,非中止 if result.failed and not confirm("put file failed, Continue[Y/N]"): abort('Aboring file put task!') #出现异常时,确认用户是否继续 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: #对比本地及远程文件MD5信息 print "ok" else: print ERROR def go(): tar_task() put_task() check_task()
黑松山资源网 Design By www.paidiu.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
黑松山资源网 Design By www.paidiu.com
暂无评论...
更新日志
2024年10月09日
2024年10月09日
- s14全球总决赛瑞士轮赛制是什么 全球总决赛瑞士轮赛制详情
- 《COD21》全新剧情宣传片:10月25日XGP见!
- 美国拳王家门口身中7枪遇害 年仅31岁凶手仍未被逮捕
- 《寂静岭2》重制版光追对比:氛围更加恐怖
- 林慧萍.1982-往昔(飞跃复刻版)【歌林】【WAV+CUE】
- 陈楚生.2007-原来我一直都不孤单(EP)【天娱传媒】【WAV+CUE】
- 罗嘉良.1986-秦始皇(2014环球复黑王·百代篇)【EMI百代】【WAV+CUE】
- 2024周年庆赠送物品介绍,周年庆送什么
- 【原神】V5.0攻略 |「明黄曜石断片」全收集
- 【原神】V5.0攻略 | 隐藏成就「烦请高抬贵脚」达成
- 证声音乐图书馆《蔚蓝海岸·爵士度假日》[FLAC/分轨][155.47MB]
- 腾讯音乐人《浪漫火焰(新势力计划合辑 Vol.11)》[320K/MP3][56.91MB]
- 腾讯音乐人《浪漫火焰(新势力计划合辑 Vol.11)[FLAC/分轨][147.45MB]
- 2024年,哪里还可以玩有趣的魔兽RPG?
- 类银河恶魔城动作游戏《灵魂熔解》已正式登陆Steam