Gitlab

Gitlab 备份与恢复

备份

  • 配置文件
...
### Backup Settings
###! Docs: https://docs.gitlab.com/omnibus/settings/backups.html

# gitlab_rails['manage_backup_path'] = true # 是否可以指定备份目录
# gitlab_rails['backup_path'] = "/var/opt/gitlab/backups" # 指定备份目录
# gitlab_rails['backup_gitaly_backup_path'] = "/opt/gitlab/embedded/bin/gitaly-backup"

###! Docs: https://docs.gitlab.com/ee/raketasks/backup_restore.html#backup-archive-permissions
# gitlab_rails['backup_archive_permissions'] = 0644 # 指定备份后的压缩包的权限

# gitlab_rails['backup_pg_schema'] = 'public'

###! The duration in seconds to keep backups before they are allowed to be deleted
# gitlab_rails['backup_keep_time'] = 604800 # 备份保留多久
...
[root@localhost gitlab]# cat > /etc/gitlab/gitlab.rb <<'EOF'
external_url 'http://gitlab.westudy.cn'
 gitlab_rails['manage_backup_path'] = true # 是否可以指定备份目录
 gitlab_rails['backup_path'] = "/var/opt/gitlab/backups" # 指定备份目录
 gitlab_rails['backup_archive_permissions'] = 0644 # 指定备份后的压缩包的权限
 gitlab_rails['backup_keep_time'] = 604800 # 备份保留多久
 gitlab_rails['smtp_enable'] = false
 gitlab_rails['registry_enabled'] = false
 registry['enable'] = false
 prometheus['enable'] = false
 alertmanager['enable'] = false
 node_exporter['enable'] = false
 redis_exporter['enable'] = false
 postgres_exporter['enable'] = false
 gitlab_exporter['enable'] = false
 prometheus_monitoring['enable'] = false
EOF
[root@localhost gitlab]#
  • 执行
[root@localhost gitlab]# gitlab-ctl reconfigure
[root@localhost gitlab]# gitlab-ctl restart
[root@localhost gitlab]# gitlab-backup create
[root@localhost gitlab]# ls /var/opt/gitlab/backups/ # 该文件夹下有内容输出
[root@localhost gitlab]# tar tf /var/opt/gitlab/backups/1715691366_2024_05_14_15.9.3_gitlab_backup.tar

恢复

  • 重置密码
[root@localhost gitlab]# gitlab-rake "gitlab:password:reset"
Enter username: root
Enter password:
Confirm password:
Password successfully updated for user with username root.
[root@localhost gitlab]#

  • 模拟误删
    在这里插入图片描述
  • 执行恢复

1️⃣ 停止写入类服务

[root@localhost gitlab]# gitlab-ctl stop unicorn
[root@localhost gitlab]# gitlab-ctl stop sidekiq
ok: down: sidekiq: 1s, normally up
[root@localhost gitlab]#

2️⃣ 执行恢复

[root@localhost gitlab]# gitlab-backup restore BACKUP=1715691366_2024_05_14_15.9.3
# 这里要交互式输入两次yes

3️⃣ 查看结果
在这里插入图片描述

自动备份

[root@localhost gitlab]# cat > backup_gitlab.sh <<'EOF'
#!/bin/bash
# 备份gitlab数据
gitlab-backup create

# 备份gitlab配置和密码文件
mkdir -p /backup/gitlab
tar zcf /backup/gitlab/gitlab-conf-$(date +%F_%T).tar.gz /etc/gitlab

# 传输到备份服务器
[root@localhost gitlab]#
[root@localhost gitlab]# chmod +x backup_gitlab.sh
[root@localhost gitlab]# crontab -l
*/1 * * * * sh /root/gitlab/backup_gitlab.sh &> /dev/null # 这里为了看到效果,设置每分钟备份一次
[root@localhost gitlab]#
[root@localhost gitlab]# ls /var/opt/gitlab/backups/
1715691366_2024_05_14_15.9.3_gitlab_backup.tar  1715696489_2024_05_14_15.9.3_gitlab_backup.tar  1715696548_2024_05_14_15.9.3_gitlab_backup.tar
[root@localhost gitlab]# ls -l /var/opt/gitlab/backups/
total 1680
-rw-r--r--. 1 git git 430080 May 14 20:56 1715691366_2024_05_14_15.9.3_gitlab_backup.tar
-rw-r--r--. 1 git git 430080 May 14 22:21 1715696489_2024_05_14_15.9.3_gitlab_backup.tar
-rw-r--r--. 1 git git 430080 May 14 22:22 1715696548_2024_05_14_15.9.3_gitlab_backup.tar
-rw-r--r--. 1 git git 430080 May 14 22:23 1715696608_2024_05_14_15.9.3_gitlab_backup.tar
[root@localhost gitlab]# ls -l /backup/gitlab/
total 156
-rw-r--r--. 1 root root 49438 May 14 22:21 gitlab-conf-2024-05-14_22:21:35.tar.gz
-rw-r--r--. 1 root root 49438 May 14 22:22 gitlab-conf-2024-05-14_22:22:34.tar.gz
-rw-r--r--. 1 root root 49438 May 14 22:23 gitlab-conf-2024-05-14_22:23:35.tar.gz
[root@localhost gitlab]# crontab -l # 查看当前用户下的定时任务
*/1 * * * * sh /root/gitlab/backup_gitlab.sh &> /dev/null
[root@localhost gitlab]# crontab -r # 删除当前用户下的定时任务
[root@localhost gitlab]# crontab -l
no crontab for root
  • 10
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值