Windows
使用卷影副本 (VSS) 和 Diskshadow.exe 執行 Hyper-V 映像的命令行備份
我需要通過命令提示符以最短的停機時間備份正在執行的 Hyper-V 虛擬機。備份應儲存在另一個本地磁碟或遠端共享上。
下面是用於使用 VSS 創建快照來備份 Hyper-V 的範例腳本。不支持 VSS 的客戶機作業系統將在快照期間進入保存狀態。
此範例將位於E:\VS目錄的圖像備份到位於F:\VS Backups的本地目錄。這些位置需要根據您的需要進行調整。對於每個源驅動器,需要將一個附加卷添加到 VSS 快照中。
Technet 上提供了有關diskshadow.exe 命令的文件。
將這三個文件中的每一個複製到一個目錄中並執行HyperVBackup.cmd。
HyperVBackup.cmd:
REM Use the diskshadow command to support "live" Hyper-V backup REM though VSS diskshadow /s diskshadow_script.txt > HyperVBackup_LOG.txt REM Remove CAB files which are generated to support the exporting REM of disk shadow copies (not required here) del *.cab /Q
diskshadow_script.txt:
# Remove any existing shadow copies from crashed or errored scripts # WARNING: this will conflict with other backup software if running # at the same time. delete shadows all # Use a persistent context so we can "map" a drive set context persistent # Log everything set verbose on # ***TODO*** Change this drive letter to match the location of your # VHD files add volume E: alias HyperV1 # Add additional volumes if needed #add add volume H: alias HyperV2 # Create the shadow copy create # Expose each shadowed volume as a drive # ***TODO*** Make sure the exposed drive letter is available and used # in the backup script expose %HyperV1% S: # Expose additional volumes as needed #expose %HyperV2% T: # Execute the backup script (robocopy) exec HyperVBAckup_exec.cmd # clean up the shadow copy images delete shadows all
HyperVBackup_exec.cmd:
REM This is the script to perform the actual copy of the files REM Use robocopy with the source set to the expose shadow drives REM The drives are read-only, so don't try to reset the archive bit REM **TODO** Set the destination location for the backups robocopy S:\VS "F:\VS Backup" /MIR /NP /XF *.ISO /R:2 /W:5 REM Dummy command to clear the robocopy errorlevel verify >nul