• GitLab的基础使用-数据备份与恢复


               GitLab的基础使用-数据备份与恢复

                                            作者:尹正杰

    版权声明:原创作品,谢绝转载!否则将追究法律责任。

    一.GitLab的数据备份

    1>.查看GitLab默认存储数据的目录

    [root@gitlab201.yinzhengjie.org.cn ~]# ll /var/opt/gitlab/git-data/
    total 12
    drwx------  3 git  root 4096 Mar 13 04:43 ./
    drwxr-xr-x 21 root root 4096 Mar 13 10:08 ../
    drwxrws---  4 git  root 4096 Mar 18 10:25 repositories/
    [root@gitlab201.yinzhengjie.org.cn ~]# 

    2>.停止GitLab的数据服务

    [root@gitlab201.yinzhengjie.org.cn ~]# gitlab-ctl status
    run: alertmanager: (pid 18999) 0s; run: log: (pid 1630) 642s
    run: gitaly: (pid 1699) 641s; run: log: (pid 1618) 642s
    run: gitlab-exporter: (pid 1697) 641s; run: log: (pid 1620) 642s
    run: gitlab-workhorse: (pid 1695) 641s; run: log: (pid 1631) 642s
    run: grafana: (pid 1690) 641s; run: log: (pid 1625) 642s
    run: logrotate: (pid 1696) 641s; run: log: (pid 1623) 642s
    run: nginx: (pid 1692) 641s; run: log: (pid 1621) 642s
    run: node-exporter: (pid 1638) 642s; run: log: (pid 1624) 642s
    run: postgres-exporter: (pid 1689) 641s; run: log: (pid 1628) 642s
    run: postgresql: (pid 1693) 641s; run: log: (pid 1619) 642s
    run: prometheus: (pid 1687) 641s; run: log: (pid 1626) 642s
    run: redis: (pid 1698) 641s; run: log: (pid 1617) 642s
    run: redis-exporter: (pid 1686) 641s; run: log: (pid 1627) 642s
    run: sidekiq: (pid 1694) 641s; run: log: (pid 1629) 642s
    run: unicorn: (pid 1691) 641s; run: log: (pid 1622) 642s
    [root@gitlab201.yinzhengjie.org.cn ~]#
    [root@gitlab201.yinzhengjie.org.cn ~]# gitlab-ctl status
    [root@gitlab201.yinzhengjie.org.cn ~]# gitlab-ctl stop unicorn
    ok: down: unicorn: 0s, normally up
    [root@gitlab201.yinzhengjie.org.cn ~]# 
    [root@gitlab201.yinzhengjie.org.cn ~]# gitlab-ctl stop sidekiq
    ok: down: sidekiq: 0s, normally up
    [root@gitlab201.yinzhengjie.org.cn ~]# 
    [root@gitlab201.yinzhengjie.org.cn ~]# gitlab-ctl status
    run: alertmanager: (pid 18999) 0s; run: log: (pid 1630) 791s
    run: gitaly: (pid 1699) 790s; run: log: (pid 1618) 791s
    run: gitlab-exporter: (pid 1697) 790s; run: log: (pid 1620) 791s
    run: gitlab-workhorse: (pid 1695) 790s; run: log: (pid 1631) 791s
    run: grafana: (pid 1690) 790s; run: log: (pid 1625) 791s
    run: logrotate: (pid 1696) 790s; run: log: (pid 1623) 791s
    run: nginx: (pid 1692) 790s; run: log: (pid 1621) 791s
    run: node-exporter: (pid 1638) 791s; run: log: (pid 1624) 791s
    run: postgres-exporter: (pid 1689) 790s; run: log: (pid 1628) 791s
    run: postgresql: (pid 1693) 790s; run: log: (pid 1619) 791s
    run: prometheus: (pid 1687) 790s; run: log: (pid 1626) 791s
    run: redis: (pid 1698) 790s; run: log: (pid 1617) 791s
    run: redis-exporter: (pid 1686) 790s; run: log: (pid 1627) 791s
    down: sidekiq: 71s, normally up; run: log: (pid 1629) 791s
    down: unicorn: 84s, normally up; run: log: (pid 1622) 791s
    [root@gitlab201.yinzhengjie.org.cn ~]# 
    [root@gitlab201.yinzhengjie.org.cn ~]# gitlab-ctl status

    3>.手动备份数据

    [root@gitlab201.yinzhengjie.org.cn ~]# ll /var/opt/gitlab/backups/
    total 8
    drwx------  2 git  root 4096 Mar 13 04:43 ./
    drwxr-xr-x 21 root root 4096 Mar 13 10:08 ../
    [root@gitlab201.yinzhengjie.org.cn ~]# 
    [root@gitlab201.yinzhengjie.org.cn ~]# gitlab-rake gitlab:backup:create
    2020-03-18 10:37:04 +0000 -- Dumping database ... 
    Dumping PostgreSQL database gitlabhq_production ... [DONE]
    2020-03-18 10:37:07 +0000 -- done
    2020-03-18 10:37:07 +0000 -- Dumping repositories ...
     * china_bigdata/cmdb (@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b) ... [DONE]
    [SKIPPED] Wiki
    2020-03-18 10:37:08 +0000 -- done
    2020-03-18 10:37:08 +0000 -- Dumping uploads ... 
    2020-03-18 10:37:08 +0000 -- done
    2020-03-18 10:37:08 +0000 -- Dumping builds ... 
    2020-03-18 10:37:08 +0000 -- done
    2020-03-18 10:37:08 +0000 -- Dumping artifacts ... 
    2020-03-18 10:37:08 +0000 -- done
    2020-03-18 10:37:08 +0000 -- Dumping pages ... 
    2020-03-18 10:37:08 +0000 -- done
    2020-03-18 10:37:08 +0000 -- Dumping lfs objects ... 
    2020-03-18 10:37:08 +0000 -- done
    2020-03-18 10:37:08 +0000 -- Dumping container registry images ... 
    2020-03-18 10:37:08 +0000 -- [DISABLED]
    Creating backup archive: 1584527828_2020_03_18_12.8.6_gitlab_backup.tar ... done
    Uploading backup archive to remote storage  ... skipped
    Deleting tmp directories ... done
    done
    done
    done
    done
    done
    done
    done
    Deleting old backups ... skipping
    Warning: Your gitlab.rb and gitlab-secrets.json files contain sensitive data 
    and are not included in this backup. You will need these files to restore a backup.
    Please back them up manually.
    Backup task is done.
    [root@gitlab201.yinzhengjie.org.cn ~]# 
    [root@gitlab201.yinzhengjie.org.cn ~]# 
    [root@gitlab201.yinzhengjie.org.cn ~]# ll /var/opt/gitlab/backups/
    total 168
    drwx------  2 git  root   4096 Mar 18 10:37 ./
    drwxr-xr-x 21 root root   4096 Mar 13 10:08 ../
    -rw-------  1 git  git  163840 Mar 18 10:37 1584527828_2020_03_18_12.8.6_gitlab_backup.tar
    [root@gitlab201.yinzhengjie.org.cn ~]# 
    [root@gitlab201.yinzhengjie.org.cn ~]# gitlab-rake gitlab:backup:create

    4>.启动GitLab服务

    [root@gitlab201.yinzhengjie.org.cn ~]# gitlab-ctl start
    ok: run: alertmanager: (pid 24886) 1352s
    ok: run: gitaly: (pid 1699) 1352s
    ok: run: gitlab-exporter: (pid 1697) 1352s
    ok: run: gitlab-workhorse: (pid 1695) 1352s
    ok: run: grafana: (pid 1690) 1352s
    ok: run: logrotate: (pid 1696) 1352s
    ok: run: nginx: (pid 1692) 1352s
    ok: run: node-exporter: (pid 1638) 1353s
    ok: run: postgres-exporter: (pid 1689) 1352s
    ok: run: postgresql: (pid 1693) 1352s
    ok: run: prometheus: (pid 1687) 1352s
    ok: run: redis: (pid 1698) 1352s
    ok: run: redis-exporter: (pid 1686) 1352s
    ok: run: sidekiq: (pid 24907) 0s
    ok: run: unicorn: (pid 24914) 0s
    [root@gitlab201.yinzhengjie.org.cn ~]# 

    5>.查看GitLab的WebUI

    二.模拟删除数据

    1>.访问项目目录,如下图所示,点击"index.html"文件

    2>.如下图所示,点击"Delete"

    3>.点击"Delete file"文件

    删除成功后,会有如下图所示的提示信息。

    三.利用第一步备份GitLab的数据进行恢复操作

    1>.恢复数据之前,先停止数据服务

    [root@gitlab201.yinzhengjie.org.cn ~]# gitlab-ctl stop unicorn
    ok: down: unicorn: 1s, normally up
    [root@gitlab201.yinzhengjie.org.cn ~]# 
    [root@gitlab201.yinzhengjie.org.cn ~]# gitlab-ctl stop sidekiq
    ok: down: sidekiq: 0s, normally up
    [root@gitlab201.yinzhengjie.org.cn ~]# 

    2>.执行恢复数据的命令

    [root@gitlab201.yinzhengjie.org.cn ~]# ll /var/opt/gitlab/backups/
    total 168
    drwx------  3 git  root   4096 Mar 18 11:05 ./
    drwxr-xr-x 21 root root   4096 Mar 13 10:08 ../
    -rw-------  1 git  git  163840 Mar 18 10:37 1584527828_2020_03_18_12.8.6_gitlab_backup.tar
    [root@gitlab201.yinzhengjie.org.cn ~]# 
    [root@gitlab201.yinzhengjie.org.cn ~]# gitlab-rake gitlab:backup:restore BACKUP=1584527828_2020_03_18_12.8.6      #指定要恢复的版本,注意BACKUP的名称格式为:unix时间戳_年_月_日_GitLab的版本号

    3>.如下图所示,第一个提示信息输入"yes"

    4>.如下图所示,第二个提示信息依旧输入"yes" 

    5>.再次启动GitLab的数据服务

    [root@gitlab201.yinzhengjie.org.cn ~]# gitlab-ctl start unicorn
    ok: run: unicorn: (pid 37482) 0s
    [root@gitlab201.yinzhengjie.org.cn ~]# 
    [root@gitlab201.yinzhengjie.org.cn ~]# gitlab-ctl start sidekiq
    ok: run: sidekiq: (pid 37595) 1s
    [root@gitlab201.yinzhengjie.org.cn ~]# 

    6>.再次查看GitLab的WebUI,如下图所示

  • 相关阅读:
    vue nextTick使用
    Vue slot插槽内容分发
    vue 项目设置实现通过本地手机访问
    vue router mode模式在webpack 打包上线问题
    html设置 hight100%问题
    更新模块通知栏显看不到当前进度,以及更新下载中可以清理通知问题,华为强制更新退出软件后台下载不显示通知问题
    ScrollView下嵌套GridView或ListView默认不在顶部的解决方法
    文件说明注释
    EditText双光标问题
    原 android重启应用(应用重新启动自身)
  • 原文地址:https://www.cnblogs.com/yinzhengjie2020/p/12489865.html
Copyright © 2020-2023  润新知