1、本地备份

1.1、如果需要修改备份目录可以修改配置文件下面的参数,记得修改后使配置生效

gitlab_rails['backup_path'] = ""


1.2、执行备份命令

# gitlab-rake gitlab:backup:create

Dumping database ...

Dumping PostgreSQL database gitlabhq_production ... [DONE]

done

Dumping repositories ...

 * root/test ... [DONE]

 * root/test.wiki ...  [SKIPPED]

 * test1/my-helloworld ... [DONE]

 * test1/my-helloworld.wiki ...  [SKIPPED]

 * qifanfan/hello ... [DONE]

 * qifanfan/hello.wiki ...  [SKIPPED]

 * qifanfan/eaf ... [DONE]

 * qifanfan/eaf.wiki ...  [SKIPPED]

done

Dumping uploads ...

done

Dumping builds ...

done

Dumping artifacts ...

done

Dumping pages ...

done

Dumping lfs objects ...

done

Dumping container registry images ...

[DISABLED]

Creating backup archive: 1539850586_2018_10_18_10.5.7_gitlab_backup.tar ... done

Uploading backup archive to remote storage  ... skipped

Deleting tmp directories ... done

done

done

done

done

done

done

done

Deleting old backups ... skipping

# ll

total 384

-rw------- 1 git  git  389120 Oct 18 16:16 1539850586_2018_10_18_10.5.7_gitlab_backup.tar

1.3、把备份命令写进脚本

# cd /var/opt/gitlab/backups

# vi auto_backup.sh

#!/bin/bash

/var/opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1

注意:环境变量CRON=1的作用是如果没有任何错误发生时, 抑制备份脚本的所有进度输出

脚本赋权

# chmod a+x auto_backup.sh

1.4、定时执行脚本,每天12点18点执行脚本

# crontab -e 

0 12,18 * * * /var/opt/gitlab/backups/auto_backup.sh > /dev/null 2>&1

1.5、设置备份天数为两周

# vi /etc/gitlab/gitlab.rb

gitlab_rails['backup_keep_time'] = 1209600

# gitlab-ctl recofigure

2、备机备份及在备机恢复

2.1、做原机访问备机做免密

原机和备机生成秘钥

# ssh-keygen -t rsa -P ""

原机拷贝公钥到备机(192.168.42.137为原机,192.168.42.138为备机

# ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.42.138

2.2、备机需要安装相同版本的gitlab

# rpm -i gitlab-ce-10.5.0-ce.0.el7.x86_64.rpm

# vi /etc/gitlab/gitlab.rb

external_url 'http://192.168.42.138'

# gitlab-ctl reconfigure

2.3、拷贝备份文件到备机

# scp 1539850586_2018_10_18_10.5.7_gitlab_backup.tar 192.168.42.138:/var/opt/gitlab/backups

2.4、备机执行恢复操作

修改文件权限

# chmod 777 1539850586_2018_10_18_10.5.7_gitlab_backup.tar

关闭服务

# gitlab-ctl stop unicorn

# gitlab-ctl sidekiq

执行恢复,gitlab首先会清空当前所有的数据,然后根据备份数据进行恢复

# gitlab-rake gitlab:backup:restore BACKUP=1539850586_2018_10_18_10.5.7

Unpacking backup ... done

Before restoring the database, we will remove all existing

tables to avoid future upgrade problems. Be aware that if you have

custom tables in the GitLab database these tables and all data will be

removed.

Do you want to continue (yes/no)?

输入“yes”

This will rebuild an authorized_keys file.

You will lose any data stored in authorized_keys file.

Do you want to continue (yes/no)?

输入“yes”

启动服务

# gitlab-ctl start

参考:

https://blog.csdn.net/ouyang_peng/article/details/77070977

https://www.cnblogs.com/kevingrace/p/7821529.html