Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 1개 있습니다.)
실수로 지워진 예전 글을 복원한 것입니다.


사실, 제가 운영하는 VM들은 그다지 Mission Critical한 것들은 아니라서 그동안 임시적으로 robocopy를 이용해서 백업을 해왔습니다. 비록 robocopy가 간편한 면은 있지만, 잠긴 파일들은 복사를 못하기 때문에 .bin, .vsv 파일등은 VM 운영 중에 복사를 하지 못하는 단점이 있고, 게다가 "export(내보내기)"를 통한 결과물과는 다르기 때문에 나중에 복구할 때도 VM을 새로 생성하고 vhd를 연결해야 한다는 문제가 있습니다.

세월이 지났으니... 이제 좀 나아져야 하는 것이 있어야겠지요. 마침 다음의 글이 눈에 띄어서 이번 기회에 VM 백업을 개선해보기로 했습니다.

Hyper-V How To: Backup Hyper-V with Windows
; http://blogs.technet.com/b/tonyso/archive/2009/12/03/hyper-v-how-to-backup-hyper-v-with-windows.aspx

오~~~ 훌륭합니다. VSS(Volume Shadow Service)를 이용하여 운영 중인 VM의 정합성을 깨뜨리지 않고 백업을 할 수가 있는 것입니다.

DiskShadow / Xcopy BACKUP of Hyper-V
; http://blogs.technet.com/enterprise_admin/archive/2009/11/19/diskshadow-xcopy-backup-of-hyper-v.aspx

DiskShadow / Xcopy RESTORE of Hyper-V
; http://blogs.technet.com/enterprise_admin/archive/2009/11/20/diskshadow-xcopy-restore-of-hyper-v.aspx

실제로 BACKUP을 한번 해볼까요? ^^

제 경우에 다음과 같이 diskshadow용 스크립트 파일을 제작했습니다.

=== devvpc.backup.script.txt ===
set context persistent
set metadata C:\backup\devvpc_backup.cab
set verbose on
begin backup
     add volume C: alias CDriveVolume
     writer verify {66841cd4-6ded-4f4b-8f17-fd23f8ddc3de}
     create
     EXPOSE %CDriveVolume% Y:
EXEC DevVpc_Backup.cmd
     UNEXPOSE Y:
end backup

복사 과정에 쓰이는 DevVpc_Backup.cmd 내용은 아래와 같고.

Xcopy y:\DevVpc\*.* \\file_server\Backup\VMs\DevVpc\*.* /e /s /y /F /O /X /R /H 
copy C:\backup\devvpc_backup.cab \\file_server\Backup\VMs

실행시켜 보면, 아래와 같은 출력 결과로 잘 실행이 됩니다. ^^

C:\backup>diskshadow -s devvpc.backup.script.txt
Microsoft DiskShadow version 1.0
Copyright (C) 2007 Microsoft Corporation
On computer: TESTDEV, 2011-02-02 오후 2:05:05

-> set context persistent
-> set metadata C:\backup\devvpc_backup.cab
-> set verbose on
-> begin backup
-> add volume C: alias CDriveVolume
-> writer verify {66841cd4-6ded-4f4b-8f17-fd23f8ddc3de}
-> create
Excluding writer "SqlServerWriter", because all of its components have been excluded.
Excluding writer "Shadow Copy Optimization Writer", because all of its components have been excluded.
Excluding writer "BITS Writer", because all of its components have been excluded.
Component "\BCD\BCD" from writer "ASR Writer" is excluded from backup,
because it requires volume which is not in the shadow copy set.
The writer "ASR Writer" is now entirely excluded from the backup because the top-level
non selectable component "\BCD\BCD" is excluded.
All components from writer "{66841cd4-6ded-4f4b-8f17-fd23f8ddc3de}" are selected.

* Including writer "Task Scheduler Writer":
        + Adding component: \TasksStore

