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)
13538정성태1/25/20242422닷넷: 2211. C# - NonGC(FOH) 영역에 .NET 개체를 생성파일 다운로드1
13537정성태1/24/20242524닷넷: 2210. C# - Native 메모리에 .NET 개체를 생성파일 다운로드1
13536정성태1/23/20242599닷넷: 2209. .NET 8 - NonGC Heap / FOH (Frozen Object Heap) [1]
13535정성태1/22/20242468닷넷: 2208. C# - GCHandle 구조체의 메모리 분석
13534정성태1/21/20242259닷넷: 2207. C# - SQL Server DB를 bacpac으로 Export/Import파일 다운로드1
13533정성태1/18/20242481닷넷: 2206. C# - TCP KeepAlive의 서버 측 구현파일 다운로드1
13532정성태1/17/20242366닷넷: 2205. C# - SuperSimpleTcp 사용 시 주의할 점파일 다운로드1
13531정성태1/16/20242271닷넷: 2204. C# - TCP KeepAlive에 새로 추가된 Retry 옵션파일 다운로드1
13530정성태1/15/20242207닷넷: 2203. C# - Python과의 AES 암호화 연동파일 다운로드1
13529정성태1/15/20242085닷넷: 2202. C# - PublishAot의 glibc에 대한 정적 링킹하는 방법
13528정성태1/14/20242231Linux: 68. busybox 컨테이너에서 실행 가능한 C++, Go 프로그램 빌드
13527정성태1/14/20242154오류 유형: 892. Visual Studio - Failed to launch debug adapter. Additional information may be available in the output window.
13526정성태1/14/20242240닷넷: 2201. C# - Facebook 연동 / 사용자 탈퇴 처리 방법
13525정성태1/13/20242208오류 유형: 891. Visual Studio - Web Application을 실행하지 못하는 IISExpress
13524정성태1/12/20242294오류 유형: 890. 한국투자증권 KIS Developers OpenAPI - GW라우팅 중 오류가 발생했습니다.
13523정성태1/12/20242098오류 유형: 889. Visual Studio - error : A project with that name is already opened in the solution.
13522정성태1/11/20242241닷넷: 2200. C# - HttpClient.PostAsJsonAsync 호출 시 "Transfer-Encoding: chunked" 대신 "Content-Length" 헤더 처리
13521정성태1/11/20242300닷넷: 2199. C# - 한국투자증권 KIS Developers OpenAPI의 WebSocket Ping, Pong 처리
13520정성태1/10/20242069오류 유형: 888. C# - Unable to resolve service for type 'Microsoft.Extensions.ObjectPool.ObjectPool`....'
13519정성태1/10/20242126닷넷: 2198. C# - Reflection을 이용한 ClientWebSocket의 Ping 호출파일 다운로드1
13518정성태1/9/20242383닷넷: 2197. C# - ClientWebSocket의 Ping, Pong 처리
13517정성태1/8/20242218스크립트: 63. Python - 공개 패키지를 이용한 위성 이미지 생성 (pystac_client, odc.stac)
13516정성태1/7/20242339닷넷: 2196. IIS - AppPool의 "Disable Overlapped Recycle" 옵션의 부작용
13515정성태1/6/20242613닷넷: 2195. async 메서드 내에서 C# 7의 discard 구문 활용 사례 [1]
13514정성태1/5/20242294개발 환경 구성: 702. IIS - AppPool의 "Disable Overlapped Recycle" 옵션
13513정성태1/5/20242221닷넷: 2194. C# - WebActivatorEx / System.Web의 PreApplicationStartMethod 특성
1  2  3  [4]  5  6  7  8  9  10  11  12  13  14  15  ...