Rick0

#1_FAZER_BKP_HD

Oct 4th, 2019 (edited)
544
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 3.30 KB | None | 0 0
  1. @ECHO off
  2. TITLE SCRIPT BACKUP HD EXTERNO..
  3. ::Elevando privilegio para executar o Robocopy
  4. setlocal EnableDelayedExpansion
  5. pushd "%~dp0"
  6. SET "PSW=%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\powershell.exe"
  7. if not "%1"=="am_admin" (%PSW% start -verb runas '%0' am_admin & exit /b)  
  8. ::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
  9. :USUARIO
  10. SETLOCAL
  11. SET "ID="
  12. TITLE SELECIONE A PASTA PARA REALIZAR O BACKUP
  13. CLS
  14. :: Interacao do USUARIO para selecionar a pasta de backup
  15. set "psCommand="(new-object -COM 'Shell.Application')^.BrowseForFolder(0,'SELECIONE A PASTA:','^&H200','').Self.Path""
  16. for /f "usebackq delims=" %%I in (`%PSW% %psCommand%`) do set "ID=%%I"
  17. :: Checa Se o valor informado e nulo caso seja solicita novamente que seja informado caso nao prossegue
  18. ::IF DEFINED ID (GOTO CONTINUE) else (GOTO USUARIO)
  19. IF NOT EXIST "%ID%" (GOTO USUARIO) ELSE (GOTO CONTINUE)
  20.  
  21. :CONTINUE
  22. for /f %%d in ('%PSW% -c "$env:ID.length"') do SET "LEN=%%d"
  23. IF %LEN% LEQ 3 (SET "IDS=%ID::\=%" & SET "ORIGEM=%ID:\=%" ) ELSE (for %%d in ("%ID%") do set "IDS=%%~nxd" SET & SET "ORIGEM=%ID%")
  24. TITLE Fazendo Backup de ["%ID%"]
  25. IF "%NEO%"=="1" (GOTO BACKUP)
  26. :: Questiona o USUARIO se ele quer apagar bkps antigos ou nao e valida somente com S/N
  27. for /F %%i in ('dir "%~d0\BACKUP\OK\*" /O-D /B /A:D') do set CHK=%%i
  28. IF NOT DEFINED %CHK% choice /c SN /T 10 /D N /m "Deseja Deletar bkps antigos da pasta %~d0\BACKUP\OK do hd externo?"
  29. IF %ERRORLEVEL% EQU 1 (forfiles /P "%~d0\BACKUP\OK" /M * /C "cmd /c if @isdir==TRUE rmdir /S /Q @file" & GOTO BACKUP)
  30. IF %ERRORLEVEL% EQU 2 (IF NOT EXIST "%~d0\BACKUP\OK\" md "%~d0\BACKUP\OK\" & GOTO BACKUP)
  31.  
  32. :BACKUP
  33. IF NOT EXIST "%~d0\BACKUP\OK\" md "%~d0\BACKUP\OK\"
  34. SET "DESTINO=%~d0\BACKUP\OK\%IDS%"
  35. SET "LOGBKP=%~d0\backup\OK\copia.log"
  36. TITLE Fazendo Backup de ["%ORIGEM%"] para ["%DESTINO%"]
  37. ECHO Backup Sendo Efetuado para "%DESTINO%" Aguarde...
  38. Robocopy "%ORIGEM%" "%DESTINO%" /S /ZB /DCOPY:T /FFT /DST /XA:SH /XJD /XJF /R:3 /XF "*.tmp" /XD "All Users" "DefaultAppPool" "Public" "administrator" "default" "Links" "WFMData" ".swt" "AppData" "Contacts" "Searches" /NP /TEE /FP /NJH /XX /LOG+:"%LOGBKP%"
  39. IF EXIST "%ID%\AppData\Roaming\Microsoft\Sticky Notes\*.snt" ECHO f|xcopy /R /S /H /D /V /Y /O /F "%ID%\AppData\Roaming\Microsoft\Sticky Notes\*.snt" "%~d0\BACKUP\OK\%IDS%\AppData\Roaming\Microsoft\Sticky Notes\*.snt"> nul
  40. IF EXIST "%ID%\AppData\Local\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalState\plum.sqlite" ECHO f|xcopy /R /S /H /D /V /Y /O /F "%ID%\AppData\Local\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalState\*.*" "%~d0\BACKUP\OK\%IDS%\AppData\Local\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalState\*.*"> nul
  41. IF EXIST "%~d0\BACKUP\OK\%IDS%\AppData\" attrib +h +s "%~d0\BACKUP\OK\%IDS%\AppData" /S /D> nul
  42. CLS
  43. GOTO ESCOLHA
  44.  
  45. :ESCOLHA
  46. choice /c SN /T 10 /D N /m "Deseja Realizar um novo Backup?"
  47. IF %ERRORLEVEL% EQU 1 (CLS & SET "NEO=1" & GOTO USUARIO)
  48. IF %ERRORLEVEL% EQU 2 (ECHO. & ECHO Backup Concluido... & ECHO. &ECHO #Backup %DESTINO% &ECHO #Log %LOGBKP% & TIMEOUT 3 & GOTO END)
  49. :END
  50. explorer "%~d0\BACKUP\OK\" & ENDLOCAL & POPD & EXIT
Add Comment
Please, Sign In to add comment