@echo off
setlocal
:: 设置源目录路径
set SOURCE_DIR=D:\WWW
:: 设置目标备份目录路径
set BACKUP_DIR=D:\backup\www
:: 设置备份文件名前缀
set FILE_PREFIX=backup_
:: 获取当前日期和时间
for /f "tokens=1-4 delims=/ " %%i in ('date /t') do (
set YEAR=%%i
set MONTH=%%j
set DAY=%%k
)
for /f "tokens=1-2 delims=:" %%i in ('echo %time%') do (
set HOUR=%%i
set MINUTE=%%j
)
set DATETIME=%YEAR%%MONTH%%DAY%_%HOUR%%MINUTE%
:: 创建备份文件名
set BACKUP_FILE=%BACKUP_DIR%\%FILE_PREFIX%%DATETIME%.zip
:: 使用7-Zip压缩源目录到备份文件
"C:\Users\Administrator\7-Zip\7z.exe" a -tzip "%BACKUP_FILE%" "%SOURCE_DIR%" -r
:: 打印备份文件路径
echo Backup file created at: %BACKUP_FILE%
endlocal