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)
13307정성태4/4/20233902.NET Framework: 2106. C# - .NET Core/5+ 환경의 Windows Forms 응용 프로그램에서 HINSTANCE 구하는 방법
13306정성태4/3/20233702Windows: 243. Win32 - 윈도우(cbWndExtra) 및 윈도우 클래스(cbClsExtra) 저장소 사용 방법
13305정성태4/1/20234068Windows: 242. Win32 - 시간 만료를 갖는 MessageBox 대화창 구현 (쉬운 버전)파일 다운로드1
13304정성태3/31/20234416VS.NET IDE: 181. Visual Studio - C/C++ 프로젝트에 application manifest 적용하는 방법
13303정성태3/30/20233789Windows: 241. 환경 변수 %PATH%에 DLL을 찾는 규칙
13302정성태3/30/20234388Windows: 240. RDP 환경에서 바뀌는 %TEMP% 디렉터리 경로
13301정성태3/29/20234483Windows: 239. C/C++ - Windows 10 Version 1607부터 지원하는 /DEPENDENTLOADFLAG 옵션파일 다운로드1
13300정성태3/28/20234125Windows: 238. Win32 - Modal UI 창에 올바른 Owner(HWND)를 설정해야 하는 이유
13299정성태3/27/20233896Windows: 237. Win32 - 모든 메시지 루프를 탈출하는 WM_QUIT 메시지
13298정성태3/27/20233878Windows: 236. Win32 - MessageBeep 소리가 안 들린다면?
13297정성태3/26/20234555Windows: 235. Win32 - Code Modal과 UI Modal
13296정성태3/25/20233886Windows: 234. IsDialogMessage와 협업하는 WM_GETDLGCODE Win32 메시지 [1]파일 다운로드1
13295정성태3/24/20234161Windows: 233. Win32 - modeless 대화창을 modal처럼 동작하게 만드는 방법파일 다운로드1
13294정성태3/22/20234330.NET Framework: 2105. LargeAddressAware 옵션이 적용된 닷넷 32비트 프로세스의 가용 메모리 - 두 번째
13293정성태3/22/20234396오류 유형: 853. dumpbin - warning LNK4048: Invalid format file; ignored
13292정성태3/21/20234510Windows: 232. C/C++ - 일반 창에도 사용 가능한 IsDialogMessage파일 다운로드1
13291정성태3/20/20234895.NET Framework: 2104. C# Windows Forms - WndProc 재정의와 IMessageFilter 사용 시의 차이점
13290정성태3/19/20234365.NET Framework: 2103. C# - 윈도우에서 기본 제공하는 FindText 대화창 사용법파일 다운로드1
13289정성태3/18/20233565Windows: 231. Win32 - 대화창 템플릿의 2진 리소스를 읽어들여 자식 윈도우를 생성하는 방법파일 다운로드1
13288정성태3/17/20233680Windows: 230. Win32 - 대화창의 DLU 단위를 pixel로 변경하는 방법파일 다운로드1
13287정성태3/16/20233841Windows: 229. Win32 - 대화창 템플릿의 2진 리소스를 읽어들여 윈도우를 직접 띄우는 방법파일 다운로드1
13286정성태3/15/20234287Windows: 228. Win32 - 리소스에 포함된 대화창 Template의 2진 코드 해석 방법
13285정성태3/14/20233868Windows: 227. Win32 C/C++ - Dialog Procedure를 재정의하는 방법파일 다운로드1
13284정성태3/13/20234093Windows: 226. Win32 C/C++ - Dialog에서 값을 반환하는 방법파일 다운로드1
13283정성태3/12/20233644오류 유형: 852. 파이썬 - TypeError: coercing to Unicode: need string or buffer, NoneType found
13282정성태3/12/20233961Linux: 58. WSL - nohup 옵션이 필요한 경우
1  2  3  4  5  6  7  8  9  10  11  12  [13]  14  15  ...