2018-10-24


gitlab查看版本

cat /opt/gitlab/embedded/service/gitlab-rails/VERSION

查看gitlab服务状态命令

gitlab-ctl status

启动、停止服务

# 启动Gitlab所有组件
sudo gitlab-ctl start

# 停止Gitlab所有组件
sudo gitlab-ctl stop

# 重启Gitlab所有组件
sudo gitlab-ctl restart

备份与恢复

备份配置

配置文件再/etc/gitlab/ 下面,将所有的配置用tar备份即可

[root@localhost init.d]# cd /etc/gitlab/
[root@localhost gitlab]# ls
gitlab.rb  gitlab-secrets.json  trusted-certs

备份数据

Gitlab的备份目录路径设置

[root@code-server ~]# vim /etc/gitlab/gitlab.rb
gitlab_rails['manage_backup_path'] = true
gitlab_rails['backup_path'] = "/data/gitlab/backups"    //gitlab备份目录
gitlab_rails[       //生成的备份文件权限
gitlab_rails[              //备份保留天数为3个月(即90天,这里是7776000秒)

[root@code-server ~]# mkdir -p /data/gitlab/backups
[root@code-server ~]# chown -R git.git /data/gitlab/backups
[root@code-server ~]# chmod -R  /data/gitlab/backups

如上设置了gitlab备份目录路径为/data/gitlab/backups,最后使用下面命令重载gitlab配置文件,是上述修改生效!
root@code-server ~]# gitlab-ctl reconfigure

GItlab备份操作(使用备份命令"gitlab-rake gitlab:backup:create")

手动备份gitlab
[root@code-server backups]# gitlab-rake gitlab:backup:create
Dumping database ...
Dumping PostgreSQL database gitlabhq_production ... [DONE]
done
Dumping repositories ...
 * treesign/treesign ... [DONE]
 * gateway/gateway ... [DONE]
 * treesign/treesign-doc ... [SKIPPED]
 * qwsign/qwsign ... [DONE]
 * qwsign/qwsign-doc ... [DONE]
 * test/test ... [DONE]
done
Dumping uploads ...
done
Dumping builds ...
done
Dumping artifacts ...
done
Dumping pages ...
done
Dumping lfs objects ...
done
Dumping container registry images ...
[DISABLED]
Creating backup archive: 1510471890_2017_11_12_9..5_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 ... done. ( removed)

然后查看下备份文件(文件权限是设定好的644)
[root@code-server backups]# ll
total
-rw-r--r--  git git  Nov  : 1510472027_2017_11_12_9..5_gitlab_backup.tar

编写备份脚本,结合crontab实施自动定时备份,比如每天0点、6点、12点、18点各备份一次
[root@code-server backups]# pwd
/data/gitlab/backups
[root@code-server backups]# vim gitlab_backup.sh
#!/bin/bash
/usr/bin/gitlab-rake gitlab:backup:create CRON=

注意:环境变量CRON=1的作用是如果没有任何错误发生时, 抑制备份脚本的所有进度输出

[root@code-server backups]# crontab -l
 ,,, * * * /bin/bash -x /data/gitlab/backups/gitlab_backup.sh > /dev/>&

3)Gitlab恢复操作

GItlab只能还原到与备份文件相同的gitlab版本。
假设在上面gitlab备份之前创建了test项目,然后不小心误删了test项目,现在就进行gitlab恢复操作:

)停止相关数据连接服务
[root@code-server backups]# gitlab-ctl stop unicorn
ok: down: unicorn: 0s, normally up
[root@code-server backups]# gitlab-ctl stop sidekiq
ok: down: sidekiq: 1s, normally up
[root@code-server backups]# gitlab-ctl status
run: gitaly: (pid ) 1883s; run: log: (pid ) 163003s
run: gitlab-monitor: (pid ) 1883s; run: log: (pid ) 163002s
run: gitlab-workhorse: (pid ) 1882s; run: log: (pid ) 163002s
run: logrotate: (pid ) 1882s; run: log: (pid ) 160832s
run: nginx: (pid ) 1881s; run: log: (pid ) 163002s
run: node-exporter: (pid ) 1881s; run: log: (pid ) 163002s
run: postgres-exporter: (pid ) 1881s; run: log: (pid ) 163003s
run: postgresql: (pid ) 1880s; run: log: (pid ) 163002s
run: prometheus: (pid ) 1880s; run: log: (pid ) 163002s
run: redis: (pid ) 1879s; run: log: (pid ) 163002s
run: redis-exporter: (pid ) 1879s; run: log: (pid ) 163003s
down: sidekiq: 8s, normally up; run: log: (pid ) 163001s
down: unicorn: 21s, normally up; run: log: (pid ) 163001s

)现在通过之前的备份文件进行恢复(必须要备份文件放到备份路径下,这里备份路径我自定义的/data/gitlab/backups,默认的是/var/opt/gitlab/backups)
[root@code-server backups]# pwd
/data/gitlab/backups
[root@code-server backups]# ll
total
-rw-r--r--  git git  Nov  : 1510472027_2017_11_12_9..5_gitlab_backup.tar

