gitlab 备份恢复脚本
作者:互联网
1.gitlab 服务备份脚本和恢复
#!/bin/bash
backupDir="/chj/data/BackupData"
function checkNewFile(){
find $backupDir -name "*_gitlab_backup.tar"|head -1|xargs rm -vf
}
function restoreCopyData(){
restoreDir=$(ls -ltd /mnt/tools/bakups/* |awk '{if(NR<=1){print $9}}')
yes|cp -rpf $restoreDir $backupDir
}
function stopConnection(){
gitlab-ctl stop sidekiq
gitlab-ctl stop unicorn
}
function restoreData(){
cd $backupDir
gitlab-rake gitlab:backup:restore
}
function bakcupGitlab(){
cd $backupDir
gitlab-rake gitlab:backup:create
}
function startService(){
gitlab-ctl reconfigure
gitlab-ctl restart
}
function main(){
checkNewFile
restoreCopyData
stopConnection
restoreData
startService
}
case $1 in
"all")
main $*
;;
"CheckNewFile")
checkNewFile
;;
"restartService")
startService
;;
"restoreData")
checkNewFile
stopConnection
restoreCopyData
;;
"bakcupGitlab")
bakcupGitlab
;;
*)
echo -e "\033[32m 参数如下: \033[0m"
echo -e "\033[32m CheckNewFile \033[0m 检查数据文件,清理历史文件"
echo -e "\033[32m startService \033[0m 重启系统服务"
echo -e "\033[32m restoreData \033[0m 恢复gitlab数据"
echo -e "\033[32m bakcupGitlab \033[0m 备份gitlab数据"
;;
esac
标签:脚本,function,tar,备份,gitlab,backupDir 来源: https://blog.51cto.com/breaklinux/2564101