一、创建备份
docker exec gitlab gitlab-rake gitlab:backup:create
二、迁移备份
wget -O 1700569074_2023_11_21_15.1.1_gitlab_backup.tar http://192.168.31.247/down/H1zhXWIynpLp
三、导入备份
进入备份目录后执行导入命令
gitlab-rake gitlab:backup:restore BACKUP=1700569074_2023_11_21_15.1.1
警告提示
# gitlab-rake gitlab:backup:restore BACKUP=1700569074_2023_11_21_15.1.1
2023-11-21 12:30:38 +0000 -- Unpacking backup ...
2023-11-21 12:30:39 +0000 -- Unpacking backup ... done
2023-11-21 12:30:39 +0000 -- Restoring database ...
2023-11-21 12:30:39 +0000 -- Be sure to stop Puma, Sidekiq, and any other process that
connects to the database before proceeding. For Omnibus
installs, see the following link for more information:
https://docs.gitlab.com/ee/raketasks/backup_restore.html#restore-for-omnibus-gitlab-installations
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
Removing all tables. Press `Ctrl-C` within 5 seconds to abort
2023-11-17 16:37:07 UTC -- Cleaning the database ...
正常执行导入后,控制台输出如下:
2023-11-21 12:55:32 +0000 -- Restoring repositories ... done
2023-11-21 12:55:32 +0000 -- Restoring uploads ...
2023-11-21 12:55:32 +0000 -- Restoring uploads ... done
2023-11-21 12:55:32 +0000 -- Restoring builds ...
2023-11-21 12:55:32 +0000 -- Restoring builds ... done
2023-11-21 12:55:32 +0000 -- Restoring artifacts ...
2023-11-21 12:55:33 +0000 -- Restoring artifacts ... done
2023-11-21 12:55:33 +0000 -- Restoring pages ...
2023-11-21 12:55:33 +0000 -- Restoring pages ... done
2023-11-21 12:55:33 +0000 -- Restoring lfs objects ...
2023-11-21 12:55:33 +0000 -- Restoring lfs objects ... done
2023-11-21 12:55:33 +0000 -- Restoring terraform states ...
2023-11-21 12:55:33 +0000 -- Restoring terraform states ... done
2023-11-21 12:55:33 +0000 -- Restoring packages ...
2023-11-21 12:55:33 +0000 -- Restoring packages ... done
This task will now rebuild the authorized_keys file.
You will lose any data stored in the authorized_keys file.
Do you want to continue (yes/no)? yes
2023-11-21 12:55:49 +0000 -- Deleting tar staging files ...
2023-11-21 12:55:49 +0000 -- Cleaning up /var/opt/gitlab/backups/backup_information.yml
2023-11-21 12:55:49 +0000 -- Cleaning up /var/opt/gitlab/backups/db
2023-11-21 12:55:49 +0000 -- Cleaning up /var/opt/gitlab/backups/repositories
2023-11-21 12:55:49 +0000 -- Cleaning up /var/opt/gitlab/backups/uploads.tar.gz
2023-11-21 12:55:49 +0000 -- Cleaning up /var/opt/gitlab/backups/builds.tar.gz
2023-11-21 12:55:49 +0000 -- Cleaning up /var/opt/gitlab/backups/artifacts.tar.gz
2023-11-21 12:55:49 +0000 -- Cleaning up /var/opt/gitlab/backups/pages.tar.gz
2023-11-21 12:55:49 +0000 -- Cleaning up /var/opt/gitlab/backups/lfs.tar.gz
2023-11-21 12:55:49 +0000 -- Cleaning up /var/opt/gitlab/backups/terraform_state.tar.gz
2023-11-21 12:55:49 +0000 -- Cleaning up /var/opt/gitlab/backups/packages.tar.gz
2023-11-21 12:55:49 +0000 -- Deleting tar staging files ... done
2023-11-21 12:55:49 +0000 -- Deleting backups/tmp ...
2023-11-21 12:55:49 +0000 -- Deleting backups/tmp ... done
2023-11-21 12:55:49 +0000 -- Warning: Your gitlab.rb and gitlab-secrets.json files contain sensitive data
and are not included in this backup. You will need to restore these files manually.
2023-11-21 12:55:49 +0000 -- Restore task is done.
输出内容提到 gitlab.rb
和 gitlab-secrets.json
文件要手动还原
报错:
Restoring PostgreSQL database gitlabhq_production ... ERROR: must be owner of extension pg_trgm
ERROR: must be owner of extension btree_gist
ERROR: must be owner of extension btree_gist
ERROR: must be owner of extension pg_trgm
解决方法:
- 修改postgresql配置
$ vim /var/opt/gitlab/postgresql/data/postgresql.conf
listen_addresses = '*'
# 最下面新增两行
$ vim /var/opt/gitlab/postgresql/data/pg_hba.conf
local all all trust
host all all 127.0.0.1/32 trust
- 重启gitlab服务
$ gitlab-ctl restart
ok: run: logrotate: (pid 29367) 1s
ok: run: nginx: (pid 29371) 0s
ok: run: postgresql: (pid 29389) 0s
ok: run: redis: (pid 29391) 0s
ok: run: sidekiq: (pid 29404) 0s
ok: run: unicorn: (pid 29413) 0s
- 修改gitlab账号为超级用户
切换到gitlab-psql用户
su - gitlab-psql
进入到生产数据库postgresql
/opt/gitlab/embedded/bin/psql -h 127.0.0.1 gitlabhq_production
给数据库用户gitlab赋予超级权限
ALTER USER gitlab WITH SUPERUSER;
退出数据库
\q
操作控制台输出如下
$ su - gitlab-psql
$ /opt/gitlab/embedded/bin/psql -h 127.0.0.1 gitlabhq_production
psql (9.2.8)
Type "help" for help.
gitlabhq_production=# ALTER USER gitlab WITH SUPERUSER;
ALTER ROLE
gitlabhq_production=# \q
四、重启服务
admin@DESKTOP-JQNAP:~/dockerfile$ docker exec gitlab gitlab-rake gitlab:env:info
System information
System:
Current User: git
Using RVM: no
Ruby Version: 2.7.5p203
Gem Version: 3.1.4
Bundler Version:2.3.15
Rake Version: 13.0.6
Redis Version: 6.2.7
Sidekiq Version:6.4.0
Go Version: unknown
GitLab information
Version: 15.1.1
Revision: 35925db62b6
Directory: /opt/gitlab/embedded/service/gitlab-rails
DB Adapter: PostgreSQL
DB Version: 13.6
URL: http://10.10.12.235:30002
HTTP Clone URL: http://10.10.12.235:30002/some-group/some-project.git
SSH Clone URL: ssh://git@10.10.12.235:30003/some-group/some-project.git
Using LDAP: no
Using Omniauth: yes
Omniauth Providers:
GitLab Shell
Version: 14.7.4
Repository storage paths:
- default: /var/opt/gitlab/git-data/repositories
GitLab Shell path: /opt/gitlab/embedded/service/gitlab-shell
评论 (0)