1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| outputLog() { logFile="/Users/shaoweinan154/wanjia2B/svnBackBash/SVNBackLog/svnBack.log" if [ ! -f "$logFile" ]; then touch "$logFile" echo "$1" >> $logFile else sed -i '' "1i\\ \\${1}\\ " $logFile fi open -a "Sublime Text" $logFile }
beginBackFile() { currentTime="`date +%Y-%m-%d`" rm -rf "/Users/shaoweinan154/wanjia2B/svnBackBash/SVNBackFile/.svn_${currentTime}" cp -rf "/Users/shaoweinan154/wanjia2B/.svn" "/Users/shaoweinan154/wanjia2B/svnBackBash/SVNBackFile/.svn_${currentTime}"
if [[ ! $? -eq 0 ]]; then outputLog " 备份出错 ${currentTime} " else outputLog " 备份成功 ${currentTime} " fi }
deleteOldBackFile() { Folder="/Users/shaoweinan154/wanjia2B/svnBackBash/SVNBackFile/" SubFolder=$(ls -a ${Folder}) SubFolderArray=(${SubFolder}) ArrayLength=${#SubFolderArray[@]}
TotalBack=0 for (( i=${ArrayLength}-1; i>=0; i-- )); do dir=${SubFolderArray[$i]} if [[ $dir == .svn_* ]]; then let TotalBack++ if (( ${TotalBack} > 10 )); then rm -rf "/Users/shaoweinan154/wanjia2B/svnBackBash/SVNBackFile/${dir}" if [[ ! $? -eq 0 ]]; then outputLog " 删除出错 ${dir} " else outputLog " 删除成功 ${dir} " fi fi fi done }
beginBackFile
deleteOldBackFile
|