backup.cmd 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. @echo off
  2. chcp 65001
  3. ::cls
  4. ::color A
  5. ::setlocal EnableExtensions
  6. ::setlocal ENABLEDELAYEDEXPANSION
  7. set FILENAME=%~1
  8. if not defined FILENAME set FILENAME=backup
  9. set SRCPATH=%~2
  10. if not defined SRCPATH set SRCPATH=%~dp0
  11. set DESTPATH=%~3
  12. if not defined DESTPATH set DESTPATH=%~dp0
  13. set TMPPATH=%~4
  14. if not defined TMPPATH set TMPPATH=%TMP%
  15. set PASSWORD=111
  16. ::set compress_cmd="%ProgramFiles%\WinRAR\winrar.exe"
  17. ::set "compress_keys=-r -u -dh -rr10p -qo+ -y -se -scUL -p%PASSWORD% -ep2 -ma -m5 -IBCK -INUL -x*\Thumbs.db -w%TMPPATH% -ilog%DESTPATH%%FILENAME%.error.log "
  18. set compress_cmd="%ProgramFiles%\7-Zip\7z.exe"
  19. set "compress_keys=-mx9 -ms=on -mqs=on -mhc=on -mhe=on -mmt=on -spf2 -t7z -ssw -y -p%PASSWORD% -scrcSHA256 -sccUTF-8 -scsUTF-8 -x!*\Thumbs.db -w%TMPPATH%"
  20. :: -ms=on -mqs=on -mhc=on -mhe=on -mmt=on
  21. if not exist "%SRCPATH%" call :PRINT_USAGE
  22. if not exist "%DESTPATH%" ( md "%DESTPATH%" || exit /b )
  23. if not exist "%TMPPATH%" ( md "%TMPPATH%" || exit /b )
  24. :: Main
  25. echo.Creating backup...
  26. %compress_cmd% u %compress_keys% -- "%DESTPATH%%FILENAME%.7z" @"%SRCPATH%%FILENAME%.lst
  27. if errorlevel 1 ( @echo. && @echo.ERROR! Process %compress_cmd% failed. Code: %errorlevel% )
  28. type %DESTPATH%%FILENAME%.error.log 2>NUL
  29. echo.&pause&goto:eof
  30. :PRINT_USAGE
  31. echo:
  32. echo USAGE:
  33. echo %~n0 ^<filename> ^<source path^> ^<destination path^> [temp_dir]
  34. exit /b !ERRORLEVEL!