gitlab简单脚本做主备

目前网上通常搜到的都是利用drbd做共享磁盘实现gitlab主备,但这种方式需要挂载磁盘及安装软件,有点复杂,且gitlab不需要实时同步,所以我自己写了脚本,原理是利用gitlab自带的备份命令备份文件到本机,然后复制备份压缩包到备机上,并进行备份文件还原,即可以完成远程定时同步

具体方案:
1.登录到gitlab主机上进行备份操作,并将备份文件远程复制到备机上,ip1为主机
#!/bin/bash
user=root
pass1=’******’
pass=’******’
ip1=******
/usr/bin/expect << FLAGEOF
set timeout 2000
spawn ssh u s e r @ user@ user@ip1
expect {
“(yes/no)” {send “yes\r”; exp_continue}
“password:” {send “KaTeX parse error: Can't use function '\r' in math mode at position 6: pass1\̲r̲"} } expect "ro…pass\r”}
expect “root@” {send “exit\r”}
expect eof
FLAGEOF
2.在备机上利用备份文件进行还原操作,ip为备机
#!/bin/bash
user=root
pass=’******’
pass1=’******’
ip=******
ip1=******
p1=$( cd /tmp && ls -a|grep date +%Y_%m_%d|cut -c1-28) ##截取还原gitlab所需要的参数
/usr/bin/expect << FLAGEOF
set timeout 2000
spawn ssh u s e r @ user@ user@ip
expect {
“(yes/no)” {send “yes\r”; exp_continue}
“password:” {send “KaTeX parse error: Can't use function '\r' in math mode at position 5: pass\̲r̲"} } expect "ro…p1\r”} ##在备机进行还原
expect “(yes/no)” {send “yes\r”}
expect “(yes/no)” {send “yes\r”}
expect “root@” {send “mv /tmp/gitlab_backup.tar /wjtest/\r”} ##将备份文件转移到备份目录下
expect “root@” {send “exit\r”}
spawn ssh u s e r @ user@ user@ip1
expect {
“(yes/no)” {send “yes\r”; exp_continue}
“password:” {send “$pass1\r”}
}
expect “root@” {send “rm -f /test1/gitlab_backup.tar\r"} ##将主机下的备份文件删除
expect “rm” {send “yes\r”}
expect "root@
” {send “exit\r”}
expect eof
FLAGEOF3.在备机上设置定时任务,既可以实现同步
Crontab -e 设置脚本运行时间,需要备份脚本运行完毕才能运行还原脚本

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值