Gitlab的恢复操作会先将当前所有的数据清空,然后再根据备份数据进行恢复
[root@code-server backups]# gitlab-rake gitlab:backup:restore BACKUP=1510472027_2017_11_12_9.4.5
Unpacking backup ... done
Before restoring the database we recommend removing 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)?
........
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
WARNING:  no privileges were granted for "public"
GRANT
[DONE]
done
Restoring repositories ...
 * treesign/treesign ... [DONE]
 * gateway/gateway ... [DONE]
 * treesign/treesign-doc ... [DONE]
 * qwsign/qwsign ... [DONE]
 * qwsign/qwsign-doc ... [DONE]
 * test/test ... [DONE]
Put GitLab hooks in repositories dirs [DONE]
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
[root@code-server backups]#

最后再次启动Gitlab
[root@code-server backups]# gitlab-ctl start
ok: run: gitaly: (pid ) 2138s
ok: run: gitlab-monitor: (pid ) 2138s
ok: run: gitlab-workhorse: (pid ) 2137s
ok: run: logrotate: (pid ) 2137s
ok: run: nginx: (pid ) 2136s
ok: run: node-exporter: (pid ) 2136s
ok: run: postgres-exporter: (pid ) 2136s
ok: run: postgresql: (pid ) 2135s
ok: run: prometheus: (pid ) 2135s
ok: run: redis: (pid ) 2134s
ok: run: redis-exporter: (pid ) 2134s
ok: run: sidekiq: (pid ) 0s
ok: run: unicorn: (pid ) 1s
[root@code-server backups]# gitlab-ctl status
run: gitaly: (pid ) 2142s; run: log: (pid ) 163262s
run: gitlab-monitor: (pid ) 2142s; run: log: (pid ) 163261s
run: gitlab-workhorse: (pid ) 2141s; run: log: (pid ) 163261s
run: logrotate: (pid ) 2141s; run: log: (pid ) 161091s
run: nginx: (pid ) 2140s; run: log: (pid ) 163261s
run: node-exporter: (pid ) 2140s; run: log: (pid ) 163261s
run: postgres-exporter: (pid ) 2140s; run: log: (pid ) 163262s
run: postgresql: (pid ) 2139s; run: log: (pid ) 163261s
run: prometheus: (pid ) 2139s; run: log: (pid ) 163261s
run: redis: (pid ) 2138s; run: log: (pid ) 163261s
run: redis-exporter: (pid ) 2138s; run: log: (pid ) 163262s
run: sidekiq: (pid ) 4s; run: log: (pid ) 163260s
run: unicorn: (pid ) 4s; run: log: (pid ) 163260s

恢复命令完成后,可以check检查一下恢复情况
[root@code-server backups]# gitlab-rake gitlab:check SANITIZE=true
Checking GitLab Shell ...

GitLab Shell version >=  ? ... OK ()
Repo base directory exists?
default... yes
Repo storage directories are symlinks?
default... no
Repo paths owned by git:root, or git:git?
default... yes
Repo paths access is drwxrws---?
default... yes
hooks directories in repos are links: ...
/ ... ok
/ ... ok
/ ... repository is empty
/ ... ok
/ ... ok
Running /opt/gitlab/embedded/service/gitlab-shell/bin/check
Check GitLab API access: OK
Access to /var/opt/gitlab/.ssh/authorized_keys: OK
Send ping to redis server: OK
gitlab-shell self-check successful

Checking GitLab Shell ... Finished

Checking Sidekiq ...

Running? ... yes
Number of Sidekiq processes ... 

Checking Sidekiq ... Finished

Checking Reply by email ...

Reply by email is disabled in config/gitlab.yml

Checking Reply by email ... Finished

Checking LDAP ...

LDAP is disabled in config/gitlab.yml

Checking LDAP ... Finished

Checking GitLab ...

