这里写图片描述
这篇文章主要介绍一下gitlab的备份和恢复的两种方式。

gitlab备份的两种方式

使用oracle备份的称呼方式,可以称之为冷备和热备,其实在gitlab中一般没有像oracle那样非常严格数据的完整性要求,所以一般来说没有那么严格。

方式说明
冷备份对gitlab的数据/设定/日志进行全量备份
热备份使用gitlab提供的命令进行备份

冷备说明

gitlab的数据文件分成如下三类,使用docker方式,一般会做成本地卷,则对此卷进行tar操作即可进行备份。

备份目录说明
/var/log/gitlab日志文件
/etc/gitlab设定文件
/var/opt/gitlab数据文件

热备说明

简单来说使用gitlab:backup:create能将信息备份到/var/opt/gitlab/backups

项目说明
命令gitlab-rake gitlab:backup:create
备份目录/var/opt/gitlab/backups
备份文件名称TIMESTAMP_gitlab_backup.tar

执行信息

可以看到其从数据库以及上传附件等各个部分进行备份

# gitlab-rake gitlab:backup:create
Dumping database ... 
Dumping PostgreSQL database gitlabhq_production ... [DONE]
done
Dumping repositories ...
 * root/demoprj ... [DONE]
done
Dumping uploads ... 
done
Dumping builds ... 
done
Dumping artifacts ... 
done
Dumping lfs objects ... 
done
Dumping container registry images ... 
[DISABLED]
Creating backup archive: 1499310141_gitlab_backup.tar ... done
Uploading backup archive to remote storage  ... skipped
Deleting tmp directories ... done
done
done
done
done
done
done
Deleting old backups ... skipping
#

结果确认

可以看到在指定目录下生成了备份文件

# pwd
/var/opt/gitlab/backups
# ls
1499310141_gitlab_backup.tar
# 

Restore(冷备)

使用冷备方式备份出来的tar文件,还原至以前的备份原目录,覆盖即可。

备份目录说明
/var/log/gitlab日志文件
/etc/gitlab设定文件
/var/opt/gitlab数据文件

#

Restore(热备)

使用gitlab的命令,我们得到了一个TIMESTAMP_gitlab_backup.tar的备份文件,自然使用此文件即可进行恢复。

项目说明
命令gitlab-rake gitlab:backup:restore BACKUP=TIMESTAMP
备份目录/var/opt/gitlab/backups
备份文件名称TIMESTAMP_gitlab_backup.tar

执行信息

# pwd
/var/opt/gitlab/backups
# ls
1499310141_gitlab_backup.tar
# gitlab-rake gitlab:backup:restore BACKUP=1499310141
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)? yes
...
GRANT
[DONE]
done
Restoring repositories ...
 * root/demoprj ... [DONE]
Put GitLab hooks in repositories dirs [DONE]
done
Restoring uploads ... 
done
Restoring builds ... 
done
Restoring artifacts ... 
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
# 

总结

这篇文章介绍一下gitlab的备份和恢复的方式,定期的备份是开发团队应该具有的良好习惯。

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