* Including writer "VSS Metadata Store Writer":
        + Adding component: \WriterMetadataStore

* Including writer "Performance Counters Writer":
        + Adding component: \PerformanceCounters

* Including writer "Microsoft Hyper-V VSS Writer":
        + Adding component: \010434F5-D6EB-4515-AEB6-07F54FC8D8CD
        + Adding component: \381EF73A-B892-49B8-A85C-40551FF99613
        + Adding component: \410FD69E-FEB4-47B6-BFE4-EC4B68E648CC
        + Adding component: \41B1DBCE-73C7-4BD8-8AB5-C1951932055C
        + Adding component: \52D5C9C9-7969-4DEB-8309-CFE05B5DD884
        + Adding component: \56813D63-57C3-4C26-A2A6-E33A20F8AB16
        + Adding component: \6378C634-BBE2-4E96-BB29-5030BD74EB7A
        + Adding component: \67BE52CE-B1DE-4A1C-ADF0-EE460B56512B
        + Adding component: \789A7A84-A50E-4963-8645-584E4783D6F0
        + Adding component: \936D9957-D43E-4537-A1C4-865CCAED9766
        + Adding component: \9833A038-EEF6-4553-8669-82D14554FDD0
        + Adding component: \B4D2F831-36EE-4A9C-8A53-6054E4083801
        + Adding component: \BCABC9EF-65D3-4127-AD37-A4EBA337CD38
        + Adding component: \BE34C8A1-77DC-4E19-813A-0EAEBDFC2105
        + Adding component: \CD34D520-6BD0-47D6-A02F-07A55A285233
        + Adding component: \CE254D34-199C-4734-A71E-DB0B78A618CC
        + Adding component: \ECE0EF1C-B03B-4574-A968-3046615BF98F
        + Adding component: \EEE8A12A-2A82-417E-84DF-E04981A91F6B
        + Adding component: \F05DD4D5-CE44-4821-AFC8-641F2F8BA95F
        + Adding component: \F71DC118-8D67-4B3C-BDB7-A11BF894B14E
        + Adding component: \Initial Store

* Including writer "System Writer":
        + Adding component: \System Files

* Including writer "WMI Writer":
        + Adding component: \WMI

* Including writer "Dhcp Jet Writer":
        + Adding component: \C:_Windows_system32_dhcp\dhcp

* Including writer "Registry Writer":
        + Adding component: \Registry

* Including writer "COM+ REGDB Writer":
        + Adding component: \COM+ REGDB

* Including writer "IIS Config Writer":
        + Adding component: \IISCONFIG

* Including writer "IIS Metabase Writer":
        + Adding component: \IISMETABASE

Alias CDriveVolume for shadow ID {c30ac6d4-8402-4a9d-ad25-a7905950acf5} set as environment variable.
Alias VSS_SHADOW_SET for shadow set ID {419ccabf-8cc6-42c2-a16b-747ffabd0327} set as environment variable.
Inserted file Manifest.xml into .cab file devvpc_backup.cab
Inserted file BCDocument.xml into .cab file devvpc_backup.cab
Inserted file WM0.xml into .cab file devvpc_backup.cab
Inserted file WM1.xml into .cab file devvpc_backup.cab
Inserted file WM2.xml into .cab file devvpc_backup.cab
Inserted file WM3.xml into .cab file devvpc_backup.cab
Inserted file WM4.xml into .cab file devvpc_backup.cab
Inserted file WM5.xml into .cab file devvpc_backup.cab
Inserted file WM6.xml into .cab file devvpc_backup.cab
Inserted file WM7.xml into .cab file devvpc_backup.cab
Inserted file WM8.xml into .cab file devvpc_backup.cab
Inserted file WM9.xml into .cab file devvpc_backup.cab
Inserted file WM10.xml into .cab file devvpc_backup.cab
Inserted file WM11.xml into .cab file devvpc_backup.cab
Inserted file WM12.xml into .cab file devvpc_backup.cab
Inserted file WM13.xml into .cab file devvpc_backup.cab
Inserted file WM14.xml into .cab file devvpc_backup.cab
Inserted file Dis90B3.tmp into .cab file devvpc_backup.cab