Git configured correctly? ... yes
Database config exists? ... yes
All migrations up? ... yes
Database contains orphaned GroupMembers? ... no
GitLab config exists? ... yes
GitLab config up to date? ... yes
Log directory writable? ... yes
Tmp directory writable? ... yes
Uploads directory exists? ... yes
Uploads directory has correct permissions? ... yes
Uploads directory tmp has correct permissions? ... yes
Init script exists? ... skipped (omnibus-gitlab has no init script)
Init script up-to-date? ... skipped (omnibus-gitlab has no init script)
Projects have namespace: ...
/ ... yes
/ ... yes
/ ... yes
/ ... yes
/ ... yes
Redis version >= ? ... yes
Ruby version >=  ? ... yes ()
Git version >=  ? ... yes ()
Active users: ... 

Checking GitLab ... Finished

然后稍等一会(如果启动gitlab后,访问出现500,这是因为redis等程序还没完全启动,等一会儿访问就ok了),再次登录Gitlab,就会发现之前误删除的test项目已经恢复了!

另外:Gitlab迁移与恢复一样,但是要求两个GitLab版本号一致
GItlab只能还原到与备份文件相同的gitlab版本。
假设在上面gitlab备份之前创建了test项目,然后不小心误删了test项目,现在就进行gitlab恢复操作:
  
1)停止相关数据连接服务
[root@code-server backups]# gitlab-ctl stop unicorn
ok: down: unicorn: 0s, normally up
[root@code-server backups]# gitlab-ctl stop sidekiq
ok: down: sidekiq: 1s, normally up
[root@code-server backups]# gitlab-ctl status
run: gitaly: (pid 98087) 1883s; run: log: (pid 194202) 163003s
run: gitlab-monitor: (pid 98101) 1883s; run: log: (pid 194363) 163002s
run: gitlab-workhorse: (pid 98104) 1882s; run: log: (pid 194362) 163002s
run: logrotate: (pid 98117) 1882s; run: log: (pid 5793) 160832s
run: nginx: (pid 98123) 1881s; run: log: (pid 194359) 163002s
run: node-exporter: (pid 98167) 1881s; run: log: (pid 194360) 163002s
run: postgres-exporter: (pid 98173) 1881s; run: log: (pid 194204) 163003s
run: postgresql: (pid 98179) 1880s; run: log: (pid 194365) 163002s
run: prometheus: (pid 98187) 1880s; run: log: (pid 194364) 163002s
run: redis: (pid 98230) 1879s; run: log: (pid 194358) 163002s
run: redis-exporter: (pid 98234) 1879s; run: log: (pid 194208) 163003s
down: sidekiq: 8s, normally up; run: log: (pid 194437) 163001s
down: unicorn: 21s, normally up; run: log: (pid 194443) 163001s
  
2)现在通过之前的备份文件进行恢复(必须要备份文件放到备份路径下,这里备份路径我自定义的/data/gitlab/backups,默认的是/var/opt/gitlab/backups
[root@code-server backups]# pwd
/data/gitlab/backups
[root@code-server backups]# ll
total 244
-rw-r--r-- 1 git git 245760 Nov 12 15:33 1510472027_2017_11_12_9.4.5_gitlab_backup.tar
  
Gitlab的恢复操作会先将当前所有的数据清空,然后再根据备份数据进行恢复
[root@code-server backups]# gitlab-rake gitlab:backup:restore BACKUP=1510472027_2017_11_12_9.4.5
Unpacking backup ... done
Before restoring the database we recommend removing 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)?
........
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
WARNING:  no privileges were granted for "public"
GRANT
[DONE]
done
Restoring repositories ...
 * treesign/treesign ... [DONE]
 * gateway/gateway ... [DONE]
 * treesign/treesign-doc ... [DONE]
 * qwsign/qwsign ... [DONE]
 * qwsign/qwsign-doc ... [DONE]
 test/test ... [DONE]
Put GitLab hooks in repositories dirs [DONE]
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
[root@code-server backups]#
  
