gitlab 備份恢復腳本

1.gitlab 服務備份腳本和恢復git

#!/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
相關文章
相關標籤/搜索