Rick0

#2_RETORNAR_BKP_HD

Oct 4th, 2019 (edited)
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 3.29 KB | None | 0 0
  1. @ECHO off
  2. TITLE RESTAURANDO BACKUP DO HD EXTERNO...
  3. ::Elevando privilegio para executar o Robocopy
  4. pushd "%~dp0"
  5. if not "%1"=="am_admin" (%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\powershell.exe start -verb runas '%0' am_admin & exit /b)  
  6. ::taskkill /f /fi "USERNAME eq %username%" /fi "IMAGENAME ne mstsc.exe" /fi "IMAGENAME ne explorer.exe" /fi "IMAGENAME ne %~nx0" /fi "IMAGENAME ne cmd.exe" /fi "IMAGENAME ne conhost.exe" /fi "IMAGENAME ne notepad.exe" /fi "IMAGENAME ne robocopy.exe" &CLS >nul
  7. :USUARIO
  8. SETLOCAL
  9. SET "ID="
  10. TITLE SELECIONE A PASTA PARA RESTAURAR O BACKUP
  11. CLS
  12. :: Interacao do USUARIO para selecionar a pasta de backup
  13. set "psCommand="(new-object -COM 'Shell.Application')^.BrowseForFolder(0,'SELECIONE A PASTA:','^&H200','%~d0\BACKUP\OK').Self.Path""
  14. for /f "usebackq delims=" %%I in (`%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\powershell.exe %psCommand%`) do set "ID=%%I"
  15. CLS
  16. :: Salva o nome da pasta na variavel IDS a variavel ID e o caminho completo da pasta
  17. for %%d in ("%ID%") do set "IDS=%%~nxd"
  18. :: Checa Se o valor informado e nulo caso seja solicita novamente
  19. IF DEFINED ID (goto CONTINUE) else (goto USUARIO)
  20. :CONTINUE
  21. TITLE Retornando Backup de ["%IDS%"]
  22. :: Checa Se existe a pasta caso nao exista questiona se que salvar o backup em outro local
  23. IF NOT EXIST "%SYSTEMDRIVE%\Users\%IDS%" CHOICE /c SN /T 10 /D S /m "Nao existe "%SYSTEMDRIVE%\Users\%IDS%" deseja Salvar BACKUP na pasta "%SYSTEMDRIVE%\BACKUP\OK\%IDS%"?"
  24. TITLE Restaurando Backup de ["%IDS%"]
  25. IF %ERRORLEVEL% EQU 1 (CLS & goto BACKUPPST)
  26. IF %ERRORLEVEL% EQU 2 (ECHO Nao foi Possivel Concluir o Backup... & ECHO.& TIMEOUT 7 & EXIT)
  27.  
  28. IF EXIST "%SYSTEMDRIVE%\Users\%IDS%" CHOICE /c SN /T 10 /D S /m "Deseja Restaurar o Backup na pasta "%SYSTEMDRIVE%\Users\%IDS%"?"
  29. TITLE Restaurando Backup de ["%IDS%"]
  30. IF %ERRORLEVEL% EQU 1 (CLS & goto BACKUP)
  31. IF %ERRORLEVEL% EQU 2 (ECHO Nao foi Possivel Concluir o Backup... & ECHO.& TIMEOUT 7 & EXIT)
  32.  
  33. :BACKUP
  34. CLS
  35. ECHO Backup Sendo Restaurado Aguarde...
  36. SET "LOCAL=%SYSTEMDRIVE%\Users\%IDS%"
  37. SET "LOGBKP=%~d0\BACKUP\OK\OK.log"
  38. TITLE Fazendo Backup de ["%ID%"] para ["%LOCAL%"]
  39. robocopy "%ID%" "%LOCAL%" /E /ZB /DCOPY:T /FFT /DST /XA:SH /R:1 /W:1 /NP /TEE /FP /NJH /XX /LOG+:"%LOGBKP%"
  40. CLS
  41. GOTO STICK
  42.  
  43. :BACKUPPST
  44. SET "LOCAL=%SYSTEMDRIVE%\BACKUP\OK\%IDS%"
  45. SET "LOGBKP=%~d0\backup\OK\OK.log"
  46. robocopy "%ID%" "%LOCAL%" /E /ZB /DCOPY:T /FFT /DST /XA:SH /XJD /XJF /R:1 /W:1 /NP /TEE /FP /NJH /XX /LOG+:"%LOGBKP%"
  47. GOTO STICK
  48. :STICK
  49. IF EXIST "%ID%\AppData\Roaming\Microsoft\Sticky Notes\*.snt" ECHO f| xcopy /R /S /H /D /V /Y /I /O /F "%ID%\AppData\Roaming\Microsoft\Sticky Notes\*.snt" "%LOCAL%\AppData\Roaming\Microsoft\Sticky Notes\*.snt"> nul
  50. IF EXIST "%ID%\AppData\Local\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalState\*.*" ECHO f| xcopy /R /O /E /H /D /V /Y /I "%ID%\AppData\Local\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalState\*.*" "%LOCAL%\AppData\Local\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalState\*.*"> nul
  51. CLS
  52. GOTO ESCOLHA
  53. :ESCOLHA
  54. CHOICE /c SN /T 10 /D N /m "Deseja Restaurar Outro Backup?"
  55. IF %ERRORLEVEL% EQU 1 (CLS & GOTO USUARIO)
  56. IF %ERRORLEVEL% EQU 2 (ECHO. & ECHO Backup Restaurado... & ECHO. &ECHO #Backup "%LOCAL%" &ECHO #Log %~d0\backup\OK.log & TIMEOUT 3 & goto END)
  57. :END
  58. explorer "%LOCAL%" & ENDLOCAL & EXIT
Add Comment
Please, Sign In to add comment