
分享一段自己寫的自動備份批處理代碼順便求精簡如題自己寫了一個小工具,這里是其中的一段使用shadowscopy進行備份的代碼,問下有沒精簡的方案注:精簡的話主要在針對盤符上,但要考慮映射驅動器的問題.我這個腳本適合在我的工作環境中使用,所有機器都分兩個盤,所以沒什么麻煩事.當然如果能識別映射驅動器的話就更好.代碼如下:
此腳本只能在管理員權限下運行,整個完整的腳本我是使用計劃任務來進行的.nclick="copycode($('code0'));">復制代碼
- @echo off & setlocal enabledelayedexpansion
- set sc=c:tempshadowsc.txt
- set sd=c:tempshadowsd.txt
- set tp=%temp%tmp.tmp
- (
- if not exist %sc% for /f tokens=2 delims={} %%i in ('^(vssadmin list shadows /for^=c:^|find Copy ID:^)^|^|^(vssadmin list shadows /for^=c:^|find 副本 ID:^)') do echo.%%i>>%sc%
- for /f %%i in ('find /v /c ^<%sc%') do (
- if %%i LEQ 6 goto :nextc
- set /a line=%%i-6
- for /f %%i in (%sc%) do (
- set id=%%i
- set /a a+=1
- vssadmin delete shadows /shadow={!id!} /quiet
- if !a! equ !line! more +!line! %sc%>%tp% && move /y %tp% %sc%>nul & goto :nextc
- )
- )
- :nextc
- for /f tokens=2 delims={} %%i in ('wmic shadowcopy call create clientaccessible^,c:^|find ShadowID') do echo.%%i>>%sc%
- if exist d: (
- if not exist %sd% for /f tokens=2 delims={} %%i in ('^(vssadmin list shadows /for^=d:^|find Copy ID:^)^|^|^(vssadmin list shadows /for^=d:^|find 副本 ID:^)') do echo.%%i>>%sd%
- for /f %%i in ('find /v /c ^<%sd%') do (
- if %%i LEQ 6 goto :nextd
- set /a line=%%i-6
- for /f %%i in (%sd%) do (
- set id=%%i
- set /a a+=1
- vssadmin delete shadows /shadow={!id!} /quiet
- if !a! equ !line! more +!line! %sd%>%tp% && move /y %tp% %sd%>nul & goto :nextd
- )
- )
- :nextd
- for /f tokens=2 delims={} %%i in ('wmic shadowcopy call create clientaccessible^,d:^|find ShadowID') do echo.%%i>>%sd%
- )
- )>nul

