<font size=5>gitlab的备份和恢复</font>
(1)创建备份目录,并授权
[root@linux-node1 ~]# mkdir /data/backups/gitlab -p
[root@linux-node1 ~]# chown -R git.git /data/
[root@linux-node1 ~]# ll /data/ -d
drwxr-xr-x 3 git git 20 Dec 20 16:21 /data/
(2)修改gitlab配置
[root@linux-node1 ~]# vim /etc/gitlab/gitlab.rb
gitlab_rails['backup_path'] = "/data/backups/gitlab" #备份路径
gitlab_rails['backup_keep_time'] = 604800 #备份7天
[root@linux-node1 ~]# gitlab-ctl reconfigure
[root@linux-node1 ~]# gitlab-ctl restart
ok: run: gitaly: (pid 41722) 0s
ok: run: gitlab-monitor: (pid 41735) 1s
ok: run: gitlab-workhorse: (pid 41738) 0s
ok: run: logrotate: (pid 41748) 0s
ok: run: nginx: (pid 41755) 0s
ok: run: node-exporter: (pid 41757) 0s
ok: run: postgres-exporter: (pid 41765) 0s
ok: run: postgresql: (pid 41792) 0s
ok: run: prometheus: (pid 41795) 0s
ok: run: redis: (pid 41807) 0s
ok: run: redis-exporter: (pid 41812) 1s
ok: run: sidekiq: (pid 41822) 0s
ok: run: unicorn: (pid 41831) 0s
(3)备份
[root@linux-node1 ~]# gitlab-rake gitlab:backup:create
Dumping database ...
Dumping PostgreSQL database gitlabhq_production ... [DONE]
done
Dumping repositories ...
* java/app1 ... [DONE]
* java/app1.wiki ... [SKIPPED]
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: 1513759548_2017_12_20_10.2.4_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. (0 removed)
(4)查看备份目录
[root@linux-node1 ~]# ll /data/backups/gitlab/
total 72
-rw------- 1 git git 71680 Dec 20 16:45 1513759548_2017_12_20_10.2.4_gitlab_backup.tar
#1513759548_2017_12_20_10.2.4为时间戳,备份的时候用的着
(5)恢复备份
删除gitlab中的app1的项目,再恢复
停止数据写入服务:
[root@linux-node1 ~]# gitlab-ctl stop unicorn
[root@linux-node1 ~]# gitlab-ctl stop sidekiq
恢复数据:
[root@linux-node1 ~]# gitlab-rake gitlab:backup:restore BACKUP=1513759548_2017_12_20_10.2.4
[root@linux-node1 ~]# gitlab-ctl restart
ok: run: gitaly: (pid 45486) 0s
ok: run: gitlab-monitor: (pid 45502) 0s
ok: run: gitlab-workhorse: (pid 45507) 1s
ok: run: logrotate: (pid 45525) 0s
ok: run: nginx: (pid 45531) 1s
ok: run: node-exporter: (pid 45536) 0s
ok: run: postgres-exporter: (pid 45540) 1s
ok: run: postgresql: (pid 45547) 0s
ok: run: prometheus: (pid 45555) 1s
ok: run: redis: (pid 45562) 0s
ok: run: redis-exporter: (pid 45568) 1s
ok: run: sidekiq: (pid 45572) 0s
ok: run: unicorn: (pid 45614) 0s
此时即可恢复原来的项目
邮件配置:
gitlab_rails['time_zone'] = 'Asia/Shanghai'
gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = 'xiaoming@126.com'
gitlab_rails['gitlab_email_display_name'] = 'gitlab'
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.126.com"
gitlab_rails['smtp_port'] = 25
gitlab_rails['smtp_user_name'] = "xiaoming"
gitlab_rails['smtp_password'] = "your password"
gitlab_rails['smtp_domain'] = "126.com"
gitlab_rails['smtp_authentication'] = "login"
本文转自 IT_外卖小哥 51CTO博客,原文链接:http://blog.51cto.com/jinlong/2052584