GitLab-备份恢复

GitLab-备份恢复

备份脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/bash

cd /gitlab_jenkins_bakcup/gitlab/

DATETIME=$(date +"%Y%m%d%H%M")

FILE1="gitlab_data_"${DATETIME}.tar
FILE2="gitlab_config_"${DATETIME}.tar

rm -f /gitlab_jenkins_bakcup/gitlab/*.tar

gitlab-backup create
gitlab-ctl backup-etc

mv /var/opt/gitlab/backups/*_gitlab_backup.tar $FILE1
mv /etc/gitlab/config_backup/gitlab_config*.tar $FILE2

/usr/local/bin/aws s3 cp $FILE1 s3://hxs3/backup/
/usr/local/bin/aws s3 cp $FILE2 s3://hxs3/backup/

恢复

查看版本,备份恢复gitlab版本需一致

http://192.168.8.1:8090/help

13.10.3

安装指定版本

1
2
3
4
5
6
7
8
9
10
11
cat << EOF > /etc/yum.repos.d/gitlab-ce.repo
[gitlab-ce]
name=gitlab-ce
baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7
repo_gpgcheck=0
gpgcheck=0
enabled=1
EOF

yum list gitlab-ce --showduplicates
yum install -y gitlab-ce-13.10.3-ce.0.el7

将配置文件拷贝到 /etc/gitlab/

将备份文件拷贝到 /var/opt/gitlab/backups/

恢复准备

1
2
3
4
5
gitlab-ctl reconfigure
gitlab-ctl stop unicorn
gitlab-ctl stop puma
gitlab-ctl stop sidekiq
gitlab-ctl status

恢复,文件名不包含_gitlab_backup.tar

1
2
3
mv gitlab_data_202201190445.tar  1633686919_2021_10_08_13.10.3_gitlab_backup.tar
mv 1633686919_2021_10_08_13.10.3_gitlab_backup.tar /var/opt/gitlab/backups/
gitlab-backup restore BACKUP=1633686919_2021_10_08_13.10.3

重新配置并启动

1
2
gitlab-ctl reconfigure
gitlab-ctl restart