Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

262 lines
5.7 KiB

  1. #include "stdafx.hxx"
  2. #include "vss.h"
  3. #include "vswriter.h"
  4. #include "cwriter.h"
  5. #include "debug.h"
  6. #include "time.h"
  7. #include "msxml.h"
  8. #define IID_PPV_ARG( Type, Expr ) IID_##Type, reinterpret_cast< void** >( static_cast< Type** >( Expr ) )
  9. #define SafeQI( Type, Expr ) QueryInterface( IID_PPV_ARG( Type, Expr ) )
  10. static BYTE x_rgbIcon[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
  11. static unsigned x_cbIcon = 10;
  12. static VSS_ID s_WRITERID =
  13. {
  14. 0xc0577ae6, 0xd741, 0x452a,
  15. 0x8c, 0xba, 0x99, 0xd7, 0x44, 0x00, 0x8c, 0x05
  16. };
  17. static LPCWSTR s_WRITERNAME = L"MP Test Writer";
  18. void CTestVssWriter::Initialize()
  19. {
  20. CHECK_SUCCESS(CVssWriter::Initialize
  21. (
  22. s_WRITERID,
  23. s_WRITERNAME,
  24. VSS_UT_USERDATA,
  25. VSS_ST_OTHER
  26. ));
  27. }
  28. bool STDMETHODCALLTYPE CTestVssWriter::OnIdentify(IN IVssCreateWriterMetadata *pMetadata)
  29. {
  30. CHECK_SUCCESS(pMetadata->AddIncludeFiles
  31. (
  32. L"%systemroot%\\config",
  33. L"mytestfiles.*",
  34. false,
  35. NULL
  36. ));
  37. CHECK_SUCCESS(pMetadata->AddExcludeFiles
  38. (
  39. L"%systemroot%\\config",
  40. L"*.tmp",
  41. true
  42. ));
  43. CHECK_SUCCESS(pMetadata->AddComponent
  44. (
  45. VSS_CT_DATABASE,
  46. L"\\mydatabases",
  47. L"db1",
  48. L"this is my main database",
  49. x_rgbIcon,
  50. x_cbIcon,
  51. true,
  52. true,
  53. true
  54. ));
  55. CHECK_SUCCESS(pMetadata->AddDatabaseFiles
  56. (
  57. L"\\mydatabases",
  58. L"db1",
  59. L"e:\\databases",
  60. L"foo.db"
  61. ));
  62. CHECK_SUCCESS(pMetadata->AddDatabaseLogFiles
  63. (
  64. L"\\mydatabases",
  65. L"db1",
  66. L"e:\\logs",
  67. L"foo.log"
  68. ));
  69. CHECK_SUCCESS(pMetadata->SetRestoreMethod
  70. (
  71. VSS_RME_RESTORE_TO_ALTERNATE_LOCATION,
  72. NULL,
  73. NULL,
  74. VSS_WRE_ALWAYS,
  75. true
  76. ));
  77. CHECK_SUCCESS(pMetadata->AddAlternateLocationMapping
  78. (
  79. L"c:\\databases",
  80. L"*.db",
  81. false,
  82. L"e:\\databases\\restore"
  83. ));
  84. CHECK_SUCCESS(pMetadata->AddAlternateLocationMapping
  85. (
  86. L"d:\\logs",
  87. L"*.log",
  88. false,
  89. L"e:\\databases\\restore"
  90. ));
  91. return true;
  92. }
  93. bool STDMETHODCALLTYPE CTestVssWriter::OnPrepareBackup(IN IVssWriterComponents *pWriterComponents)
  94. {
  95. unsigned cComponents;
  96. LPCWSTR wszBackupType;
  97. switch(GetBackupType())
  98. {
  99. default:
  100. wszBackupType = L"undefined";
  101. break;
  102. case VSS_BT_FULL:
  103. wszBackupType = L"full";
  104. break;
  105. case VSS_BT_INCREMENTAL:
  106. wszBackupType = L"incremental";
  107. break;
  108. case VSS_BT_DIFFERENTIAL:
  109. wszBackupType = L"differential";
  110. break;
  111. case VSS_BT_OTHER:
  112. wszBackupType = L"other";
  113. break;
  114. }
  115. wprintf(L"\n\n****WRITER*****\nBackup Type = %s\n", wszBackupType);
  116. wprintf
  117. (
  118. L"AreComponentsSelected = %s\n",
  119. AreComponentsSelected() ? L"yes" : L"no"
  120. );
  121. wprintf
  122. (
  123. L"BootableSystemStateBackup = %s\n\n",
  124. IsBootableSystemStateBackedUp() ? L"yes" : L"no"
  125. );
  126. if (pWriterComponents)
  127. {
  128. pWriterComponents->GetComponentCount(&cComponents);
  129. for(unsigned iComponent = 0; iComponent < cComponents; iComponent++)
  130. {
  131. CComPtr<IVssComponent> pComponent;
  132. VSS_COMPONENT_TYPE ct;
  133. CComBSTR bstrLogicalPath;
  134. CComBSTR bstrComponentName;
  135. CHECK_SUCCESS(pWriterComponents->GetComponent(iComponent, &pComponent));
  136. CHECK_SUCCESS(pComponent->GetLogicalPath(&bstrLogicalPath));
  137. CHECK_SUCCESS(pComponent->GetComponentType(&ct));
  138. CHECK_SUCCESS(pComponent->GetComponentName(&bstrComponentName));
  139. if (ct != VSS_CT_DATABASE)
  140. {
  141. wprintf(L"component type is incorrect\n");
  142. DebugBreak();
  143. }
  144. wprintf
  145. (
  146. L"Backing up database %s\\%s.\n",
  147. bstrLogicalPath,
  148. bstrComponentName
  149. );
  150. WCHAR buf[100];
  151. swprintf (buf, L"backupTime = %d", (INT) time(NULL));
  152. CHECK_SUCCESS(pComponent->SetBackupMetadata(buf));
  153. wprintf(L"%s\n", buf);
  154. }
  155. }
  156. wprintf(L"\n******END WRITER******\n\n");
  157. return true;
  158. }
  159. bool STDMETHODCALLTYPE CTestVssWriter::OnPrepareSnapshot()
  160. {
  161. wprintf(L"OnPrepareSnapshot\n");
  162. return true;
  163. }
  164. bool STDMETHODCALLTYPE CTestVssWriter::OnFreeze()
  165. {
  166. wprintf(L"OnFreeze\n");
  167. return true;
  168. }
  169. bool STDMETHODCALLTYPE CTestVssWriter::OnThaw()
  170. {
  171. wprintf(L"OnThaw\n");
  172. return true;
  173. }
  174. bool STDMETHODCALLTYPE CTestVssWriter::OnBackupComplete(IN IVssWriterComponents *pWriterComponents)
  175. {
  176. unsigned cComponents;
  177. if (pWriterComponents == NULL)
  178. return true;
  179. pWriterComponents->GetComponentCount(&cComponents);
  180. for(unsigned iComponent = 0; iComponent < cComponents; iComponent++)
  181. {
  182. CComPtr<IVssComponent> pComponent;
  183. VSS_COMPONENT_TYPE ct;
  184. CComBSTR bstrLogicalPath;
  185. CComBSTR bstrComponentName;
  186. bool bBackupSucceeded;
  187. CHECK_SUCCESS(pWriterComponents->GetComponent(iComponent, &pComponent));
  188. CHECK_SUCCESS(pComponent->GetLogicalPath(&bstrLogicalPath));
  189. CHECK_SUCCESS(pComponent->GetComponentType(&ct));
  190. CHECK_SUCCESS(pComponent->GetComponentName(&bstrComponentName));
  191. CHECK_SUCCESS(pComponent->GetBackupSucceeded(&bBackupSucceeded));
  192. if (ct != VSS_CT_DATABASE)
  193. {
  194. wprintf(L"component type is incorrect\n");
  195. DebugBreak();
  196. }
  197. wprintf
  198. (
  199. L"Database %s\\%s backup %s.\n",
  200. bstrLogicalPath,
  201. bstrComponentName,
  202. bBackupSucceeded ? L"succeeded" : L"failed"
  203. );
  204. CComBSTR bstrMetadata;
  205. CHECK_SUCCESS(pComponent->GetBackupMetadata(&bstrMetadata));
  206. wprintf(L"%s\n", bstrMetadata);
  207. }
  208. return true;
  209. }
  210. bool STDMETHODCALLTYPE CTestVssWriter::OnPostRestore(IN IVssWriterComponents *pComponent)
  211. {
  212. UNREFERENCED_PARAMETER(pComponent);
  213. return true;
  214. }
  215. bool STDMETHODCALLTYPE CTestVssWriter::OnAbort()
  216. {
  217. return true;
  218. }