Querying all shadow copies with the shadow copy set ID {419ccabf-8cc6-42c2-a16b-747ffabd0327}

        * Shadow copy ID = {c30ac6d4-8402-4a9d-ad25-a7905950acf5} %CDriveVolume%
                - Shadow copy set: {419ccabf-8cc6-42c2-a16b-747ffabd0327} %VSS_SHADOW_SET%
                - Original count of shadow copies = 3
                - Original volume name: \\?\Volume{f46e1413-c223-11de-9341-806e6f6e6963}\ [C:\]
                - Creation time: 2011-02-02 오후 2:09:05
                - Shadow copy device name: \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy3
                - Originating machine: TESTDEV
                - Service machine: TESTDEV
                - Not exposed
                - Provider ID: {b5946137-7b9f-4925-af80-51abd60b20d5}
                - Attributes: No_Auto_Release Persistent Differential

Number of shadow copies listed: 1
-> EXPOSE %CDriveVolume% Y:
-> %CDriveVolume% = {895ff2bc-68a1-4277-acf4-bf00329c28bc}
The shadow copy was successfully exposed as Y:\.
-> EXEC DevVpc_Backup.cmd

C:\backup>Xcopy y:\DevVpc\*.* \\file_server\Backup\VMs\DevVpc\*.* /e /s /y /F /O /X /R /H
...[생략]...
xxxxx File(s) copied

C:\backup>copy C:\backup\devvpc_backup.cab \\file_server\Backup\VMs
        1 file(s) copied.
-> UNEXPOSE Y:
Shadow copy ID {e5b2eafc-5c59-46f1-92f2-43be41afbc27} is no longer exposed.
-> end backup
->
->

물론, robocopy로는 복사가 안되었던 vsv 파일들까지 모두 복사됩니다.




백업은 그럼 완료되었고, 이제 복원을 해야 할 텐데요. 복원 스크립트와 그 내부에 쓰이는 xcopy 내용은 다음과 같이 구성했습니다.

=== devvpc.restore.script.txt ===
set context persistent
load metadata C:\backup\devvpc_backup.cab
set verbose on
begin restore
EXEC C:\backup\DevVpc_Restore.cmd
end restore

=== DevVpc_Restore.cmd ===
Xcopy \\file_server\Backup\VMs\DevVpc\*.* C:\DevVpc\*.* /e /s /y /F /O /X /R /H

주의할 점이 하나 있는데, 복원 과정 중에는 Hyper-V 머신에 실행 중인 "복원에 해당하는 VM"들의 서비스가 중지되고 아예 목록에서 삭제됩니다. (vmwp.exe들이 종료됩니다.) 이를 염두에 두고, 준비된 스크립트 파일로 diskshadow.exe를 실행시켜 주면 다음과 같이 복원 과정이 진행됩니다.

C:\backup>diskshadow -s devvpc.restore.script.txt
Microsoft DiskShadow version 1.0
Copyright (C) 2007 Microsoft Corporation
On computer: TESTDEV, 2011-02-03 오전 9:46:23

-> set context persistent
-> #the backup.cab file mentioned below is the one created during backup.
-> load metadata C:\backup\devvpc_backup.cab
Alias CDriveVolume for value {75fc0781-1afa-4db1-91f2-94cd64d8fcfc} set as an environment variable.
Alias VSS_SHADOW_SET for value {8de552b0-8fdc-4642-9cf2-212090940b2f} set as an environment variable.
-> set verbose on
-> begin restore

