对svn服务端托管库进行完全恢复shell脚本

 


#!/bin/sh 

# Description: Download the backup file and restore from the FTP server 
# Require: SVN environment is normal 

#SVN_USER="svn"
SVN_BASICDIR="/usr/bin"
#YESTERDAY=`date -d'1 days ago' +%Y%m%d` 
SVNDIR="/var/svn"
DOWNLOAD_DIR="/data/svnbak"
LOGFILE="${DOWNLOAD_DIR}/svn_recover.log"
CONFIG_BASE="/etc/svn"
  
#FTPHOST="x.x.x.x"
#FTPPORT="x"
#FTPUSER="xxx"
#FTPPASSWD="xxxxxx"
#FTPDOCUMENT="xxx"
  
#! type lftp &> /dev/null && echo "Lftp command does not exist,Plz install lftp." && exit 128
  
[ ! -d ${DOWNLOAD_DIR} ] && mkdir -p ${DOWNLOAD_DIR} 
  
make_log() { 
    /bin/echo -e "[ $(date +%Y-%m-%d' '%H:%M:%S) ] ${1}" >> ${LOGFILE} 

  
#ftp_download() { 
    ############################ 
    # Backup file download 
#    cd ${1} 
    #echo "Start download file: `date`" 
  
#/usr/bin/lftp << EOF 
#open -p $FTPPORT ftp://$FTPUSER:$FTPPASSWD@$FTPHOST/$FTPDOCUMENT 
#mirror -i ${YESTERDAY}.*.tgz 
#EOF 
#    cd    
    #echo "Download file end: `date`" 
    ############################ 
#} 
  
#extract() { 
#    cd ${1} 
#    make_log "tar xf *.tgz"
#    tar xf *.tgz &> /dev/null 
#    make_log "rm -f *.tgz"
#    rm -f *.tgz &> /dev/null 
#} 
  
  
#ftp_download "${DOWNLOAD_DIR}"
cd ${DOWNLOAD_DIR}
ls -al ${DOWNLOAD_DIR}
read -p "Please Input Recover File:" file


tar xf $file &>/dev/null


BAKDIR=`echo $file | awk -F "." '{print $1}'`
cd $BAKDIR 
ls -al
 


if [  -d ${DOWNLOAD_DIR}/${BAKDIR}  ];then 
    # 
    # Recover SVN Project 
    make_log "=========== [`date +%Y/%m/%d' '%H:%M`] Start Recover ==========="
    for _project_ in `ls -lh ${DOWNLOAD_DIR}/${BAKDIR} | grep "^d" | awk '{print $NF}'`; do 
        if [ ! -d ${SVNDIR}/${_project_} ];then 
            make_log "mkdir -p ${SVNDIR}/${_project_}"
            mkdir -p ${SVNDIR}/${_project_} &> /dev/null 
        else
            make_log "Project directory exist."
            echo "Project directory exist."
            exit 127
        fi 
        make_log "${SVN_BASICDIR}/svnadmin hotcopy ${DOWNLOAD_DIR}/${BAKDIR}/${_project_} ${SVNDIR}/${_project_}"
        ${SVN_BASICDIR}/svnadmin hotcopy ${DOWNLOAD_DIR}/${BAKDIR}/${_project_} ${SVNDIR}/${_project_} &> /dev/null 
        make_log "${SVN_BASICDIR}/svnlook youngest ${SVNDIR}/${_project_}"
        ${SVN_BASICDIR}/svnlook youngest ${SVNDIR}/${_project_} &> /dev/null 
        if [ $? != 0 ];then 
            make_log "Recover Failed."
            echo "Recover Failed."
            exit 125
        fi 
    done 
    echo "" >> ${LOGFILE} 
    # 
    # Copy configuration file 
    for _config_file_ in `ls -lh ${DOWNLOAD_DIR}/${BAKDIR} | grep "^-" | awk '{print $NF}'`; do 
        #make_log "cp ${DOWNLOAD_DIR}/${BAKDIR}/${_config_file_} ${SVNDIR}" 
        #make_log "chown svn.svn ${SVNDIR}/${_config_file_}" 
        cp -rf ${DOWNLOAD_DIR}/${BAKDIR}/${_config_file_} ${CONFIG_BASE}/ 
    done 
    #make_log "chown -R ${SVN_USER}.${SVN_USER} ${SVNDIR}"
    #make_log "rm -rf ${DOWNLOAD_DIR}/${BAKDIR}"
    #rm -rf ${DOWNLOAD_DIR}/${BAKDIR} 
    #chown -R ${SVN_USER}.${SVN_USER} ${SVNDIR} &> /dev/null 
    make_log "=========== [`date +%Y/%m/%d' '%H:%M`] Recover Finish ==========="
    echo "" >> ${LOGFILE} 
    echo "Recover SVN Project successfull." 
else
    make_log "Download Backup File Failed."
    echo "" >> ${LOGFILE} 
    echo "Download Backup File Failed.Plz Check..."
    exit 122
fi 
分割线
感谢打赏
江西数库信息技术有限公司
YWSOS.COM 平台代运维解决方案
 评论
 发表评论
姓   名:

Powered by AKCMS