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)
13466정성태11/29/20232665닷넷: 2175. C# - DllImport 메서드의 AOT 지원을 위한 LibraryImport 옵션
13465정성태11/28/20232420개발 환경 구성: 689. MSBuild - CopyToOutputDirectory가 "dotnet publish" 시에는 적용되지 않는 문제파일 다운로드1
13464정성태11/28/20232530닷넷: 2174. C# - .NET 7부터 UnmanagedCallersOnly 함수 export 기능을 AOT 빌드에 통합파일 다운로드1
13463정성태11/27/20232429오류 유형: 881. Visual Studio - NU1605: Warning As Error: Detected package downgrade
13462정성태11/27/20232430오류 유형: 880. Visual Studio - error CS0246: The type or namespace name '...' could not be found
13461정성태11/26/20232507닷넷: 2173. .NET Core 3/5+ 기반의 COM Server를 registry 등록 없이 사용하는 방법파일 다운로드1
13460정성태11/26/20232447닷넷: 2172. .NET 6+ 기반의 COM Server 내에 Type Library를 내장하는 방법파일 다운로드1
13459정성태11/26/20232482닷넷: 2171. .NET Core 3/5+ 기반의 COM Server를 기존의 regasm처럼 등록하는 방법파일 다운로드1
13458정성태11/26/20232488닷넷: 2170. .NET Core/5+ 기반의 COM Server를 tlb 파일을 생성하는 방법(tlbexp)
13457정성태11/25/20232382VS.NET IDE: 187. Visual Studio - 16.9 버전부터 추가된 "Display inline type hints" 옵션
13456정성태11/25/20232725닷넷: 2169. C# - OpenAI를 사용해 PDF 데이터를 대상으로 OpenAI 챗봇 작성 [1]파일 다운로드1
13455정성태11/25/20232627닷넷: 2168. C# - Azure.AI.OpenAI 패키지로 OpenAI 사용파일 다운로드1
13454정성태11/23/20232928닷넷: 2167. C# - Qdrant Vector DB를 이용한 Embedding 벡터 값 보관/조회 (Azure OpenAI) [1]파일 다운로드1
13453정성태11/23/20232380오류 유형: 879. docker desktop 설치 시 "Invalid JSON string. (Exception from HRESULT: 0x83750007)"
13452정성태11/22/20232490닷넷: 2166. C# - Azure OpenAI API를 이용해 사용자가 제공하는 정보를 대상으로 검색하는 방법파일 다운로드1
13451정성태11/21/20232616닷넷: 2165. C# - Azure OpenAI API를 이용해 ChatGPT처럼 동작하는 콘솔 응용 프로그램 제작파일 다운로드1
13450정성태11/21/20232421닷넷: 2164. C# - Octokit을 이용한 GitHub Issue 검색파일 다운로드1
13449정성태11/21/20232537개발 환경 구성: 688. Azure OpenAI 서비스 신청 방법
13448정성태11/20/20232877닷넷: 2163. .NET 8 - Dynamic PGO를 결합한 성능 향상파일 다운로드1
13447정성태11/16/20232749닷넷: 2162. ASP.NET Core 웹 사이트의 SSL 설정을 코드로 하는 방법
13446정성태11/16/20232703닷넷: 2161. .NET Conf 2023 - Day 1 Blazor 개요 정리
13445정성태11/15/20233029Linux: 62. 리눅스/WSL에서 CA 인증서를 저장하는 방법
13444정성태11/15/20232749닷넷: 2160. C# 12 - Experimental 특성 지원
13443정성태11/14/20232797개발 환경 구성: 687. OpenSSL로 생성한 사용자 인증서를 ASP.NET Core 웹 사이트에 적용하는 방법
13442정성태11/13/20232561개발 환경 구성: 686. 비주얼 스튜디오로 실행한 ASP.NET Core 사이트를 WSL 2 인스턴스에서 https로 접속하는 방법
13441정성태11/12/20232943닷넷: 2159. C# - ASP.NET Core 프로젝트에서 서버 Socket을 직접 생성하는 방법파일 다운로드1
1  2  3  4  5  6  [7]  8  9  10  11  12  13  14  15  ...