最后再次启动Gitlab
[root@code-server backups]# gitlab-ctl start
ok: run: gitaly: (pid 98087) 2138s
ok: run: gitlab-monitor: (pid 98101) 2138s
ok: run: gitlab-workhorse: (pid 98104) 2137s
ok: run: logrotate: (pid 98117) 2137s
ok: run: nginx: (pid 98123) 2136s
ok: run: node-exporter: (pid 98167) 2136s
ok: run: postgres-exporter: (pid 98173) 2136s
ok: run: postgresql: (pid 98179) 2135s
ok: run: prometheus: (pid 98187) 2135s
ok: run: redis: (pid 98230) 2134s
ok: run: redis-exporter: (pid 98234) 2134s
ok: run: sidekiq: (pid 104494) 0s
ok: run: unicorn: (pid 104497) 1s
[root@code-server backups]# gitlab-ctl status
run: gitaly: (pid 98087) 2142s; run: log: (pid 194202) 163262s
run: gitlab-monitor: (pid 98101) 2142s; run: log: (pid 194363) 163261s
run: gitlab-workhorse: (pid 98104) 2141s; run: log: (pid 194362) 163261s
run: logrotate: (pid 98117) 2141s; run: log: (pid 5793) 161091s
run: nginx: (pid 98123) 2140s; run: log: (pid 194359) 163261s
run: node-exporter: (pid 98167) 2140s; run: log: (pid 194360) 163261s
run: postgres-exporter: (pid 98173) 2140s; run: log: (pid 194204) 163262s
run: postgresql: (pid 98179) 2139s; run: log: (pid 194365) 163261s
run: prometheus: (pid 98187) 2139s; run: log: (pid 194364) 163261s
run: redis: (pid 98230) 2138s; run: log: (pid 194358) 163261s
run: redis-exporter: (pid 98234) 2138s; run: log: (pid 194208) 163262s
run: sidekiq: (pid 104494) 4s; run: log: (pid 194437) 163260s
run: unicorn: (pid 104497) 4s; run: log: (pid 194443) 163260s
 
恢复命令完成后,可以check检查一下恢复情况
[root@code-server backups]# gitlab-rake gitlab:check SANITIZE=true
Checking GitLab Shell ...
 
GitLab Shell version >= 5.3.1 ? ... OK (5.3.1)
Repo base directory exists?
default... yes
Repo storage directories are symlinks?
default... no
Repo paths owned by git:root, or git:git?
default... yes
Repo paths access is drwxrws---?
default... yes
hooks directories in repos are links: ...
5/1 ... ok
6/2 ... ok
5/3 ... repository is empty
12/4 ... ok
12/5 ... ok
Running /opt/gitlab/embedded/service/gitlab-shell/bin/check
Check GitLab API access: OK
Access to /var/opt/gitlab/.ssh/authorized_keys: OK
Send ping to redis server: OK
gitlab-shell self-check successful
 
Checking GitLab Shell ... Finished
 
Checking Sidekiq ...
 
Running? ... yes
Number of Sidekiq processes ... 1
 
Checking Sidekiq ... Finished
 
Checking Reply by email ...
 
Reply by email is disabled in config/gitlab.yml
 
Checking Reply by email ... Finished
 
Checking LDAP ...
 
LDAP is disabled in config/gitlab.yml
 
Checking LDAP ... Finished
 
Checking GitLab ...
 
Git configured correctly? ... yes
Database config exists? ... yes
All migrations up? ... yes
Database contains orphaned GroupMembers? ... no
GitLab config exists? ... yes
GitLab config up to date? ... yes
Log directory writable? ... yes
Tmp directory writable? ... yes
Uploads directory exists? ... yes
Uploads directory has correct permissions? ... yes
Uploads directory tmp has correct permissions? ... yes
Init script exists? ... skipped (omnibus-gitlab has no init script)
Init script up-to-date? ... skipped (omnibus-gitlab has no init script)
Projects have namespace: ...
5/1 ... yes
6/2 ... yes
5/3 ... yes
12/4 ... yes
12/5 ... yes
Redis version >= 2.8.0? ... yes
Ruby version >= 2.3.3 ? ... yes (2.3.3)
Git version >= 2.7.3 ? ... yes (2.13.4)
Active users: ... 11
 
Checking GitLab ... Finished
  
然后稍等一会(如果启动gitlab后,访问出现500,这是因为redis等程序还没完全启动,等一会儿访问就ok了),再次登录Gitlab,就会发现之前误删除的test项目已经恢复了!
  
另外:Gitlab迁移与恢复一样,但是要求两个GitLab版本号一致