Listing writer status information ...

        * WRITER "Task Scheduler Writer"
        * WRITER "VSS Metadata Store Writer"
        ...[생략]...
        * WRITER "Dhcp Jet Writer"
                - Status: 1 (VSS_WS_STABLE)
                - Writer failure code: 0x00000000 (S_OK)
                - Writer ID: {be9ac81e-3619-421f-920f-4c6fea9e93ad}
                - Writer instance ID: {272e50ad-e51b-460f-a954-80aa644f1cd2}

Number of writers listed: 15
Writer Task Scheduler Writer is present in the Backup Components Document and on the computer.
Writer VSS Metadata Store Writer is present in the Backup Components Document and on the computer.
...[생략]...
Notifying VSS of selected writer components for restore.
        * Writer "Microsoft Hyper-V VSS Writer":
                + Selecting component: \010434F5-D6EB-4515-AEB6-07F54FC8D8CD
                + Selecting component: \381EF73A-B892-49B8-A85C-40551FF99613
                ...[생략]...
                + Selecting component: \F71DC118-8D67-4B3C-BDB7-A11BF894B14E
                + Selecting component: \Initial Store
        * Writer "Dhcp Jet Writer":
                + Selecting component: \C:_Windows_system32_dhcp\dhcp
The PreRestore event was successfully sent to the writers.
The restore operation has started. Please issue END RESTORE when it is complete.
-> EXEC C:\backup\DevVpc_Restore.cmd

C:\backup>Xcopy \\file_server\Backup\VMs\DevVpc\*.* C:\DevVpc\*.* /e /s /y /F /O /X /R /H
...[생략]...
27 File(s) copied
-> end restore
Setting restore status for all restore components...
        * Writer "Microsoft Hyper-V VSS Writer":
                + Selecting component: \010434F5-D6EB-4515-AEB6-07F54FC8D8CD
                + Selecting component: \381EF73A-B892-49B8-A85C-40551FF99613
                + Selecting component: \410FD69E-FEB4-47B6-BFE4-EC4B68E648CC
                + Selecting component: \41B1DBCE-73C7-4BD8-8AB5-C1951932055C
                + Selecting component: \52D5C9C9-7969-4DEB-8309-CFE05B5DD884
                + Selecting component: \56813D63-57C3-4C26-A2A6-E33A20F8AB16
                + Selecting component: \6378C634-BBE2-4E96-BB29-5030BD74EB7A
                + Selecting component: \67BE52CE-B1DE-4A1C-ADF0-EE460B56512B
                + Selecting component: \789A7A84-A50E-4963-8645-584E4783D6F0
                + Selecting component: \936D9957-D43E-4537-A1C4-865CCAED9766
                + Selecting component: \9833A038-EEF6-4553-8669-82D14554FDD0
                + Selecting component: \B4D2F831-36EE-4A9C-8A53-6054E4083801
                + Selecting component: \BCABC9EF-65D3-4127-AD37-A4EBA337CD38
                + Selecting component: \BE34C8A1-77DC-4E19-813A-0EAEBDFC2105
                + Selecting component: \CD34D520-6BD0-47D6-A02F-07A55A285233
                + Selecting component: \CE254D34-199C-4734-A71E-DB0B78A618CC
                + Selecting component: \ECE0EF1C-B03B-4574-A968-3046615BF98F
                + Selecting component: \EEE8A12A-2A82-417E-84DF-E04981A91F6B
                + Selecting component: \F05DD4D5-CE44-4821-AFC8-641F2F8BA95F
                + Selecting component: \F71DC118-8D67-4B3C-BDB7-A11BF894B14E
                + Selecting component: \Initial Store
        * Writer "Dhcp Jet Writer":
                + Selecting component: \C:_Windows_system32_dhcp\dhcp
->
->

복원 후에는 해당 VM들이 멈춘 상태이므로 수작업으로 시작해주어야 합니다.

자, 그럼 이것으로 백업/복원이 모두 끝났군요. 남은 것은 주기적으로 (일요일 새벽 같은 날) 백업이 되도록 Task Scheduler에 등록시켜 두면 끝!




