要求
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_backups" #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} 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}
[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.uj5u.com/qita/287555.html
標籤:其他
下一篇:Prim演算法實作最小生成樹
