python pexpect 免交互自动恢复gitlab数据

fabric + fexpect == fabric + pexpect

以下脚本通过fabric调用,可以实现远程执行的功能:

#!/usr/bin/python
#-*-coding:utf-8-*-
import sys
from time import sleep
import pexpect
expectations=["Do you want to continue (yes/no)?","Do you want to continue (yes/no)?",]
child = pexpect.spawn('/bin/bash -c "docker exec -it gitlab_secid /bin/sh /opt/gitlab/bin/gitlab-rake gitlab:backup:restore 1582248489_2020_02_21_11.8.0_gitlab_backup.tar"',timeout=1800)
child.logfile = sys.stdout
while True:
        try:
                i = child.expect(expectations)
                if i == 0:
                        child.sendline('yes')
                elif i == 1:
                        child.sendline('yes')
        except pexpect.EOF:
                print('Exiting fexpect for EOF.')
                break
 

 

posted @ 2020-02-21 22:11  老农夫  阅读(344)  评论(0编辑  收藏  举报