시도를 하는 과정 중에, 몇 가지 시행 착오가 있었는데 아래는 그에 대한 설명입니다.

C:\backup>diskshadow -s devvpc.backup.script.txt
Microsoft DiskShadow version 1.0
Copyright (C) 2007 Microsoft Corporation
On computer: MAINDEV, 2011-02-02 오후 1:26:52

-> set context persistent
-> set metadata C:\backup\devvpc_backup.cab
-> set verbose on
-> begin backup
-> add volume C: alias ConfigVolume

COM call "CreateVssBackupComponents" failed.

위와 같은 오류가 발생하면, 명령어를 "관리자 권한"으로 실행시켜야 합니다.

-> set context persistent
-> set metadata C:\backup\devvpc_backup.cab
-> set verbose on
-> begin backup
-> add volume C: alias ConfigVolume

COM call "(*vssObject)->InitializeForBackup" failed.

위와 같은 오류가 발생하면, 우선 위의 명령어를 실행하는 cmd.exe가 64비트로 실행되었는지 "cmd.exe *32"와 같이 32비트로 실행되었는지 확인합니다. 만약 32가 붙었다면 위와 같은 오류가 발생하므로, 64비트용 cmd.exe를 띄우고 다시 실행하면 정상적으로 백업이 진행됩니다.

-> set context persistent
-> set metadata D:\backup\devvpc_backup.cab
-> set verbose on
-> begin backup
-> add volume D: alias ConfigVolume
-> #The GUID of the Hyper-V Writer
-> writer verify {66841cd4-6ded-4f4b-8f17-fd23f8ddc3de}
-> create
Excluding writer "SqlServerWriter", because all of its components have been excluded.
Excluding writer "Shadow Copy Optimization Writer", because all of its components have been excluded.
Excluding writer "BITS Writer", because all of its components have been excluded.
Component "\TasksStore" from writer "Task Scheduler Writer" is excluded from backup,
because it requires volume C:\ which is not in the shadow copy set.
...[생략]...
The writer "COM+ REGDB Writer" is now entirely excluded from the backup,
because it does not contain any components that can be included.

       The component "Microsoft Hyper-V VSS Writer" was not found in the writer components list. Aborting backup ...
       Check the syntax of the component name.


위의 오류가 발생하는 분들이 가장 많을 것 같습니다. 오류 메시지들이 의미하는 바를 나중에 해결 방법을 알고 나서야 이해가 되었는데요. 검색의 도움을 빌어 다음의 글에서 해결책을 찾을 수 있었습니다.

Moving from VMware Server to Hyper-V 
; http://www.wintellect.com/CS/blogs/jrobbins/archive/2009/04/26/moving-from-vmware-server-to-hyper-v.aspx

즉, Hyper-V VSS Writer가 관여하는 모든 볼륨을 추가해 주어야 한다는 것인데, Hyper-V에 포함된 (운영 중이든, 아니든) VM이 속한 모든 드라이브와 Hyper-V가 설치된 드라이브(즉, 운영체제 드라이브)를 포함해 주어야 합니다.

예를 들어, 운영체제가 C 드라이브에 설치되어 있는 상태에서 Hyper-V에 등록된 "test1", "test2" VM들이 각각 C:\test1, E:\test2 폴더에 VHD 파일들을 보관해서 사용 중이라면 아래와 같이 2개의 드라이브 모두 add volume 명령을 추가해 주어야 합니다. (이런 경우, D 드라이브는 포함하지 않아도 됩니다.)

     add volume C: alias CDriveVolume 
     add volume E: alias EDriveVolume


[연관 글]






[최초 등록일: ]
[최종 수정일: 7/9/2021]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 



2013-10-02 12시58분
[wafe] 뭔가 shadow volume 을 만들고 나면 백업하는 과정 자체는 vhd 파일이나 hyper-v vm xml 파일을 그냥 복사하면 되는거로군요?
[guest]
2013-10-02 02시02분
정성태

