@echo off :: Need to install: :: - MySQL client tools (mysqldump.exe is used in this script). If version is chenged - change path to exe. :: - NcFTP client (ncftpget.exe is used in this script). It creates exe files in %windir%, if changes occurs here - change path to exe. :: - 7-Zip console verion (7za.exe is used in this script). Put exe in the same folder as this cmd has or change path. :: Create needed variables and folders (and delete old files) SET DRIVELETTER=D del /F /Q %DRIVELETTER%:\_backups_mantis\backups\* :: Russian format ::SET TIMESTAMP=%date:~6,4%%date:~3,2%%date:~0,2%%time:~0,2%%time:~3,2% :: Format on SQL server SET TIMESTAMP=%date:~10,4%%date:~4,2%%date:~7,2%%time:~0,2%%time:~3,2% :: Replace spaces by 0 SET TIMESTAMP=%TIMESTAMP: =0% SET BACKUPS_DIR=%DRIVELETTER%:\_backups_mantis\backups\mantis_%TIMESTAMP% SET SITE_DIR=%BACKUPS_DIR%\site SET DB_DIR=%BACKUPS_DIR%\db SET ARCHIVE_DIR=%DRIVELETTER%:\_backups_mantis\archive mkdir %SITE_DIR% mkdir %DB_DIR% mkdir %ARCHIVE_DIR% :: Create DB backup :: Destination file SET DSTFILE=%DB_DIR%\backup-%TIMESTAMP%.sql :: Connection parameters SET SQLSERVER=mobimus.palvelin.pro SET SQLUSER= SET SQLPASS="" SET DB=mobimus_mantisbt :: Do the job - make DB dump "D:\_backups_mantis\mysqldump.exe" -c -e --default-character-set=utf8 --hex-blob -r %DSTFILE% -h %SQLSERVER% -u %SQLUSER% -p%SQLPASS% %DB% :: Create Mantis & attachments backup :: Connection parameters SET FTPSERVER=mobimus.palvelin.pro SET FTPUSER= SET FTPPASS="" :: Backup all Mantis files (with attachments) SET SRCDIR=/public_html/mantisbt/ :: Backup only attachements ::SET SRCDIR_ATTACH=/public_html/mantisbt/upload/ :: Do the job - download files from ftp D:\_backups_mantis\ncftpget.exe -R -u %FTPUSER% -p %FTPPASS% %FTPSERVER% %SITE_DIR% %SRCDIR% # :: Move attachements to corresponding path #move %SITE_DIR%\mantisbt\mantisbt\upload %ATTACH_DIR% :: Compress backup files :: Destination file SET DSTARCH=%BACKUPS_DIR%.zip :: Do the job %DRIVELETTER%:\_backups_mantis\7za.exe a -tzip -y %DSTARCH% %BACKUPS_DIR% :: Remove backup folder from local drive FOR /D %%p IN ("%DRIVELETTER%:\_backups_mantis\backups\*.*") DO rmdir "%%p" /s /q :: Move files to archive folder and remove files older than 30 days move %DRIVELETTER%:\_backups_mantis\backups\* %ARCHIVE_DIR% ForFiles /p %ARCHIVE_DIR% /s /d -30 /c "cmd /c del @file" exit