如题自己写了一个小工具,这里是其中的一段使用shadowscopy进行备份的代码,问下有没精简的方案
注:精简的话主要在针对盘符上,但要考虑映射驱动器的问题.我这个脚本适合在我的工作环境中使用,所有机器都分两个盘,所以没什么麻烦事.当然如果能识别映射驱动器的话就更好.
代码如下:- @echo off & setlocal enabledelayedexpansion
- set sc=c:\temp\shadowsc.txt
- set sd=c:\temp\shadowsd.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
复制代码 此脚本只能在管理员权限下运行,整个完整的脚本我是使用计划任务来进行的. |