您当前的位置: 首页 >  git

暂无认证

  • 0浏览

    0关注

    92582博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

GitLab基础:如何将备份恢复至更高版本的GitLab

发布时间:2020-08-21 07:17:53 ,浏览量:0

在这里插入图片描述

在前面介绍的文章中已经提到,GitLab的备份和恢复需要保证源和目的的GitLab版本一致,如果不同版本之间如何做呢?这篇文章整理和记录一下容器化方式下GitLab-ce 11.2.3的数据恢复至GitLab 12.10.5的方法。

整体思路

仍然按照GitLab官方建议,按照如下三步进行恢复: 步骤1: 目的端拉起相同版本的GitLab 步骤2: 恢复数据导 步骤3: 使用相同数据卷重建GitLab服务

事前准备

事前准备了如下版本的GitLab备份文件, 从中可以看到为11.2.3版本的数据

liumiaocn:gitlab liumiao$ ls 1597959631_2020_08_20_11.2.3_gitlab_backup.tar 
1597959631_2020_08_20_11.2.3_gitlab_backup.tar
liumiaocn:gitlab liumiao$
步骤1: 目的端拉起相同版本的GitLab

拉起如下GitLab 11.2.3版本的服务,使用如下docker-compose.yml即可

liumiaocn:gitlab liumiao$ cat docker-compose.yml version: '2' services: # Version Control service: Gitlab gitlab: image: gitlab/gitlab-ce:11.2.3-ce.0 ports: - "32001:80" - "30022:22" - "30443:443" volumes: - ./log/:/var/log/gitlab - ./data/:/var/opt/gitlab - ./conf/:/etc/gitlab restart: "no" liumiaocn:gitlab liumiao$

登录之后确认版本信息如下所示: 在这里插入图片描述

步骤2: 恢复数据导
  • 拷贝数据至GitLab容器之中
liumiaocn:gitlab liumiao$ docker cp 1597959631_2020_08_20_11.2.3_gitlab_backup.tar gitlab_gitlab_1:/var/opt/gitlab/backups
liumiaocn:gitlab liumiao$
  • 确认文件与设定权限
liumiaocn:gitlab liumiao$ docker exec -it gitlab_gitlab_1 sh
# cd /var/opt/gitlab/backups
# ls -l
total 213952
-rw------- 1 501 dialout 207134720 Aug 20 22:07 1597959631_2020_08_20_11.2.3_gitlab_backup.tar
# 
# chmod 644 1597959631_2020_08_20_11.2.3_gitlab_backup.tar
# ls -l
total 213952
-rw-r--r-- 1 501 dialout 207134720 Aug 20 22:07 1597959631_2020_08_20_11.2.3_gitlab_backup.tar
#
  • 恢复数据

		

高版本的GitLab可直接使用gitlab-backup进行备份与恢复,详细可参看:

  • https://blog.csdn.net/liumiaocn/article/details/107952592
# gitlab-rake gitlab:backup:restore BACKUP=1597959631_2020_08_20_11.2.3
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
Removing all tables. Press `Ctrl-C` within 5 seconds to abort
Cleaning the database ... 
done
Restoring database ... 
Restoring PostgreSQL database gitlabhq_production ... SET
SET
SET
SET
SET
 set_config 
------------
 
(1 row)

SET
SET
SET
ERROR:  relation "public.timelogs" does not exist
...省略
[DONE]
done
Restoring repositories ...
...省略
done
Restoring uploads ... 
done
Restoring builds ... 
done
Restoring artifacts ... 
done
Restoring pages ... 
done
Restoring lfs objects ... 
done
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


Deleting tmp directories ... done
done
done
done
done
done
done
done
#

然后登录GitLab验证,酒客发现已经恢复成功了,但是此时版本仍然是: 在这里插入图片描述

步骤3: 使用相同数据卷重建GitLab服务
  • 停止并删除当前GitLab容器
liumiaocn:gitlab liumiao$ docker-compose down
Stopping gitlab_gitlab_1 ... done
Removing gitlab_gitlab_1 ... done
Removing network gitlab_default
liumiaocn:gitlab liumiao$

