Создай папку backup, в нее закидываешь файлы: 7z.exe, sleep.exe, cp.exe (можно найти в сети), создаешь файлы dumpdb-internal.cmd, fbackup.cmd, fbackup-internal.cmd, в диспечере задач прописываете запускать fbackup.cmd когда нужно делать бэкап.
Что в файлах:
fbackup.cmd
@echo off
SET FBACKUPLOG=fbackup.log
SET UKMFBACKUPCMD=fbackup-internal.cmd
echo -----------------------------------
echo Starting UKM backup
echo -----------------------------------
IF NOT EXIST %UKMFBACKUPCMD% GOTO file_not_found
call %UKMFBACKUPCMD% >> %FBACKUPLOG% 2>&1
IF %ERRORLEVEL% NEQ 0 GOTO error
echo ===================================
echo SUCCESS: backup complete
echo ===================================
exit 0
:file_not_found
echo ERROR: file not found
echo %UKMFBACKUPCMD%
echo ERROR: file not found >> %FBACKUPLOG%
echo %UKMFBACKUPCMD% >> %FBACKUPLOG%
:error
echo ===================================
echo ERROR: backup failed
echo ===================================
exit 1
dumpdb-internal.cmd
echo === %0 starting work ===
echo = %DATE% %TIME%
SET DBHOST=localhost
SET DBNAME=ukmserver
SET DBUSER=root
SET DBPASSWORD=CtHDbCGK.C
SET DBBACKUPFILE=d:\Backup\UKM\ukmserver-dump.sql
SET UKM_FULL_BACKUP_PATH=d:\Backup\UKM
echo -----------------------------------
echo DBHOST=%DBHOST%
echo DBNAME=%DBNAME%
echo DBUSER=%DBUSER%
echo DBPASSWORD=%DBPASSWORD%
echo DBBACKUPFILE=%DBBACKUPFILE%
echo -----------------------------------
echo SET FOREIGN_KEY_CHECKS = 0; > %DBBACKUPFILE%
echo CREATE DATABASE %DBNAME%; >> %DBBACKUPFILE%
echo use %DBNAME%; >> %DBBACKUPFILE%
c:\mysql\bin\mysqldump --opt --skip-add-drop-table --user=%DBUSER% --host=%DBHOST% --password=%DBPASSWORD% --databases %DBNAME% >> %DBBACKUPFILE%
IF %ERRORLEVEL% NEQ 0 GOTO error
echo .
echo .
echo .
echo ------ %DATE% %TIME%: Copy backup integrity check started
copy "%UKM_FULL_BACKUP_PATH%" \\192.168.1.3\backupukm\UKM
IF %ERRORLEVEL% NEQ 0 GOTO error
echo ===================================
echo = %DATE% %TIME%
echo SUCCESS: %0 - backup complete
echo ===================================
exit /B 0
:error
echo ===================================
echo = %DATE% %TIME%
echo ERROR: %0 - backup failed
echo ===================================
exit /B 1
fbackup-internal.cmd
@echo off
echo .
echo .
echo ------ LOG STARTED %DATE% %TIME% ------
echo Executing %0
echo ----------------------------------------
sc stop UkmService
sleep 60
sc stop MySql
sleep 60
sc stop Apache2ukm
sleep 60
SET DBHOST=localhost
SET DBNAME=ukmserver
SET DBUSER=root
SET DBPASSWORD=CtHDbCGK.C
SET DBBACKUPFILE=d:\Backup\UKM\ukmserver-dump.sql
SET DIR_PROGRAM_FILES=C:\Program Files
SET DIR_ONLY_UKM_SERVER=ukmserver
SET DIR_UKMSERVER=%DIR_PROGRAM_FILES%\%DIR_ONLY_UKM_SERVER%
SET DIR_UKMSERVER_EXCLUDE= -xr!"*.log" -x!"%DIR_ONLY_UKM_SERVER%\logs\*" -x!"%DIR_ONLY_UKM_SERVER%\ukmupman\update\*" -x!"%DIR_ONLY_UKM_SERVER%\ukmupman\backup" -x!"%DIR_ONLY_UKM_SERVER%\ukmupman\cli-update" -x!"%DIR_ONLY_UKM_SERVER%\ukmupman\temp_unpack" -x!"%DIR_ONLY_UKM_SERVER%\ukmupman\UPDATE_*" -ssc
SET DIR_APACHE=%DIR_PROGRAM_FILES%\Apache Group\Apache2ukm
SET DIR_APACHE_HTDOCS=%DIR_APACHE%\htdocs
SET DIR_UKMINSTALL=%DIR_APACHE_HTDOCS%\ukminstall
SET DIR_HTDOCS_UKM=%DIR_APACHE_HTDOCS%\ukm
SET DIR_HTDOCS_UKMFRONTEND=%DIR_APACHE_HTDOCS%\ukmfrontend
SET DIR_HTDOCS_YII=%DIR_APACHE_HTDOCS%\yii
SET DIR_UKMCLIENT=%DIR_PROGRAM_FILES%\ukmclient
SET DIR_PHP=C:\phpukm
SET DIR_UKM_UNINSTALL=%DIR_PROGRAM_FILES%\ukm-uninstall
SET FILE_HTTPD_CONF=%DIR_APACHE%\conf\httpd.conf
SET DIR_UKMUPMAN=%DIR_UKMSERVER%\ukmupman
SET PACKER="%DIR_UKMUPMAN%\7za.exe"
SET CP_EXE="%DIR_UKMUPMAN%\cp.exe"
SET CP_OPTIONS=-fRv
SET PACKOPS=a -y -mx=1
SET ARCHIVE_UKMSERVER=ukmserver.7z
SET ARCHIVE_HTDOCS_UKM=htdocs-ukm.7z
SET ARCHIVE_HTDOCS_UKMFRONTEND=htdocs-ukmfrontend.7z
SET ARCHIVE_HTDOCS_YII=htdocs-yii.7z
SET ARCHIVE_MYSQL_DATA=mysql-data.7z
SET ARCHIVE_PHP=phpukm.7z
SET ARCHIVE_UKMCLIENT=dir-ukmclient.7z
SET ARCHIVE_UKM_UNINSTALL=dir-ukm-uninstall.7z
SET MY_INI=%WINDIR%\my.ini
IF NOT EXIST %PACKER% GOTO packer_not_found
GOTO packer_found
:packer_not_found
echo -----------------------
echo ERROR: Packer not found
echo %PACKER%
echo -----------------------
GOTO error
:packer_found
IF "_"=="_%DIR_MYSQL_DATA%" GOTO dir_mysql_data_is_not_set
GOTO dir_mysql_data_is_set
:dir_mysql_data_is_not_set
echo WARNING! DIR_MYSQL_DATA is not set. Using default value "C:\MYSQL\DATA"
SET DIR_MYSQL_DATA=C:\MYSQL\DATA
:dir_mysql_data_is_set
echo --------------------------------------------------------------
echo DIR_MYSQL_DATA = %DIR_MYSQL_DATA%
echo --------------------------------------------------------------
IF "_"=="_%UKM_FULL_BACKUP_PATH%" GOTO ukm_backup_path_is_not_set
GOTO ukm_backup_path_is_set
:ukm_backup_path_is_not_set
SET UKM_FULL_BACKUP_PATH=d:\Backup\UKM
:ukm_backup_path_is_set
echo --------------------------------------------------------------
echo UKM_FULL_BACKUP_PATH = %UKM_FULL_BACKUP_PATH%
echo --------------------------------------------------------------
IF EXIST "%UKM_FULL_BACKUP_PATH%" echo found directory "%UKM_FULL_BACKUP_PATH%". Removing it.
IF EXIST "%UKM_FULL_BACKUP_PATH%" rmdir /S /Q "%UKM_FULL_BACKUP_PATH%"
IF %ERRORLEVEL% NEQ 0 GOTO error
IF NOT EXIST "%UKM_FULL_BACKUP_PATH%" mkdir "%UKM_FULL_BACKUP_PATH%"
IF %ERRORLEVEL% NEQ 0 GOTO error
echo Creating backup of "%MY_INI%"
IF EXIST "%MY_INI%" copy "%MY_INI%" "%UKM_FULL_BACKUP_PATH%"
IF %ERRORLEVEL% NEQ 0 GOTO error
echo .
echo .
echo .
echo ------ %DATE% %TIME%: %ARCHIVE_MYSQL_DATA% backup started
%PACKER% %PACKOPS% "%UKM_FULL_BACKUP_PATH%\%ARCHIVE_MYSQL_DATA%" "%DIR_MYSQL_DATA%"
IF %ERRORLEVEL% NEQ 0 GOTO error
echo ------ %DATE% %TIME%: %ARCHIVE_MYSQL_DATA% backup comleted
echo .
echo .
echo .
echo ------ %DATE% %TIME%: %ARCHIVE_PHP% backup started
%PACKER% %PACKOPS% "%UKM_FULL_BACKUP_PATH%\%ARCHIVE_PHP%" "%DIR_PHP%"
IF %ERRORLEVEL% NEQ 0 GOTO error
echo ------ %DATE% %TIME%: %ARCHIVE_PHP% backup completed
echo .
echo .
echo .
echo ------ %DATE% %TIME%: %ARCHIVE_UKMSERVER% backup started
%PACKER% %PACKOPS% "%UKM_FULL_BACKUP_PATH%\%ARCHIVE_UKMSERVER%" "%DIR_UKMSERVER%" %DIR_UKMSERVER_EXCLUDE%
IF %ERRORLEVEL% NEQ 0 GOTO error
echo ------ %DATE% %TIME%: %ARCHIVE_UKMSERVER% backup completed
echo .
echo .
echo .
echo ------ %DATE% %TIME%: %ARCHIVE_HTDOCS_UKM% backup started
%PACKER% %PACKOPS% "%UKM_FULL_BACKUP_PATH%\%ARCHIVE_HTDOCS_UKM%" "%DIR_HTDOCS_UKM%"
IF %ERRORLEVEL% NEQ 0 GOTO error
echo ------ %DATE% %TIME%: %ARCHIVE_HTDOCS_UKM% backup completed
IF EXIST "%DIR_HTDOCS_UKMFRONTEND%" (
echo .
echo .
echo .
echo Directory "%DIR_HTDOCS_UKMFRONTEND%" found
echo ------ %DATE% %TIME%: %ARCHIVE_HTDOCS_UKMFRONTEND% backup started
%PACKER% %PACKOPS% "%UKM_FULL_BACKUP_PATH%\%ARCHIVE_HTDOCS_UKMFRONTEND%" "%DIR_HTDOCS_UKMFRONTEND%"
IF %ERRORLEVEL% NEQ 0 GOTO error
echo ------ %DATE% %TIME%: %ARCHIVE_HTDOCS_UKMFRONTEND% backup completed
) else (
echo Directory "%DIR_HTDOCS_UKMFRONTEND%" not found found. Nothing to do
)
IF EXIST "%DIR_HTDOCS_YII%" (
echo .
echo .
echo .
echo Directory "%ARCHIVE_HTDOCS_YII%" found
echo ------ %DATE% %TIME%: %ARCHIVE_HTDOCS_YII% backup started
%PACKER% %PACKOPS% "%UKM_FULL_BACKUP_PATH%\%ARCHIVE_HTDOCS_YII%" "%DIR_HTDOCS_YII%"
IF %ERRORLEVEL% NEQ 0 GOTO error
echo ------ %DATE% %TIME%: %ARCHIVE_HTDOCS_YII% backup completed
) else (
echo Directory "%ARCHIVE_HTDOCS_YII%" not found found. Nothing to do
)
echo .
echo .
echo .
echo ------ %DATE% %TIME%: %ARCHIVE_UKMCLIENT% backup started
%PACKER% %PACKOPS% "%UKM_FULL_BACKUP_PATH%\%ARCHIVE_UKMCLIENT%" "%DIR_UKMCLIENT%"
IF %ERRORLEVEL% NEQ 0 GOTO error
echo ------ %DATE% %TIME%: %ARCHIVE_UKMCLIENT% backup completed
IF EXIST "%DIR_UKM_UNINSTALL%" (
echo .
echo .
echo .
echo ------ %DATE% %TIME%: %ARCHIVE_UKM_UNINSTALL% backup started
%PACKER% %PACKOPS% "%UKM_FULL_BACKUP_PATH%\%ARCHIVE_UKM_UNINSTALL%" "%DIR_UKM_UNINSTALL%"
IF %ERRORLEVEL% NEQ 0 GOTO error
echo ------ %DATE% %TIME%: %ARCHIVE_UKM_UNINSTALL% backup completed
)
echo .
echo .
echo .
echo ------ %DATE% %TIME%: "%DIR_UKMINSTALL%" backup started
%CP_EXE% %CP_OPTIONS% "%DIR_UKMINSTALL%" "%UKM_FULL_BACKUP_PATH%"
IF %ERRORLEVEL% NEQ 0 GOTO error
echo ------ %DATE% %TIME%: "%DIR_UKMINSTALL%" backup completed
echo .
echo .
echo .
echo ------ %DATE% %TIME%: "%FILE_HTTPD_CONF%" backup started
%CP_EXE% %CP_OPTIONS% "%FILE_HTTPD_CONF%" "%UKM_FULL_BACKUP_PATH%"
IF %ERRORLEVEL% NEQ 0 GOTO error
echo ------ %DATE% %TIME%: "%FILE_HTTPD_CONF%" backup completed
echo .
echo .
echo .
echo ------ %DATE% %TIME%: Backup integrity check started
%PACKER% t "%UKM_FULL_BACKUP_PATH%\*.7z"
IF %ERRORLEVEL% NEQ 0 GOTO error
echo ------ %DATE% %TIME%: Backup integrity check completed
sc start MySql
sleep 60
sc start Apache2ukm
sleep 60
sc start UkmService
sleep 60
echo SET FOREIGN_KEY_CHECKS = 0; > %DBBACKUPFILE%
echo CREATE DATABASE %DBNAME%; >> %DBBACKUPFILE%
echo use %DBNAME%; >> %DBBACKUPFILE%
c:\mysql\bin\mysqldump --opt --skip-add-drop-table --user=%DBUSER% --host=%DBHOST% --password=%DBPASSWORD% --databases %DBNAME% >> %DBBACKUPFILE%
IF %ERRORLEVEL% NEQ 0 GOTO error
echo .
echo .
echo .
echo ------ %DATE% %TIME%: Copy backup integrity check started
copy "%UKM_FULL_BACKUP_PATH%" \\192.168.1.3\backupukm\UKM
IF %ERRORLEVEL% NEQ 0 GOTO error
echo ------ %DATE% %TIME%: Del backup integrity check started
RD /S /Q "%UKM_FULL_BACKUP_PATH%"
IF %ERRORLEVEL% NEQ 0 GOTO error
echo .
echo .
echo SUCCESS: Backup done
echo ------ LOG ENDED %DATE% %TIME% ------
exit /B 0
:error
echo ERROR: Backup failed
echo ------ LOG ENDED %DATE% %TIME% ------
exit /B 1