抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >

[toc]

gitlab的备份与同步

gitlab备份

# sudo gitlab-rake gitlab:backup:create
# sudo scp -r /var/opt/gitlab/backups/ root@xx.xxx.xx.xxx:/root

由于版本问题,在迁移目标主机安装同样版本

# scp gitlab-ci-multi-runner_1.4.2_amd64.deb gitlab-ce_8.6.2-ce.0_amd64.deb root@xx.xxx.xx.xxx:/root
# 若无此版本的备份包时选择以下方式下载
链接:http://pan.baidu.com/s/1eS4H6NK  密码:e7i6

迁移目标主机安装与恢复

# dpkg -i /root/gitlab-ci-multi-runner_1.4.2_amd64.deb
# dpkg -i /root/gitlab-ce_8.6.2-ce.0_amd64.deb 
# mv /root/1510889754_gitlab_backup.tar /var/opt/gitlab/backups/
# gitlab-rake gitlab:backup:restore BACKUP=1510889754
# gitlab-ctl start
# vim /etc/gitlab/gitlab.rb
     unicorn['listen'] = '0.0.0.0'
     unicorn['port'] = 8080
# gitlab-ctl reconfigure
# gitlab-ctl start

检查8080端口是否启动

# netstat  -tnlup | grep 8080
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      3290/config.ru

源主机利用bash脚本+定时任务自动备份与同步备份

# 数据同步,首要做的就是双机互信;
# ssh-copy-id -i ~/.ssh/id_rsa.pub root@xx.xxx.xx.xxx
#!/bin/bash
#Can Bakup gitlab to xx.xxx.xx.xxx

FileBack () { 
    [ -d /var/opt/gitlab/backups/.bak ] || mkdir /var/opt/gitlab/backups/.bak -p
    mv /var/opt/gitlab/backups/*tar /var/opt/gitlab/backups/.bak/
    find /var/opt/gitlab/backups/.bak/  -type f -mtime +7 -exec rm -rf {} \;
    /usr/bin/gitlab-rake gitlab:backup:create &> /dev/null
    sleep 240
    ssh root@xx.xxx.xx.xxx "[ -d /var/opt/gitlab/backups/.bak ] || mkdir /var/opt/gitlab/backups/.bak -p"
    ssh root@xx.xxx.xx.xxx "mv /var/opt/gitlab/backups/*tar /var/opt/gitlab/backups/.bak/"
    ssh root@xx.xxx.xx.xxx "find /var/opt/gitlab/backups/.bak/  -type f -mtime +7 -exec rm -rf {} \;"
    scp  /var/opt/gitlab/backups/*tar root@xx.xxx.xx.xxx:/var/opt/gitlab/backups/
}

Message () {

    MESSAGE="gitlab 已备份成功 `ls -l /var/opt/gitlab/backups/` && `ls -ld /var/opt/gitlab/backups/` gitlab当前主服务器xx.xxx.xx.xxx"
    MESSAGE_2=`ssh root@xx.xxx.xx.xxx "ls -l /var/opt/gitlab/backups/;ls -ld /var/opt/gitlab/backups/; ifconfig | sed -n '/inet addr/s/^[^:]*:\([0-9.]\{7,15\}\) .*/\1/p' | head -1"`
    /bin/weixin --corpid=xxxxxxxxxxxxx --corpsecret=xxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.  --msg="$MESSAGE
    gitlab当前从服务器$MESSAGE_2" --user=15822097176@139.com --agentid=100000x
}

FileBack && Message
#!/bin/bash
#Can rolebak gitlab
FILE_BAK () {
scp /var/opt/gitlab/backups/*tar root@xx.xxx.xx.xxx:/volume1/skill-operation/bakup/gitlab/
ssh root@xx.xxx.xx.xxx "find /volume1/skill-operation/bakup/gitlab/  -type f -mtime +7 -exec rm -rf {} \;"
}

GIT_ROLBAK () {
BAKID=`cd /var/opt/gitlab/backups/ && ls | tr -dc "[:digit:]"`
cd /var/opt/gitlab/backups/ && chmod 666 *
/usr/bin/gitlab-rake gitlab:backup:restore BACKUP=$BAKID <<EOF &> /dev/null
yes
yes
EOF
}

MESSAGE () {
/bin/weixin --corpid=xxxxxxxxxxxxx --corpsecret=xxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx --msg="ID 为 $BAKID 的gitlab压缩包恢复完毕" --user=15822097176@139.com --agentid=100000x
}

FILE_BAK
GIT_ROLBAK && MESSAGE
# 定时任务进行实时备份与同步
su - root
crontab -e
10 22 * * * /bin/bash /bin/GITLAB_BAK.sh
su - root
crontab -e
30 22 * * * /bin/bash /bin/GIT_ROL.sh

评论