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)
13389정성태7/5/20233557개발 환경 구성: 684. IIS Express로 호스팅하는 웹을 WSL 환경에서 접근하는 방법
13388정성태7/3/20233706오류 유형: 871. 윈도우 탐색기에서 열리지 않는 zip 파일 - The Compressed (zipped) Folder '[...].zip' is invalid. [1]파일 다운로드1
13387정성태6/28/20233775오류 유형: 870. _mysql - Commands out of sync; you can't run this command now
13386정성태6/27/20233854Linux: 61. docker - 원격 제어를 위한 TCP 바인딩 추가
13385정성태6/27/20234070Linux: 60. Linux - 외부에서의 접속을 허용하기 위한 TCP 포트 여는 방법
13384정성태6/26/20233780.NET Framework: 2131. C# - Source Generator로 해결하는 enum 박싱 문제파일 다운로드1
13383정성태6/26/20233527개발 환경 구성: 683. GPU 런타임을 사용하는 Colab 노트북 설정
13382정성태6/25/20233594.NET Framework: 2130. C# - Win32 API를 이용한 윈도우 계정 정보 (예: 마지막 로그온 시간)파일 다운로드1
13381정성태6/25/20234005오류 유형: 869. Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
13380정성태6/24/20233430스크립트: 52. 파이썬 3.x에서의 동적 함수 추가
13379정성태6/23/20233447스크립트: 51. 파이썬 2.x에서의 동적 함수 추가
13378정성태6/22/20233349오류 유형: 868. docker - build 시 "CANCELED ..." 뜨는 문제
13377정성태6/22/20237236오류 유형: 867. 파이썬 mysqlclient 2.2.x 설치 시 "Specify MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS env vars manually" 오류
13376정성태6/21/20233596.NET Framework: 2129. C# - Polly를 이용한 클라이언트 측의 요청 재시도파일 다운로드1
13375정성태6/20/20233259스크립트: 50. Transformers (신경망 언어모델 라이브러리) 강좌 - 2장 코드 실행 결과
13374정성태6/20/20233348오류 유형: 866. 파이썬 - <class 'AttributeError'> module 'flask.json' has no attribute 'JSONEncoder'
13373정성태6/19/20234659오류 유형: 865. 파이썬 - pymssql 설치 관련 오류 정리
13372정성태6/15/20233271개발 환경 구성: 682. SQL Server TLS 통신을 위해 사용되는 키 길이 확인 방법
13371정성태6/15/20233345개발 환경 구성: 681. openssl - 인증서 버전(V1 / V3)
13370정성태6/14/20233507개발 환경 구성: 680. C# - Ubuntu + Microsoft.Data.SqlClient + SQL Server 2008 R2 연결 방법 - TLS 1.2 지원
13369정성태6/13/20233316개발 환경 구성: 679. PyCharm(을 비롯해 JetBrains에 속한 여타) IDE에서 내부 Window들의 탭이 없어진 경우
13368정성태6/13/20233485개발 환경 구성: 678. openssl로 생성한 인증서를 SQL Server의 암호화 인증서로 설정하는 방법
13367정성태6/10/20233640오류 유형: 864. openssl로 만든 pfx 인증서를 Windows Server 2016 이하에서 등록 시 "The password you entered is incorrect" 오류 발생
13366정성태6/10/20233376.NET Framework: 2128. C# - 윈도우 시스템에서 지원하는 암호화 목록(Cipher Suites) 나열파일 다운로드1
13365정성태6/8/20233104오류 유형: 863. MODIFY FILE encountered operating system error 112(failed to retrieve text for this error. Reason: 15105)
13364정성태6/8/20233941.NET Framework: 2127. C# - Ubuntu + Microsoft.Data.SqlClient + SQL Server 2008 R2 연결 방법 [1]
1  2  3  4  5  6  7  8  9  [10]  11  12  13  14  15  ...