gitlab从备份文件恢复

By Admin

gitlab

# `gitlab-rake` 是 GitLab Omnibus 社区版中提供的一种工具,用于执行 GitLab 相关的任务。`gitlab:backup:restore` 是其中的一个任务,可以用来恢复 GitLab 数据库、仓库、配置等数据。 1. ## 备份 ``` /bin/gitlab-rake gitlab:backup:create ``` **可以通过/etc/gitlab/git...

gitlab-rake
是 GitLab Omnibus 社区版中提供的一种工具,用于执行 GitLab 相关的任务。
gitlab:backup:restore
是其中的一个任务,可以用来恢复 GitLab 数据库、仓库、配置等数据。

  1. 备份

    /bin/gitlab-rake gitlab:backup:create

    可以通过/etc/gitlab/gitlab.rb配置文件来修改默认存放备份文件的目录,过期时间

    gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"
    gitlab_rails['backup_keep_time'] = 518400       #以秒为单位
  2. 安装gitlab

    yum localinstall gitlab-ce-11.6.3-ce.0.el7.x86_64.rpm

    安装完成后不要启动gitlab。

    **复制提前备份的 /etc/gitlab 整个目录覆盖 /etc/gitlab **

    cp -a /backups/config/* /etc/gitlab 

    然后执行初始化

    gitlab-ctl reconfigure
  3. 恢复

    安装依赖

    yum install -y ruby git 

    将提前做好的备份复制到指定的目录,并设置好权限。

    mkdir -p /backups/gitlab
    mv 1678385031_2023_03_10_11.6.3_gitlab_backup.tar  /backups/gitlab/
    chown -R git:git /backups/

[root@dy40244 ~]# gitlab-rake gitlab:backup:restore BACKUP=1678385031_2023_03_10_11.6.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
Restoring repositories ...
 * mpp2/mpp2 ... [DONE]
 。。。。
 * cj/dasv-page ... [DONE]
done
Restoring uploads ... 
done
Restoring builds ... 
done
Restoring artifacts ... 
done
Restoring pages ... 
done
Restoring lfs objects ... 
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

...................................................................................
Deleting tmp directories ... done
done
done
done
done
done
done
done
# 如果报错就执行下面的语句
gitlab-ctl start postgresql
gitlab-ctl start gitlab-workhorse
gitlab-ctl start gitaly
gitlab-ctl start gitlab-monitor
gitlab-ctl start redis

启动gitlab

gitlab-ctl start 
#启动gitlab

浏览器访问新服务器的地址进行查看,迁移成功

在实际情况中访问gitlab可能是用[域名]访问,我们可以修改gitlab配置文件中的url再进行备份,这样就不会影响迁移过程,恢复完成后需要进行的只是修改域名对应的dns解析ip地址