gitlab 日常运维命令的更多相关文章

  1. hadoop记录-hadoop集群日常运维命令

    hadoop集群日常运维命令 #1.namenode hadoop namenode -format #格式化,慎用 su hdfs hadoop-daemon.sh start namenode h ...

  2. Docker Swarm 日常运维命令笔记

    之前介绍了Docker管理工具-Swarm部署记录,这里简单总结下Docker Swarm的日常维护命令,以作为平时运维笔记. Swarm作为一个管理Docker集群的工具,首先需要将其部署起来,可以 ...

  3. ogg日常运维命令

    1.查看历史记录.快捷执行历史中的一条命令 GGSCI (11g) 32> h 23: view param exta24: info all25: lag exta.... GGSCI (11 ...

  4. AIX—日常运维命令总结

    1. 查看AIX服务器的物理构造信息,包括服务器网络配置信息 # prtconf # ifconfig -a # lsattr -E -l mem0 :查看系统内存大小 # netstat -in : ...

  5. Jenkins日常运维笔记-重启数据覆盖问题、迁移、基于java代码发版(maven构建)

    之前在公司机房部署了一套jenkins环境,现需要迁移至IDC机房服务器上,迁移过程中记录了一些细节:1)jenkins默认的主目录放在当前用户家目录路径下的.jenkins目录中.如jenkins使 ...

  6. hadoop日常运维与升级总结

    日常运维 升级 问题处理方法 日常运维 进程管理 由于配置文件的更改,需要重启生效, 或者是进程自己因某种致命原因终止, 或者发现进程工作出现异常等情况下,需要进行手动进程的关闭或启动, 或者是增删节 ...

  7. zookeeper 用法和日常运维

    本文以ZooKeeper3.4.3版本的官方指南为基础:http://zookeeper.apache.org/doc/r3.4.3/zookeeperAdmin.html,补充一些作者运维实践中的要 ...

  8. 关于总结一些CentOS7常用的运维命令

    Centos7日常需要用的运维命令 1.删除0字节文件 find-type f -size 0 -exec rm -rf {} \ 2.查看进程 按内存从大到小排列 ps -e   -o " ...

  9. DB2常用运维命令

    DB2是IBM公司推出关系型数据库管理系统.主要应用于银行.医院等大型机构.现今DB2主要包含以下三个系列:DB2 for Linux, UNIX and Windows(LUW) . DB2在Lin ...

随机推荐

  1. Mac OS 10.8 中的 OpenGL 开发环境设置(转)

    转自:http://www.th7.cn/Program/cp/201305/137743.shtml 一.XCode 4.5 在项目的"Build Phases">&quo ...

  2. Join导致冗余数据引起慢SQL

    业务过程中碰到多个join引起慢SQL问题,数据量不大,但查询很慢,搜到一片BLog,参考解决. 业务过程不记录,以blog内容重现: 原SQL: select distinct abc.pro_co ...

  3. location.replace() keeps the history under control

    from https://dev.opera.com/articles/efficient-javascript Occasionally, it is necessary to change the ...

  4. vi常用快捷键汇总

      第一部分:光标移动.复制粘贴.查找替换 [Ctrl] + [f]  下一页 [Ctrl] + [b]  上一页  0或[home]  到行首 $或[end]  到行尾  G  到最后一行  gg ...

  5. delphi json用法

    用法:uses Superobject, Sperjsondelphi里有json单元. procedure TForm2.SuperObjectClick(Sender: TObject); var ...

  6. ubuntu 14.04 x64下安装libreoffice

    LibreOffice是ubuntu 上的办公软件很多人都知道微软公司的的Word.Excel.PowerPoint和Outlook,但是很少有人知道LibreOffice. LibreOffice靠 ...

  7. leetcode 106. 从中序与后序遍历序列构造二叉树(Construct Binary Tree from Inorder and Postorder Traversal)

    目录 题目描述: 示例: 解法: 题目描述: 根据一棵树的中序遍历与后序遍历构造二叉树. 注意: 你可以假设树中没有重复的元素. 示例: 给出 中序遍历 inorder = [9,3,15,20,7] ...

  8. 题解 P2350 【[HAOI2012]外星人】

    题目链接 还是本宝宝写题解的一贯习惯 $ :$ 先吐槽吐槽这道题$……$ 相信不少同学第一眼一定没有看懂题.(因为我也没看懂) ~~初中~~数学知识: 对于函数 $ f(x)$ 有 $f^{-1}(x ...

  9. Android Gradle 隐形依赖的奇怪案例

    相信 Android 开发者都有在 Android Studio 中升级 compileSdkVersion 的经历,这个时候如果你使用了 support 包,并同时升级,那么可能会出现一个错误提示. ...

  10. Tensorflow的认识

    1.基本概念(Tensorflow) 使用图(graphs)来表示计算任务 n 在被称之为会话(Session)的上下文(context)中执行图 n 使用tensor表示数据 n 通过变量(Vari ...