使用卷影副本 (VSS) 和 Diskshadow.exe 运行 Hyper-V 映像的命令行备份

Dou*_*xem 8 windows backup windows-server-2008 hyper-v vss

我需要通过命令提示符以最少的停机时间备份正在运行的 Hyper-V 虚拟机。备份应存储在另一个本地磁盘或远程共享上。

Dou*_*xem 8

以下是用于使用 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
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)