在Linux系统中,GitLab的备份与恢复可以通过以下步骤进行:
使用gitlab-rake命令进行备份
gitlab-rake gitlab:backup:create
/var/opt/gitlab/backups/
目录下,但可以修改默认路径。定时备份
crontab
定时执行备份任务。/var/opt/gitlab/backups/gitlabbak.sh
:#!/bin/bash
/opt/gitlab/bin/gitlab-rake gitlab:backup:create
sleep 10
find /var/opt/gitlab/backups -name "*.tar" -type f -mtime +10 -exec rm -rf {} \;
crontab
每周执行备份任务。备份到远程服务器
scp
或其他文件传输工具将备份文件传输到远程服务器。auto_backup_gitlabdata_to_remote.sh
:#!/bin/bash
BACKUP_DIR="/var/opt/gitlab/backups"
RemoteBackDir="/mnt/backups/gitlab_backups/remote"
RemoteUser="root"
RemotePort="22"
RemoteIP="192.168.0.222"
Date=$(date +"%F-%T")
LogFile="/var/log/gitlab_backup.log"
find $BACKUP_DIR -type f -mtime -1 -name "*.tar" -exec scp {} $RemoteUser@$RemoteIP:$RemoteBackDir \;
停止GitLab服务
unicorn
和 sidekiq
服务以确保数据一致性。gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
恢复备份
/var/opt/gitlab/backups/
目录下。gitlab-rake
命令进行恢复。gitlab-rake gitlab:backup:restore BACKUP=备份编号
1560350286_gitlab_backup.tar
对应的备份编号是 1560350286
。启动GitLab服务
unicorn
和 sidekiq
服务。gitlab-ctl start unicorn
gitlab-ctl start sidekiq