GitLab备份与恢复测试(基于Docker)

GitLab环境准备

bash 复制代码
docker run --name gitlab \
-p 2022:22 -p 2080:80 -p 2443:443 -d \
-v /opt/gitlab/config:/etc/gitlab \
-v /opt/gitlab/gitlab/logs:/var/log/gitlab \
-v /opt/gitlab/gitlab/data:/var/opt/gitlab \
gitlab/gitlab-ce:16.2.1-ce.0

备份

1.修改配置文件/opt/gitlab/config/gitlab.rb

bash 复制代码
gitlab_rails['manage_backup_path'] = true
gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"
# gitlab_rails['backup_gitaly_backup_path'] = "/opt/gitlab/embedded/bin/gitaly-backup"

###! Docs: https://docs.gitlab.com/ee/raketasks/backup_restore.html#backup-archive-permissions
gitlab_rails['backup_archive_permissions'] = 0644

# gitlab_rails['backup_pg_schema'] = 'public'

###! The duration in seconds to keep backups before they are allowed to be deleted
gitlab_rails['backup_keep_time'] = 604800

2.重新加载配置

bash 复制代码
docker exec -t gitlab gitlab-ctl reconfigure

3.备份应用程序

bash 复制代码
docker exec -t gitlab gitlab-backup create STRATEGY=copy

4.备份配置

bash 复制代码
docker exec -t gitlab /bin/bash -c 'gitlab-ctl backup-etc'

恢复

1.启动gitlab

bash 复制代码
docker run --name gitlab-bak1 \
-p 2022:22 -p 2080:80 -p 2443:443 -d \
-v /opt/gitlab_bak1/config:/etc/gitlab \
-v /opt/gitlab_bak1/logs:/var/log/gitlab \
-v /opt/gitlab_bak1/data:/var/opt/gitlab \
gitlab/gitlab-ce:16.2.1-ce.0

2.修改配置文件/opt/gitlab_bak1/config/gitlab.rb

bash 复制代码
gitlab_rails['manage_backup_path'] = true
gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"
# gitlab_rails['backup_gitaly_backup_path'] = "/opt/gitlab/embedded/bin/gitaly-backup"

###! Docs: https://docs.gitlab.com/ee/raketasks/backup_restore.html#backup-archive-permissions
gitlab_rails['backup_archive_permissions'] = 0644

# gitlab_rails['backup_pg_schema'] = 'public'

###! The duration in seconds to keep backups before they are allowed to be deleted
gitlab_rails['backup_keep_time'] = 604800

3.重新加载配置

bash 复制代码
docker exec -t gitlab-bak1 gitlab-ctl reconfigure

4.复制备份文件到2指定的目录

bash 复制代码
cp /opt/gitlab/gitlab/data/backups/1705891184_2024_01_22_16.2.1_gitlab_backup.tar /opt/gitlab_bak1/data/backups/

5.停止连接到数据库的进程

bash 复制代码
docker exec -it gitlab-bak1 gitlab-ctl stop puma
docker exec -it gitlab-bak1 gitlab-ctl stop sidekiq
docker exec -it gitlab-bak1 gitlab-ctl status

6.恢复,名称中省略了_gitlab_backup.tar

bash 复制代码
docker exec -it gitlab-bak1 gitlab-backup restore BACKUP=1705891184_2024_01_22_16.2.1

7.恢复gitlab-secrets文件

bash 复制代码
tar -xf /opt/gitlab/config/config_backup/gitlab_config_1705891508_2024_01_22.tar -C /tmp/ && mv -f /tmp/etc/gitlab/gitlab-secrets.json /opt/gitlab_bak1/config/

8.重启gitlab容器

bash 复制代码
docker restart gitlab-bak1

9.检查

bash 复制代码
docker exec -it gitlab-bak1 gitlab-rake gitlab:check SANITIZE=true

参考链接

官方文档: https://docs.gitlab.com/omnibus/settings/backups.html

gitlab数据及用户迁移: https://blog.csdn.net/IT_shinchan/article/details/130783545?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-4-130783545-blog-122261961.235^v40^pc_relevant_anti_t3&spm=1001.2101.3001.4242.3&utm_relevant_index=5

相关推荐
dessler1 小时前
Docker-Dockerfile讲解(三)
linux·运维·docker
一休哥助手1 小时前
深入理解 Docker 网桥配置与网络管理
docker·容器·eureka
PittDing2 小时前
【更新】Docker新手入门教程2:在Windows系统通过compose创建多个mysql镜像并配置应用
windows·mysql·docker
Mitch3113 小时前
【漏洞复现】CVE-2014-3120 & CVE-2015-1427 Expression Injection
运维·web安全·elasticsearch·docker·apache
m0_748251084 小时前
docker安装nginx,docker部署vue前端,以及docker部署java的jar部署
java·前端·docker
m0_748240255 小时前
docker--压缩镜像和加载镜像
java·docker·eureka
颜淡慕潇6 小时前
【K8S问题系列 | 20 】K8S如何删除异常对象(Pod、Namespace、PV、PVC)
后端·云原生·容器·kubernetes
lmxnsI6 小时前
docker使用笔记
笔记·docker·容器
木卫二号Coding7 小时前
Docker-构建自己的Web-Linux系统-镜像webtop:ubuntu-kde
linux·ubuntu·docker
木卫二号Coding8 小时前
宝塔-firefox(Docker应用)-构建自己的Web浏览器
linux·docker·开源