服务器升级替换文件快速备份与回滚

服务器升级替换文件快速备份与回滚

由于升级回退问题把我坑了一下,ansible的copy backup固然好用,可是回退却特别坑人,因为backup备份是有准确时间的,所以想到了以下方法,当然你可以写playbook,希望读者提出更好的建议

思路:
利用ansible

利用简单脚本

#脚本内容展示
ybt root /etc/ansible/A #cat bak.sh 
#!/bin/bash
for i in `cat 3.txt`;do cp $i $i.bak2021_07_29; done
#for i in `cat 3.txt`; do  mv  $i{.bak2021_07_29,}; done

示例:

#展示升级文件
ybt root /etc/ansible/A #cat 3.txt 
pro 
scf
scf1
备份:
#将升级文本COPY到远程服务器
ybt root /etc/ansible/A #ansible test -m copy -a 'src=3.txt dest=/root/cin/etc/'
#查看3.txt是否存在
ybt root /etc/ansible/A #ansible test -m shell -a 'ls /root/cin/etc/'
192.168.23.137 | CHANGED | rc=0 >>
3.txt
pro
scf
scf1
ybt
192.168.23.138 | CHANGED | rc=0 >>
3.txt
pro
scf
scf1
ybt

#备份
#执行脚本第一句,第二句注释
#!/bin/bash
for i in `cat 3.txt`;do cp $i $i.bak2021_07_29; done
#for i in `cat 3.txt`; do  mv  $i{.bak2021_07_29,}; done

#示例:
ybt root /etc/ansible/A #ansible test -m script -a 'chdir=/root/cin/etc/ bak.sh'
#查看是否备份成功
ybt root /etc/ansible/A #ansible test -m shell -a 'ls /root/cin/etc/'
192.168.23.137 | CHANGED | rc=0 >>
3.txt
pro
pro.bak2021_07_29
scf
scf1
scf1.bak2021_07_29
scf.bak2021_07_29
ybt
192.168.23.138 | CHANGED | rc=0 >>
3.txt
pro
pro.bak2021_07_29
scf
scf1
scf1.bak2021_07_29
scf.bak2021_07_29
ybt
回滚:
#执行脚本第二句,第一句注释
#!/bin/bash
#for i in `cat 3.txt`;do cp $i $i.bak2021_07_29; done
for i in `cat 3.txt`; do  mv  $i{.bak2021_07_29,}; done

#示例:
#执行脚本
ybt root /etc/ansible/A #ansible test -m script -a 'chdir=/root/cin/etc/ bak.sh'
192.168.23.137 | CHANGED => {
    "changed": true, 
    "rc": 0, 
    "stderr": "Shared connection to 192.168.23.137 closed.\r\n", 
    "stderr_lines": [
        "Shared connection to 192.168.23.137 closed."
    ], 
    "stdout": "", 
    "stdout_lines": []
}
192.168.23.138 | CHANGED => {
    "changed": true, 
    "rc": 0, 
    "stderr": "Shared connection to 192.168.23.138 closed.\r\n", 
    "stderr_lines": [
        "Shared connection to 192.168.23.138 closed."
    ], 
    "stdout": "", 
    "stdout_lines": []
}
#查看结果
ybt root /etc/ansible/A #ansible test -m shell -a 'ls /root/cin/etc/'
192.168.23.137 | CHANGED | rc=0 >>
3.txt
pro
scf
scf1
ybt
192.168.23.138 | CHANGED | rc=0 >>
3.txt
pro
scf
scf1
ybt

替换:

不在示例:直接用COPY模块即可

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ybt&kexiao

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值