gitlab自动备份

2018-12-14  本文已影响0人  sunix

为了防止gitlab服务器硬盘损坏等问题导致代码丢失,最好定时自动备份git仓库并保存在远程文件服务器上,下面是我的配置过程

在ubuntu中默认的gitlab仓库是在 /var/opt/gitlab/git-data/repositories 中,gitlab的备份文件保存在 /var/opt/gitlab/backups 之中

我这里gitlab服务器挂载了两块硬盘,git仓库在第一块硬盘(/),于是我想要将gitlab的备份放在第二块硬盘中(/backups).如果没有这样的需求,只是将git备份在远程服务器的话,这一步可以省略.

我这边设置的在每天的凌晨2点进行备份

    sudo echo "0 2 * * * root /home/gitlab/auto-backup.sh -D 1" >> /etc/crontab
    sudo service cron restart

修改自动备份脚本 auto-backup.ssh ,在备份完成后将文件copy到远程文件服务器

    echo "sshpass -p $remote_password scp -r /backups $remote_user@$remote_host:$dir" >> /home/gitlab/auto-backup.sh

这里 $remote_password 替换成远程服务器的登录密码, $remote_user 是远程服务器登录用户, $remote_host 是远程服务器域名或IP, $dir 是远程服务器的保存目录

至此,gitlab服务器的备份硬盘和远程文件服务器上都有一份gitlab的备份文件

上一篇 下一篇

猜你喜欢

热点阅读