@echo off chcp 1251 >nul set filebkp=server call pass.bat user 1 call pass.bat pass 2 call pass.bat pwd 3 call pass.bat recipient 4 set mailsend=mailsend1.17b15.exe set i=1 set pathbkp=..\backup set pathtemp=..\temp set srvbkp=https://%user%:%pass%@webdav.yandex.ru/backup/%filebkp% set full=%filebkp%-full set inc=%filebkp%-inc set h=%TIME:~0,2% set m=%TIME:~3,2% set s=%TIME:~6,2% set ms=%TIME:~9,2% set curtime=%h%-%m%-%s% set dd=%DATE:~0,2% set mm=%DATE:~3,2% set yyyy=%DATE:~6,4% set curdate=%yyyy%-%mm%-%dd% set curdatetime=%curdate: =0%-%curtime: =0% call :loging "-----------------------------------" call :loging "Текущее время - %curdatetime%" call :loging "Создаем резервную копию текущих архивов" ren "%pathtemp%" temp-bkp md "%pathtemp%" call :loging "Создаем полный архив %full%.7z" 7z.exe a -xr0!*.log -xr0!*.bak -xr0!*.tmp "%pathtemp%\%full%".7z -r -mx1 "%pathbkp%\*" -%pwd% call :loging "Создаем резервную копию текущих архивов на сервере" curl.exe -k -X MOVE -H "Destination:/backup/%filebkp%"-bkp "%srvbkp%" -o .\stdout curl.exe -k -X MKCOL "%srvbkp%" -o .\stdout :upload call :loging "Попытка отправки номер %i%" call :loging "Отправляем на сервер файл %full%.7z" curl.exe -k -T "%pathtemp%\%full%".7z "%srvbkp%"/ --progress-bar -o .\stdout call :loging "Скачиваем файл %full%.7z с сервера для сравнения с исходным" curl.exe -k "%srvbkp%/%full%".7z -o "%pathtemp%"\test.7z --progress-bar -o .\stdout call :loging "Сравниваем скачанный файл с исходным" fc /LB1 /B "%pathtemp%\%full%".7z "%pathtemp%"\test.7z > nul if ERRORLEVEL 1 goto Different call :loging "Файлы одинаковы:" set tolog="%full%.7z успешно отправлен на сервер" call :loging %tolog% set mailsubject=%tolog:"=% call :loging "Удаляем устаревшие версии архива с компьютера и сервера" RD /s/q "%pathtemp%"-bkp curl.exe -k -X DELETE "%srvbkp%"-bkp -o .\stdout del /q "%pathtemp%"\test.7z goto exit :Different call :loging "Файлы различаются: %full%.7z на сервере НЕ совпадает с исходным" call :loging "Повторяем отправку" set /a i+=1 if %i% = 5 goto exit-f goto upload :exit-f set tolog="Отправка файла %full%.7z на сервер не удалась" call :loging %tolog% set mailsubject=%tolog:"=% call :loging "Восстанавливаем файлы предыдущего архива" RD /s/q "%pathtemp%" ren "%pathtemp%"-bkp temp curl.exe -k -X DELETE "%srvbkp%" -o .\stdout curl.exe -k -X MOVE -H "Destination:/backup/%filebkp%" "%srvbkp%"-bkp -o .\stdout :exit echo Отправляем лог %filebkp%-log.txt на сервер curl.exe -k -T %filebkp%-log.txt "%srvbkp%"/../ --progress-bar -o .\stdout echo Отправляем отчет в почту %mailsend% -to %recipient% -from %user%@yandex.ru -ssl -port 465 -auth -smtp smtp.yandex.ru -user %user% -pass %pass% -sub "%filebkp%: %curdatetime% - %mailsubject%" -cs "windows-1251" -mime-type "text/plain" -msg-body %filebkp%-log.tmp del /q %filebkp%-log.tmp exit :loging echo %~1 echo %~1 >> %filebkp%-log.txt echo %~1 >> %filebkp%-log.tmp exit /b
@echo off chcp 1251 >nul set filebkp=server call pass.bat user 1 call pass.bat pass 2 call pass.bat pwd 3 call pass.bat recipient 4 set mailsend=mailsend1.17b15.exe set tolog=zero set mailsubject=zero set i=1 set pathbkp=..\backup set pathtemp=..\temp set srvbkp=https://%user%:%pass%@webdav.yandex.ru/backup/%filebkp% set full=%filebkp%-full set inc=%filebkp%-inc set h=%TIME:~0,2% set m=%TIME:~3,2% set s=%TIME:~6,2% set ms=%TIME:~9,2% set curtime=%h%-%m%-%s% set dd=%DATE:~0,2% set mm=%DATE:~3,2% set yyyy=%DATE:~6,4% set curdate=%yyyy%-%mm%-%dd% set curdatetime=%curdate: =0%-%curtime: =0% call :loging "-----------------------------------" call :loging "Текущее время - %curdatetime%" call :loging "Создаем инкрементный архив %inc%-%curdatetime%.7z" 7z.exe u -xr0!*.log -xr0!*.bak -xr0!*.tmp "%pathtemp%\%full%".7z -u- -up3q3r2x2y2z0w2!"%pathtemp%\%inc%-%curdatetime%".7z "%pathbkp%\*" -%pwd% :upload call :loging "Попытка отправки номер %i%" call :loging "Отправляем архив на сервер" curl.exe -k -T "%pathtemp%\%inc%-%curdatetime%".7z "%srvbkp%"/ --progress-bar -o .\stdout call :loging "Скачиваем архив с сервера для сравнения с исходным" curl.exe -k "%srvbkp%/%inc%-%curdatetime%".7z -o "%pathtemp%"\test.7z --progress-bar -o .\stdout call :loging "Сравниваем скачанный архив с исходным" fc /LB1 /B "%pathtemp%\%inc%-%curdatetime%".7z "%pathtemp%"\test.7z > nul if ERRORLEVEL 1 goto Different call :loging "Файлы одинаковы" set tolog="%inc%-%curdatetime%.7z успешно отправлен на сервер" call :loging %tolog% set mailsubject=%tolog:"=% goto exit :Different call :loging "Файлы различаются: %inc%-%curdatetime%.7z на сервере НЕ совпадает с исходным" call :loging "Повторяем отправку" set /a i+=1 if %i% = 5 goto exit-f goto upload :exit-f set tolog="Отправка файла %inc%-%curdatetime%.7z на сервер не удалась" call :loging %tolog% set mailsubject=%tolog:"=% :exit del /q "%pathtemp%"\test.7z echo Отправляем лог %filebkp%-log.txt на сервер curl.exe -k -T %filebkp%-log.txt "%srvbkp%"/../ --progress-bar -o .\stdout echo Отправляем отчет в почту %mailsend% -to %recipient% -from %user%@yandex.ru -ssl -port 465 -auth -smtp smtp.yandex.ru -user %user% -pass %pass% -sub "%filebkp%: %mailsubject%" -cs "windows-1251" -mime-type "text/plain" -msg-body %filebkp%-log.tmp del /q %filebkp%-log.tmp exit :loging echo %~1 echo %~1 >> %filebkp%-log.txt echo %~1 >> %filebkp%-log.tmp exit /b
for /f "usebackq delims=" %%i in (`find /n /v "" "%~dp0"pass.txt ^| find "[%2]"`) do ( set newvar=%%i ) set %1=%newvar:~3%
Source: https://habr.com/ru/post/437794/