注意:此步骤具有风险性,如果事前有手动在容器中的修改,删除会连同此部分修改一同实施

  • 在同样的位置,利用之前的数据卷,拉起新的GitLab 12.10.5的服务
liumiaocn:gitlab liumiao$ vi docker-compose.yml 
liumiaocn:gitlab liumiao$ cat docker-compose.yml 
version: '2'    
services:
  # Version Control service: Gitlab
  gitlab:
    image: gitlab/gitlab-ce:12.10.5-ce.0
    ports:
      - "32001:80"
      - "30022:22"
      - "30443:443"
    volumes:
      - ./log/:/var/log/gitlab
      - ./data/:/var/opt/gitlab
      - ./conf/:/etc/gitlab
    restart: "no"
liumiaocn:gitlab liumiao$ 
liumiaocn:gitlab liumiao$ docker-compose up -d
Creating network "gitlab_default" with the default driver
Creating gitlab_gitlab_1 ... done
liumiaocn:gitlab liumiao$

结果发现需要中间升级至11.11.0,详细参看 升级问题对应,将版本改为11.11.0,重新拉起服务,发现已经正常升级至11.11.0了 在这里插入图片描述 再次修改镜像版本,重新启动GitLab服务

liumiaocn:gitlab liumiao$ vi docker-compose.yml 
liumiaocn:gitlab liumiao$ cat docker-compose.yml version: '2' services: # Version Control service: Gitlab gitlab: image: gitlab/gitlab-ce:12.10.5-ce.0 ports: - "32001:80" - "30022:22" - "30443:443" volumes: - ./log/:/var/log/gitlab - ./data/:/var/opt/gitlab - ./conf/:/etc/gitlab restart: "no" liumiaocn:gitlab liumiao$ docker-compose up -d
Recreating gitlab_gitlab_1 ... done
liumiaocn:gitlab liumiao$

重新启动之后发现已经正常升级至目标版本12.10.5了 在这里插入图片描述

升级问题对应

在步骤3中,重新拉起时出现了如下错误,相同的数据卷,从11.2.3换成了12.10.5,发现服务没有能够拉起来。

liumiaocn:gitlab liumiao$ docker-compose ps
     Name             Command       State    Ports
--------------------------------------------------
gitlab_gitlab_1   /assets/wrapper   Exit 1        
liumiaocn:gitlab liumiao$

进一步确认日志信息发现如下内容

