Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學

使用 xcopy 實現本地文件自動備份至遠程服務器

編輯:系統常見問題解答

xcopy 配合 net use 可實現跨網絡的增量備份,適合寫入批處理排程任務。

核心批處理代碼 backup.bat

@echo off
net use \\192.168.1.198\ipc$ Zqf198703 /user:royalpeak
xcopy g:\backup\*.* \\192.168.1.198\數據備份 /D /E /Y /H /K
net use \\192.168.1.198\ipc$ /delete

關鍵參數解析

參數作用
/D僅複製指定日期後更新的文件 (增量備份核心)
/E包含空目錄在內的所有子目錄
/Y覆蓋不提示
/H包含隱藏/系統文件
/K保留只讀屬性
/Z可重啟模式,網絡中斷斷點續傳

進階技巧

  • 排除文件: /exclude:exclude.txt,文件內每行一個路徑關鍵字 (如 \Obj\ 或 .obj)。
  • 權限保留: /O 複製 ACL,/X 含審核設置 (需 NTFS 目標)。
  • 退出碼判斷: 0 成功、1 無文件、2 用戶中斷、4 初始化錯誤、5 寫入錯誤。可在批處理中用 if errorlevel 處理。

注意事項

  1. 目標路徑需共享並授予寫入權限。
  2. 加密文件 (EFS) 需先解密或目標支援 EFS。
  3. 批處理中連接 IPC$ 後記得 /delete 釋放會話。
Copyright © Windows教程網 All Rights Reserved