首页 / GIT / Gitlab 定时备份
Gitlab 定时备份
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Gitlab 定时备份,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3922字,纯文字阅读大概需要6分钟。
内容图文
要求
1.为了能够备份和恢复,请确保你的系统上安装了Rsync
#Debian/Ubauntu
sudo apt-get install rsync
# RHEL/Centos
sudo yum install rsync
2.配置了与备份目标机器之间的免密认证
修改gitlab配置文件:
vim /etc/gitlab/gitlab.rb
#指定备份后数据存放的路径、权限、时间配置
gitlab_rails[‘manage_backup_path‘] = true #292行 开启备份功能
gitlab_rails[‘backup_path‘] = "/opt/gitlab_backup" #293行 指定备份的路径
gitlab_rails[‘backup_archive_permissions‘] = 0644 #296行 备份文件的权限
gitlab_rails[‘backup_keep_time‘] = 7776000 #301行 备份保留时间(保留90天 单位:秒
创建备份目录并授权:
mkdir /opt/gitlab_backups && chown -R git.git /opt/gitlab_backups/
重新生效Gitlabb配置:
gitlab-ctl reconfigure
手动备份:
[root@gitlabdev ~]# gitlab-backup create
2021-06-15 10:37:09 +0800 -- Dumping database ...
Dumping PostgreSQL database gitlabhq_production ... [DONE]
2021-06-15 10:37:12 +0800 -- done
2021-06-15 10:37:12 +0800 -- Dumping repositories ...
* eda_groups/naura_eda (@hashed/3f/db/3fdba35f04dc8c462986c992bcf875546257113072a909c162f7e470e581e278) ...
* eda_groups/naura_eda (@hashed/3f/db/3fdba35f04dc8c462986c992bcf875546257113072a909c162f7e470e581e278) ... [DONE]
* eda_groups/naura_eda.wiki (@hashed/3f/db/3fdba35f04dc8c462986c992bcf875546257113072a909c162f7e470e581e278.wiki) ...
* eda_groups/naura_eda.wiki (@hashed/3f/db/3fdba35f04dc8c462986c992bcf875546257113072a909c162f7e470e581e278.wiki) ... [EMPTY] [SKIPPED]
* eda_groups/naura_eda.design (@hashed/3f/db/3fdba35f04dc8c462986c992bcf875546257113072a909c162f7e470e581e278.design) ...
* eda_groups/naura_eda.design (@hashed/3f/db/3fdba35f04dc8c462986c992bcf875546257113072a909c162f7e470e581e278.design) ... [EMPTY] [SKIPPED]
2021-06-15 10:37:15 +0800 -- done
2021-06-15 10:37:15 +0800 -- Dumping uploads ...
2021-06-15 10:37:15 +0800 -- done
2021-06-15 10:37:15 +0800 -- Dumping builds ...
2021-06-15 10:37:15 +0800 -- done
2021-06-15 10:37:15 +0800 -- Dumping artifacts ...
2021-06-15 10:37:15 +0800 -- done
2021-06-15 10:37:15 +0800 -- Dumping pages ...
2021-06-15 10:37:15 +0800 -- done
2021-06-15 10:37:15 +0800 -- Dumping lfs objects ...
2021-06-15 10:37:15 +0800 -- done
2021-06-15 10:37:15 +0800 -- Dumping container registry images ...
2021-06-15 10:37:15 +0800 -- [DISABLED]
Creating backup archive: 1623724635_2021_06_15_13.12.3_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)
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.
ps:这里提示 gitlab.rb 和 gitlab-secrets.json 包涵敏感数据需要手动备份
查看备份:
ll -sh /opt/gitlab_backups/
编写备份脚本,结合crontab实施自动定时备份,比如每天0点、6点、12点、18点各备份一次
编写备份脚本:
#!/usr/bin/bash
locale_date=`date +%Y-%m-%d_%H:%M:%S`
backup_host=192.168.101.133
backup_path=/opt/gitlab_backups/${locale_date}
#CRON=1 环境变量CRON=1的作用是如果没有任何错误发生时, 抑制备份脚本的所有进度输出
#BACKUP=${locale_date}改变backup文件名称 例: 2021-06-15_11:22:52_gitlab_backup.tar
/opt/gitlab/bin/gitlab-backup create BACKUP=${locale_date} CRON=1
ssh root@${backup_host} ls ${backup_path} > /dev/null 2\>\&1
if [ $? -eq 0 ];then
scp ${backup_path}_gitlab_backup.tar root@${backup_host}:${backup_path}
scp /etc/gitlab/gitlab-secrets.json root@${backup_host}:${backup_path}
scp /etc/gitlab/gitlab.rb root@${backup_host}:${backup_path}
else
ssh root@${backup_host} mkdir -p ${backup_path}
scp ${backup_path}_gitlab_backup.tar root@${backup_host}:${backup_path}
scp /etc/gitlab/gitlab-secrets.json root@${backup_host}:${backup_path}
scp /etc/gitlab/gitlab.rb root@${backup_host}:${backup_path}
fi
[root@gitlabdev ~]# chmod +x /opt/gitlab_backups/gitlab_back.sh
加入定时任务:
crontab -e #添加定时任务
crontab -l #查看已添加定时任务
[root@gitlabdev ~]# crontab -l
0 0,6,12,18 * * * /bin/bash /opt/gitlab_backups/gitlab_back.sh > /dev/null 2>&1
GItlab只能还原到与备份文件相同的gitlab版本。
原文:https://www.cnblogs.com/afei654138148/p/14884439.html
内容总结
以上是互联网集市为您收集整理的Gitlab 定时备份全部内容,希望文章能够帮你解决Gitlab 定时备份所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。