CLS
@ECHO off
ECHO.
ECHO.
ECHO ===== 正在備份資料 =====
REM 取得日期,格式YYYYMMDD。
SET _MyDate=%DATE:~0,4%%DATE:~5,2%%DATE:~8,2%
REM 設定備份目的路徑。**以下存放路徑、目錄、存取權限、檔案名稱,需先手動確認。**
SET _DB_Backup_PATH=\\192.168.1.100\Backup
SET _FileName=CB1_db_%_MyDate%0200
SET _Local_Log_PATH=.
REM 寫入記錄檔
echo ===開始備份 %_MyDate% %time% === >> %_Local_Log_PATH%\DB_Backup_log.txt
echo. >> %_Local_Log_PATH%\DB_Backup_log.txt
REM 使用7z加壓縮,並寫入記錄檔。
7z a -scsUTF-8 %_FileName%.7z %_FileName%.bak
IF EXIST %_FileName%.7z (ECHO 檔案%_FileName%於%time%壓縮成功 >> %_Local_Log_PATH%\DB_Backup_log.txt
)ELSE (ECHO 檔案%_FileName%於%time%壓縮失敗 >> %_Local_Log_PATH%\DB_Backup_log.txt)
echo. >> %_Local_Log_PATH%\DB_Backup_log.txt
REM 複製所有.7z且為保存屬性的檔案,到備份資料夾,清除保存屬性,並寫入記錄檔。
XCOPY /M /D /I /Y /F *.7z %_DB_Backup_PATH% >> %_Local_Log_PATH%\DB_Backup_log.txt
echo. >> %_Local_Log_PATH%\DB_Backup_log.txt
REM 刪除沒有保存屬性的壓縮檔,並寫入記錄檔。
DEL /S /A-A *.7z >> %_Local_Log_PATH%\DB_Backup_log.txt
echo. >> %_Local_Log_PATH%\DB_Backup_log.txt
REM 寫入記錄檔
echo ===備份完畢 %_MyDate% %time% ===>> %_Local_Log_PATH%\DB_Backup_log.txt
echo. >> %_Local_Log_PATH%\DB_Backup_log.txt
echo. >> %_Local_Log_PATH%\DB_Backup_log.txt
xcopy /Y %_Local_Log_PATH%\DB_Backup_log.txt %_DB_Backup_PATH%
ECHO.
ECHO. ===== 備份完畢 =====
ECHO.
ECHO.
沒有留言:
張貼留言