Bash

svn 備份 bash 腳本錯誤

  • April 17, 2013

我已經創建了 bash 腳本來創建 svn 儲存庫的轉儲。我想添加這樣的功能,在每個儲存庫腳本轉儲後使用 rsync 將其發送到遠端伺服器並從轉儲位置刪除,然後開始轉儲下一個儲存庫。我正在使用以下腳本。

腳本有一些錯誤幫助我改進它。

#!/bin/sh

# Record todays date
# --------------------
bakdate=$(date +%Y%m%d)
echo "--------------------------------"
echo "Running SVN backup $bakdate"
echo "--------------------------------\n"

# From where to backup repos?
# ---------------------------
svnrepos="/kk/svn/"
echo "\nGoing to backup all SVN repos located at: $svnrepos \n"

# Where to save the dump?
# ------------------------
bakdest="/save/"

# Location of remote server (to copy backup)
# ----------------------------------------
baktoremote="root@192.168.11.156:/kk"

  cd $svnrepos


# Just make sure we have write access to backup-folder
if [ -d "$bakdest" ] && [ -w "$bakdest" ] ; then
 # Now $repo has folder names = project names
 for repo in *; do
   # do svn dump for each project
   echo "Taking backup/svndump for: $repo"
   echo "Executing : svnadmin dump $repo >
$bakdest/$repo-$bakdate.dump \n"
   # Now finally execute the backup
   svnadmin dump $repo > $bakdest/$repo-$bakdate.dump


# Just make sure we have write access to backup-folder
if [ -d "$bakdest" ] && [ -w "$bakdest" ] ; then
 # Now $repo has folder names = project names
 for repo in *; do
   # do svn dump for each project
   echo "Taking backup/svndump for: $repo"
   echo "Executing : svnadmin dump $repo >
$bakdest/$repo-$bakdate.svn.dump \n"
   # Now finally execute the backup
   svnadmin dump $repo > $bakdest/$repo-$bakdate.dump

   # sent it to remote server 

rsync -avP $bakdest/$repo-$bakdate.dump $baktoremote



 # delete repository after sending  

   rm -rf $repo-$bakdate.dump

   fi

結束你的 if 塊fi

結束你的循環done

每個都if必須匹配一個fi,每個都do必須匹配一個done

引用自:https://unix.stackexchange.com/questions/72706