gitlab_1  |     ================================================================================
gitlab_1  |     Error executing action `run` on resource 'bash[migrate gitlab-rails database]'
gitlab_1  |     ================================================================================
gitlab_1  |     
gitlab_1  |     Mixlib::ShellOut::ShellCommandFailed
gitlab_1  |     ------------------------------------
gitlab_1  |     Expected process to exit with [0], but received '1'
gitlab_1  |     ---- Begin output of "bash"  "/tmp/chef-script20200820-25-1llav8e" ----
gitlab_1  |     STDOUT: rake aborted!
gitlab_1  |     Your current database version is too old to be migrated. You should upgrade to GitLab 11.11.0 before moving to this version. Please see https://docs.gitlab.com/ee/policy/maintenance.html#upgrade-recommendations
gitlab_1  |     /opt/gitlab/embedded/service/gitlab-rails/lib/tasks/migrate/schema_check.rake:13:in `block in '
gitlab_1  |     /opt/gitlab/embedded/service/gitlab-rails/lib/tasks/gitlab/db.rake:49:in `block (3 levels) in '
gitlab_1  |     /opt/gitlab/embedded/bin/bundle:23:in `load'
gitlab_1  |     /opt/gitlab/embedded/bin/bundle:23:in `'
gitlab_1  |     Tasks: TOP => db:migrate => schema_version_check
gitlab_1  |     (See full trace by running task with --trace)
gitlab_1  |     STDERR: 
gitlab_1  |     ---- End output of "bash"  "/tmp/chef-script20200820-25-1llav8e" ----
gitlab_1  |     Ran "bash"  "/tmp/chef-script20200820-25-1llav8e" returned 1
gitlab_1  |     
gitlab_1  |     Resource Declaration:
gitlab_1  |     ---------------------
gitlab_1  |     # In /opt/gitlab/embedded/cookbooks/cache/cookbooks/gitlab/recipes/database_migrations.rb
gitlab_1  |     
gitlab_1  |      54: bash "migrate gitlab-rails database" do
gitlab_1  |      55:   code <<-EOH
gitlab_1  |      56:     set -e
gitlab_1  |      57:     log_file="#{node['gitlab']['gitlab-rails']['log_directory']}/gitlab-rails-db-migrate-$(date +%Y-%m-%d-%H-%M-%S).log"
gitlab_1  |      58:     umask 077
gitlab_1  |      59:     /opt/gitlab/bin/gitlab-rake gitlab:db:configure 2>& 1 | tee ${log_file}
gitlab_1  |      60:     STATUS=${PIPESTATUS[0]}
gitlab_1  |      61:     chown #{account_helper.gitlab_user}:#{account_helper.gitlab_group} ${log_file}
gitlab_1  |      62:     echo $STATUS > #{db_migrate_status_file}
gitlab_1  |      63:     exit $STATUS
gitlab_1  |      64:   EOH
gitlab_1  |      65:   environment env_variables unless env_variables.empty?
gitlab_1  |      66:   notifies :run, "execute[clear the gitlab-rails cache]", :immediately
gitlab_1  |      67:   dependent_services.each do |svc|
gitlab_1  |      68:     notifies :restart, svc, :immediately
gitlab_1  |      69:   end
gitlab_1  |      70:   not_if "(test -f #{db_migrate_status_file}) && (cat #{db_migrate_status_file} | grep -Fx 0)"
gitlab_1  |      71:   only_if { node['gitlab']['gitlab-rails']['auto_migrate'] }
gitlab_1  |      72: end
gitlab_1  |      73: 
...
gitlab_1  | Your current database version is too old to be migrated. You should upgrade to GitLab 11.11.0 before moving to this version. Please see https://docs.gitlab.com/ee/policy/maintenance.html#upgrade-recommendations
...省略

根据提示可以看到GitLab升级的时候不是一蹴而就的,可能需要多级跳,比如此处本来希望从11.2.3升级至12.10.5,需要先升到11.11.0,然后再升级,详细可参看如下说明: 在这里插入图片描述 修改版本至11.11.0之后,拉起服务,执行日志如下所示

liumiaocn:gitlab liumiao$ vi docker-compose.yml 
liumiaocn:gitlab liumiao$ cat docker-compose.yml 
version: '2'    
services:
  # Version Control service: Gitlab
  gitlab:
    image: gitlab/gitlab-ce:11.11.0-ce.0
    ports:
      - "32001:80"
      - "30022:22"
      - "30443:443"
    volumes:
      - ./log/:/var/log/gitlab
      - ./data/:/var/opt/gitlab
      - ./conf/:/etc/gitlab
    restart: "no"
liumiaocn:gitlab liumiao$ docker-compose up -d
Pulling gitlab (gitlab/gitlab-ce:11.11.0-ce.0)...
...省略
Status: Downloaded newer image for gitlab/gitlab-ce:11.11.0-ce.0
Recreating gitlab_gitlab_1 ... done
liumiaocn:gitlab liumiao$

可以通过docker-compose logs -f显示的日志确认是否正常结束,然后查看到如下正常的状态信息了

liumiaocn:gitlab liumiao$ docker-compose ps
     Name             Command          State                                      Ports                                
-----------------------------------------------------------------------------------------------------------------------
gitlab_gitlab_1   /assets/wrapper   Up (healthy)   0.0.0.0:30022->22/tcp, 0.0.0.0:30443->443/tcp, 0.0.0.0:32001->80/tcp
liumiaocn:gitlab liumiao$
参考文件

https://docs.gitlab.com/ee/policy/maintenance.html#upgrade-recommendations

关注
打赏
1653961664
查看更多评论
立即登录/注册

微信扫码登录

3.4839s