[1]  2  3  4  5  6  7  8  9  10  11  12  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
13616정성태5/3/202499닷넷: 2256. ASP.NET Core 웹 사이트의 HTTP/HTTPS + Dual mode Socket (IPv4/IPv6) 지원 방법파일 다운로드1
13615정성태5/3/2024114닷넷: 2255. C# 배열을 Numpy ndarray 배열과 상호 변환
13614정성태5/2/2024185닷넷: 2254. C# - COM 인터페이스의 상속 시 중복으로 메서드를 선언
13613정성태5/1/2024308닷넷: 2253. C# - Video Capture 장치(Camera) 열거 및 지원 포맷 조회파일 다운로드1
13612정성태4/30/2024298오류 유형: 902. Visual Studio - error MSB3021: Unable to copy file
13611정성태4/29/2024574닷넷: 2252. C# - GUID 타입 전용의 UnmanagedType.LPStruct - 두 번째 이야기파일 다운로드1
13610정성태4/28/2024644닷넷: 2251. C# - 제네릭 인자를 가진 타입을 생성하는 방법 - 두 번째 이야기
13609정성태4/27/2024814닷넷: 2250. PInvoke 호출 시 참조 타입(class)을 마샬링하는 [IN], [OUT] 특성파일 다운로드1
13608정성태4/26/20241028닷넷: 2249. C# - 부모의 필드/프로퍼티에 대해 서로 다른 자식 클래스 간에 Reflection 접근이 동작할까요?파일 다운로드1
13607정성태4/25/20241053닷넷: 2248. C# - 인터페이스 타입의 다중 포인터를 인자로 갖는 C/C++ 함수 연동
13606정성태4/24/20241002닷넷: 2247. C# - tensorflow 연동 (MNIST 예제)파일 다운로드1
13605정성태4/23/2024978닷넷: 2246. C# - Python.NET을 이용한 파이썬 소스코드 연동파일 다운로드1
13604정성태4/22/2024978오류 유형: 901. Visual Studio - Unable to set the next statement. Set next statement cannot be used in '[Exception]' call stack frames.
13603정성태4/21/20241029닷넷: 2245. C# - IronPython을 이용한 파이썬 소스코드 연동파일 다운로드1
13602정성태4/20/20241014닷넷: 2244. C# - PCM 오디오 데이터를 연속(Streaming) 재생 (Windows Multimedia)파일 다운로드1
13601정성태4/19/20241026닷넷: 2243. C# - PCM 사운드 재생(NAudio)파일 다운로드1
13600정성태4/18/20241067닷넷: 2242. C# - 관리 스레드와 비관리 스레드
13599정성태4/17/2024975닷넷: 2241. C# - WAV 파일의 PCM 사운드 재생(Windows Multimedia)파일 다운로드1
13598정성태4/16/20241018닷넷: 2240. C# - WAV 파일 포맷 + LIST 헤더파일 다운로드2
13597정성태4/15/20241053닷넷: 2239. C# - WAV 파일의 PCM 데이터 생성 및 출력파일 다운로드1
13596정성태4/14/20241135닷넷: 2238. C# - WAV 기본 파일 포맷파일 다운로드1
13595정성태4/13/20241087닷넷: 2237. C# - Audio 장치 열기 (Windows Multimedia, NAudio)파일 다운로드1
13594정성태4/12/20241112닷넷: 2236. C# - Audio 장치 열람 (Windows Multimedia, NAudio)파일 다운로드1
13593정성태4/8/20241123닷넷: 2235. MSBuild - AccelerateBuildsInVisualStudio 옵션
13592정성태4/2/20241478C/C++: 165. CLion으로 만든 Rust Win32 DLL을 C#과 연동 [1]
[1]  2  3  4  5  6  7  8  9  10  11  12  13  14  15  ...