bestlong 怕失憶論壇's Archiver

bestlong 發表於 2010-9-24 16:27

利用 XCOPY 和批次檔 .BAT 功能做備份

資料來源 [url]http://forum.icst.org.tw/phpbb/viewforum.php?f=10[/url][code]rem ----- 檔案名稱 : BACKUP.BAT -------------------------------------------------------
rem ----- 用途 : 利用 XCOPY 和 .BAT 功能做備份 ----------------------------------------

rem ----- 將 BACKUP.BAT 加入 系統排程 ( 可以手動加入 [開始][程式集][啟動] 中 ) ------
rem at 23:00 /every:s,m,t,w,th,f,sa "d:\LU\BACKUP.bat"

rem ----- XCOPY 用法 可用 "XCOPY /?" 查詢 ---------------------------------------------
rem XCOPY 差異備份常用參數
rem /D:m-d-y  複製在指定日期當天或之後發生變更的檔案。如果沒有給日期,只複製那些來源檔案日期比目的檔案日期為新的檔案。
rem /H        時複製隱藏檔和系統檔。
rem /I        如果目的不存在且複製一個以上的檔案的話,就假設指定的目的一定是目錄。
rem /S        複製每個目錄及其包含的子目錄,不複製空目錄。
rem /E        複製每個目錄及其包含的子目錄,含複製空目錄。/S 與 /E 相同,能夠用來修改 /T。
rem /Y        不要提示您確定是否要覆蓋一個已經存在的檔案。

rem ----- 增加 route 資料, 廢除 ---------------
rem route add 140.127.177.17 192.168.0.2

rem ----- 將開始備份時間寫入 log 紀錄中 -----------------------------------------------------------------------
rem %date% 表示日期環境變數, %date:~0,4% 表示 日期環境變數中從第 0 個位置抓出 4 個字
echo %date:~0,4%%date:~5,2%%date:~8,2% 網頁資料備份紀錄檔 > D:\Backup\log\%date:~0,4%%date:~5,2%%date:~8,2%.log
echo 始備份時間 >> D:\Backup\log\%date:~0,4%%date:~5,2%%date:~8,2%.log
TIME /T >> D:\Backup\log\%date:~0,4%%date:~5,2%%date:~8,2%.log

rem ------ [完整備份] 將網站資料備份到 以 日期為目錄名稱 的目錄中 --------------------------------------------------------
rem xcopy c:\inetpub D:\Backup\%date:~0,4%%date:~5,2%%date:~8,2% /h /i /s /k /o /y >> D:\Backup\log\%date:~0,4%%date:~5,2%%date:~8,2%.log

rem ----- [差異備份] 備份 MSN 表情符號, 改名成 .gif 方便加看, 更名失敗表示重複, 可刪除
XCOPY "C:\Documents and Settings\lu\Application Data\Microsoft\MSN Messenger\1061698994\CustomEmoticons" "D:\CustomEmoticons" /D /H /I /S /Y
REN D:\CustomEmoticons\*.dat *.gif
DEL D:\CustomEmoticons\*.dat

rem ------ [差異備份] 備份 MSN 表情符號 到 File Server 的個人備份區
XCOPY D:\CustomEmoticons Z:\CustomEmoticons\ /D /H /I /S /Y

rem ------ [差異備份] 備份 我的最愛 到自己的 D: 磁碟 --------------------------------------------------------------
rem 使用 %USERPROFILE% 環境變數, 它代表 "C:\Documents and Settings\(使用者登入帳號)"
XCOPY %USERPROFILE%\Favorites "z:\Favorites\" /D /H /I /S /Y
rem XCOPY "C:\Documents and Settings\lu\Favorites" "D:\Favorites\" /D /H /I /S /Y

rem ------ [差異備份] 備份 Outlook Express 6.x 通訊錄 到自己的 D: 磁碟 -------------------------------------------------------------------
XCOPY "%USERPROFILE%\Application Data\Microsoft\Address Book" "D:\Address Book\" /D /H /I /S /Y
rem XCOPY "C:\Documents and Settings\lu\Application Data\Microsoft\Address Book" "D:\Address Book\" /D /H /I /S /Y

rem ------ [差異備份] 備份 我的最愛 到 File Server 的個人備份區 -----------------------------------------------------------
XCOPY %USERPROFILE%\Favorites "z:\Favorites\" /D /H /I /S /Y
rem XCOPY "C:\Documents and Settings\lu\Favorites" "z:\Favorites\" /D /H /I /S /Y

rem ------ [差異備份] 備份 Outlook Express 6.x 通訊錄 到 File Server 的個人備份區 -----------------------------------------------------------
XCOPY "%USERPROFILE%\Application Data\Microsoft\Address Book" "z:\Address Book\" /D /H /I /S /Y
rem XCOPY "C:\Documents and Settings\lu\Application Data\Microsoft\Address Book" "z:\Address Book\" /D /H /I /S /Y

rem ----- [壓縮完整備份] 將 D:\lu 用 WinRAR 壓縮放在 d:\lu.rar 或 d:\日期.rar ----------------------
rem WinRar 是商業軟體, 網開 http://www.rarsoft.com/
rem c:\progra~1\winrar\rar a -r d:\lu.rar d:\lu\*
rem c:\progra~1\winrar\rar a -r d:\%date:~0,4%%date:~5,2%%date:~8,2%.rar d:\lu\*
rem "C:\Program Files\WinRar\rar a -r d:\%date:~0,4%%date:~5,2%%date:~8,2%.rar d:\lu\*

rem ----- [壓縮完整備份] 將 D:\lu 用 7-zip 壓縮 ----------------------
rem 7-Zip 是免費軟體, 網開 http://www.7-zip.org/
rem "C:\program Files\7-zip\7z" a -r c:\%date:~0,4%%date:~5,2%%date:~8,2%.7z d:\lu\*.*
rem 壓縮成為 .zip 格式
rem "C:\program Files\7-zip\7z" a -r -tzip c:\%date:~0,4%%date:~5,2%%date:~8,2%.zip d:\lu\*.*

rem ----- 差異備份, 異動檔案輸出到 1.log -----
rem XCOPY D:\LU Z:\LU\ /D /H /I /S /Y >> c:\1.log
XCOPY D:\LU Z:\LU\ /D /H /I /S /Y

rem ------ 備份 Outlook 信件 -------------------------------------------------
rem echo 請先關閉 Outlook , 否則 Outlook 信件無法備份
rem pause
XCOPY "D:\Outlook" "z:\Outlook\" /D /H /I /S /Y

rem ------ 備份 hosts 檔案 -------------------------------------------------
XCOPY C:\WINDOWS\system32\drivers\etc\hosts z:\ /D /H /I /S /Y

rem ------ 輸出備份完成時間 -----------------------------------------------
echo 結束備份時間 >> D:\Backup\log\%date:~0,4%%date:~5,2%%date:~8,2%.log
TIME /T >> D:\Backup\log\%date:~0,4%%date:~5,2%%date:~8,2%.log[/code]
頁: [1]

Powered by Discuz! X1.5 Archiver   © 2001-2010 Comsenz Inc.