未完成-AutoGhost

2016年1月11日 0 条评论 429 次阅读 0 人点赞
@echo off
:::::::::
::mail:sevenfal@163.com
::by lf
::2010_07_24_00_18
:::::::::
setlocal enabledelayedexpansion
color 0a
title AutoGhost_v1.0                     -by lf 2010_07_23
call :初始化
:主菜单
cls
echo.
echo.
echo  AutoGhost_v1.0
echo _____________________________________________________
echo.
echo           1. 备份          2. 恢复         
echo _____________________________________________________
echo.
echo                                 q.取消上次操作
set/p cho=选择(1/2/q):
>>%log% echo +主菜单选择 %cho%
if "%cho%"=="1" goto :备份菜单
if "%cho%"=="2" goto :恢复菜单
if /i "%cho%"=="q" goto :取消
goto :主菜单
:备份菜单
set "titl=AutoGhost_v1.0 备份                -by lf 2010_07_23"
title %titl%
::选择剩余空间最大的磁盘(超过1000G无法检测)
set max=0
for %%i in (%drivers%) do (
    for /f "tokens=3" %%j in ('dir %%i:') do set %%i1=%%j
    set %%i1=!%%i1:,=!
    set %%i1=!%%i1:~0,-2!
    if !%%i1! GTR !max! (
        set max=!%%i1!
        set 最大盘=%%i
    )
)
cls
echo.
echo.
echo            选择备份系统盘至:
echo _____________________________________________________
echo.
call set 磁盘菜单=%%drivers:%最大盘%=(%最大盘%)%%
echo %磁盘菜单%
>>%log% echo +磁盘菜单 %磁盘菜单%
echo _____________________________________________________
echo.
echo 其中磁盘可用空间最大的为 (%最大盘%)
echo.
set bfc=%drivers: =/%
set/p bf=选择(%bfc:~1%):
>>%log% echo +备份磁盘选择 %bf%
set lbf=%bf:~0,1%
echo %drivers% |find/i "%bf%" >nul
if %errorlevel%==1 goto :备份菜单
call :autoexec%cho%
call :开始操作
goto :eof

:恢复菜单
set "titl=AutoGhost_v1.0 恢复                -by lf 2010_07_23"
title %titl%
set agh=
cls
echo.
echo.
echo            检测到已存在gho文件:
echo _____________________________________________________
echo.
set num=
for %%a in (%drivers:~2%) do ( 
   echo %%a:\AutoGhost\^>
   pushd %%a:\AutoGhost\ 2>nul
   for /f "tokens=*" %%i in ('dir/b/a-d *.gho') do (
     set/a num+=1
     set !num!gho=!%%a!%%~pnxi
     set !num!gh=%%~fi
     echo    !num!.%%i
   )
   popd
)
echo _____________________________________________________
for /l %%i in (1 1 %num%) do set agh=!agh! %%i
>>%log% echo +存在gho文件
for /l %%i in (1 1 %num%) do >>%log% echo  !%%igh!
set agh=%agh: =/%
echo.
echo (此脚本只会搜索除系统盘外所有磁盘根目录中的AutoGhost文件夹中的gho文件,如需
echo   恢复某gho文件,须将其放置于除系统盘外任一磁盘根目录中的AutoGhost文件夹中)
echo.
set/p gho=选择(%agh:~1%):
set gho=%gho:~0,1%
echo %agh:~1% |find/i "%gho%" >nul
if !errorlevel!==1 goto :恢复菜单
>>%log% echo +已选择 !%gho%gh!
echo.
echo 已选择 !%gho%gh!
set/p sure=确定?(y/n):
>>%log% echo +确定 %sure%
if /i "%sure%" neq "y" goto :恢复菜单

::echo !%sysdriv%!
::pause
call :autoexec%cho%
call :开始操作
goto :eof
:初始化
cls
echo.
echo.
echo            初始化.请稍后...
set filename=%date:~0,4%_%date:~5,2%_%date:~8,2%_%time:~0,2%_%time:~3,2%
set filename=%filename: =0%
::部分变量处理
set 系统盘=%SystemDrive%
::盘符比获取开始
del/q diskpart\*.txt 2>nul
::取得现有可操作磁盘列表
echo list disk | diskpart.exe >diskpart\listdisk.txt
::取得现有可操作盘
for /f "tokens=2 skip=9" %%i in (diskpart\listdisk.txt) do set disk=%%i
::取得可操作盘分区列表
for /l %%i in (0 1 %disk%) do (
  echo select disk %%i>diskpart\%%i.txt
  echo detail disk>>diskpart\%%i.txt
  diskpart.exe /s diskpart\%%i.txt >diskpart\disk%%i.txt
  for /f "tokens=2,3 skip=17" %%a in (diskpart\disk%%i.txt) do echo %%b>>diskpart\p%%i.txt
)
::关联盘符和分区号
for /l %%i in (0 1 %disk%) do (
 set/a dri=%%i+1
 set volume=0
 for /f %%a in (diskpart\p%%i.txt) do (
   set/a volume+=1
   set %%a=!dri!:!volume!
   echo %%a !%%a!
   set drivers=!drivers! %%a
 )
)

echo %c% %d% %e% %f%
::文件夹预处理
for %%a in (%drivers%) do set last=%%a
::生成日志
set logp=%last%:\AutoGhost\log\%filename%\
set log=%logp%AutoGhost.log
md %logp%
>>%log% echo.
>>%log% echo __________________________________
>>%log% echo %filename%
>>%log% echo +系统盘 %系统盘%
>>%log% echo +存在磁盘 %drivers%
>>%log% echo +盘符比
for %%a in (%drivers%) do >>%log% echo  %%a !%%a!

 

rd/q/s %last%:\AutoGhost\boot.ini
rd/q/s %last%:\AutoGhost\autoexec.bat
md %last%:\AutoGhost\boot.ini >nul 2>nul
md %last%:\AutoGhost\autoexec.bat >nul 2>nul
set sysdriv=%drivers:~1,1%
>>%log% echo +系统盘确认 %sysdriv%
::处理boot.ini
set bak=AutoGhost\boot.bak
set boot=AutoGhost\boot.ini\boot.ini
set lf=AutoGhost\boot.ini\lf.ini
set bfbat=AutoGhost\autoexec.bat\bf.bat
set hfbat=AutoGhost\autoexec.bat\hf.bat
attrib -H -S -R %系统盘%\boot.ini
copy %系统盘%\boot.ini %last%:\%bak% /y
copy %last%:\%bak% %logp% /y
if exist %last%:\%bak% del/q %系统盘%\boot.ini
for /f "tokens=1,* delims==" %%i in (%last%:\%bak%) do (
    if "%%j"=="" (>>%last%:\%boot% echo %%i) else (
       if "%%i"=="C:\" (
          if not defined yes (
             set yes=1
             >>%last%:\%boot% echo %%i="AutoGhost"
          )
       ) else (>>%last%:\%boot% echo %%i=%%j)
    )
)
if not defined yes (>>%last%:\%boot% echo C:\="自动恢复_AutoGhost")
for /f "tokens=1,* delims==" %%i in (%last%:\%boot%) do (
    if "%%j"=="" (>>%last%:\%lf% echo %%i) else (
       if /i "%%i"=="default" (>>%last%:\%lf% echo %%i=C:\) else (
          if "%%j"=="" (>>%last%:\%lf% echo %%i) else (>>%last%:\%lf% echo %%i=%%j)
       )
    )
)
copy %last%:\%boot% %系统盘%\boot.ini /y
copy %last%:\%boot% %logp% /y
copy %last%:\%lf% %logp% /y
attrib +H +S +R %系统盘%\boot.ini
cls
echo.
echo.
echo                初始化完毕.
echo.
echo       +若获取盘符错误请重试
echo       +编写环境_WindowsXPSP2 
echo       +__by lf 2010_07_23
echo.
ping -n 3 127.1>nul 2>nul
goto :eof

:autoexec1
::备份时用autoexec.bat
attrib -H -S -R %系统盘%\autoexec.bat
>%last%:\%bfbat% echo prompt $p$g
>>%last%:\%bfbat% echo path %系统盘%\ghost;%系统盘%\;%系统盘%\windows;%系统盘%\windows\system32
>>%last%:\%bfbat% echo attrib -h -s -r %系统盘%\boot.ini
>>%last%:\%bfbat% echo copy %last%:\%bak% %系统盘%\boot.ini /y
>>%last%:\%bfbat% echo attrib +h +s +r %系统盘%\boot.ini
>>%last%:\%bfbat% echo Ghost.exe -clone,mode=pdump,src=!%sysdriv%!,dst=!%bf%!\AutoGhost\%filename%.gho -z9 -sure -rb
copy %last%:\%bfbat% %系统盘%\autoexec.bat /y
copy %last%:\%bfbat% %logp% /y
copy %系统盘%\autoexec.bat %logp% /y
attrib +H +S +R %系统盘%\autoexec.bat
goto :eof

:autoexec2
::备份时用autoexec.bat
attrib -H -S -R %系统盘%\autoexec.bat
>%last%:\%hfbat% echo prompt $p$g
>>%last%:\%hfbat% echo path %系统盘%\ghost;%系统盘%\;%系统盘%\windows;%系统盘%\windows\system32
>>%last%:\%hfbat% echo attrib -h -s -r %系统盘%\boot.ini
>>%last%:\%hfbat% echo copy %last%:\%bak% %系统盘%\boot.ini /y
>>%last%:\%hfbat% echo attrib +h +s +r %系统盘%\boot.ini
>>%last%:\%hfbat% echo Ghost.exe -clone,mode=pload,src=!%gho%gho!:1,dst=!%sysdriv%! -sure -rb
copy %last%:\%hfbat% %系统盘%\autoexec.bat /y
copy %last%:\%hfbat% %logp% /y
copy %系统盘%\autoexec.bat %logp% /y
attrib +H +S +R %系统盘%\autoexec.bat
goto :eof

:开始操作
>>%log% echo __________________________________
cls
attrib -h -s -r %系统盘%\boot.ini
copy %last%:\%lf% %系统盘%\boot.ini /y
attrib +H +S +R %系统盘%\boot.ini
echo.
echo.
echo +所有步骤已完成,请确认所选磁盘剩余空间是否满足备份或恢复.
echo +若想取消此次操作,重新运行此脚本选择相应选项即可
echo +如在操作中发生错误:
echo  打包%logp:~1%文件夹发至sevenfal@163.com
echo.
echo 手动重启以完成后续步骤
pause
goto :eof

:取消
for /f "tokens=1,* delims==" %%i in (%系统盘%\boot.ini) do (
    if "%%j"=="" (>>%logp%qx.ini echo %%i) else (
       if /i "%%i"=="default" (>>%logp%qx.ini echo %%i=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS) else (
          if "%%j"=="" (>>%logp%qx.ini echo %%i) else (>>%logp%qx.ini echo %%i=%%j)
       )
    )
)
attib -h -s -r %系统盘%\boot.ini
copy %logp%qx.ini %系统盘%\boot.ini /y
attrib +H +S +R %系统盘%\boot.ini
cls
echo.
echo.
echo               已取消上次操作.
ping -n 3 127.1>nul 2>nul
goto :eof

Sevenfal

这个人太懒什么东西都没留下

文章评论(0)