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.

294 lines
6.2 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, 0x04
  16. };
  17. static LPCWSTR s_WRITERNAME = L"BeTest Writer";
  18. void CTestVssWriter::Initialize()
  19. {
  20. HRESULT hr;
  21. CHECK_SUCCESS(CVssWriter::Initialize
  22. (
  23. s_WRITERID,
  24. s_WRITERNAME,
  25. VSS_UT_USERDATA,
  26. VSS_ST_OTHER
  27. ));
  28. }
  29. bool STDMETHODCALLTYPE CTestVssWriter::OnIdentify(IN IVssCreateWriterMetadata *pMetadata)
  30. {
  31. HRESULT hr;
  32. if (m_lWait & x_maskWaitGatherWriterMetadata)
  33. {
  34. wprintf(L"OnIdentify sleeping 20 seconds.\n");
  35. Sleep(20000);
  36. }
  37. CHECK_SUCCESS(pMetadata->AddIncludeFiles
  38. (
  39. L"%systemroot%\\config",
  40. L"mytestfiles.*",
  41. false,
  42. NULL
  43. ));
  44. CHECK_SUCCESS(pMetadata->AddExcludeFiles
  45. (
  46. L"%systemroot%\\config",
  47. L"*.tmp",
  48. true
  49. ));
  50. CHECK_SUCCESS(pMetadata->AddComponent
  51. (
  52. VSS_CT_DATABASE,
  53. L"\\mydatabases",
  54. L"db1",
  55. L"this is my main database",
  56. x_rgbIcon,
  57. x_cbIcon,
  58. true,
  59. true,
  60. true
  61. ));
  62. CHECK_SUCCESS(pMetadata->AddDatabaseFiles
  63. (
  64. L"\\mydatabases",
  65. L"db1",
  66. L"e:\\databases",
  67. L"foo.db"
  68. ));
  69. CHECK_SUCCESS(pMetadata->AddDatabaseLogFiles
  70. (
  71. L"\\mydatabases",
  72. L"db1",
  73. L"e:\\logs",
  74. L"foo.log"
  75. ));
  76. CHECK_SUCCESS(pMetadata->SetRestoreMethod
  77. (
  78. VSS_RME_RESTORE_IF_NOT_THERE,
  79. NULL,
  80. NULL,
  81. VSS_WRE_ALWAYS,
  82. true
  83. ));
  84. CHECK_SUCCESS(pMetadata->AddAlternateLocationMapping
  85. (
  86. L"c:\\databases",
  87. L"*.db",
  88. false,
  89. L"e:\\databases\\restore"
  90. ));
  91. CHECK_SUCCESS(pMetadata->AddAlternateLocationMapping
  92. (
  93. L"d:\\logs",
  94. L"*.log",
  95. false,
  96. L"e:\\databases\\restore"
  97. ));
  98. return true;
  99. }
  100. bool STDMETHODCALLTYPE CTestVssWriter::OnPrepareBackup(IN IVssWriterComponents *pWriterComponents)
  101. {
  102. unsigned cComponents;
  103. LPCWSTR wszBackupType;
  104. if (m_lWait & x_maskWaitPrepareBackup)
  105. {
  106. wprintf(L"OnPrepareBackup sleeping 10 seconds.\n");
  107. Sleep(10000);
  108. }
  109. switch(GetBackupType())
  110. {
  111. default:
  112. wszBackupType = L"undefined";
  113. break;
  114. case VSS_BT_FULL:
  115. wszBackupType = L"full";
  116. break;
  117. case VSS_BT_INCREMENTAL:
  118. wszBackupType = L"incremental";
  119. break;
  120. case VSS_BT_DIFFERENTIAL:
  121. wszBackupType = L"differential";
  122. break;
  123. case VSS_BT_OTHER:
  124. wszBackupType = L"other";
  125. break;
  126. }
  127. wprintf(L"\n\n****WRITER*****\nBackup Type = %s\n", wszBackupType);
  128. wprintf
  129. (
  130. L"AreComponentsSelected = %s\n",
  131. AreComponentsSelected() ? L"yes" : L"no"
  132. );
  133. wprintf
  134. (
  135. L"BootableSystemStateBackup = %s\n\n",
  136. IsBootableSystemStateBackedUp() ? L"yes" : L"no"
  137. );
  138. pWriterComponents->GetComponentCount(&cComponents);
  139. for(unsigned iComponent = 0; iComponent < cComponents; iComponent++)
  140. {
  141. HRESULT hr;
  142. CComPtr<IVssComponent> pComponent;
  143. VSS_COMPONENT_TYPE ct;
  144. CComBSTR bstrLogicalPath;
  145. CComBSTR bstrComponentName;
  146. CHECK_SUCCESS(pWriterComponents->GetComponent(iComponent, &pComponent));
  147. CHECK_SUCCESS(pComponent->GetLogicalPath(&bstrLogicalPath));
  148. CHECK_SUCCESS(pComponent->GetComponentType(&ct));
  149. CHECK_SUCCESS(pComponent->GetComponentName(&bstrComponentName));
  150. if (ct != VSS_CT_DATABASE)
  151. {
  152. wprintf(L"component type is incorrect\n");
  153. DebugBreak();
  154. }
  155. wprintf
  156. (
  157. L"Backing up database %s\\%s.\n",
  158. bstrLogicalPath,
  159. bstrComponentName
  160. );
  161. WCHAR buf[100];
  162. wsprintf (buf, L"backupTime = %d", (INT) time(NULL));
  163. CHECK_SUCCESS(pComponent->SetBackupMetadata(buf));
  164. wprintf(L"\nBACKUPMETADATA=%s\n", buf);
  165. }
  166. wprintf(L"\n******END WRITER******\n\n");
  167. return true;
  168. }
  169. bool STDMETHODCALLTYPE CTestVssWriter::OnPrepareSnapshot()
  170. {
  171. IsPathAffected(L"e:\\foobar");
  172. return true;
  173. }
  174. bool STDMETHODCALLTYPE CTestVssWriter::OnFreeze()
  175. {
  176. return true;
  177. }
  178. bool STDMETHODCALLTYPE CTestVssWriter::OnThaw()
  179. {
  180. return true;
  181. }
  182. bool STDMETHODCALLTYPE CTestVssWriter::OnBackupComplete(IN IVssWriterComponents *pWriterComponents)
  183. {
  184. if (m_lWait & x_maskWaitBackupComplete)
  185. {
  186. wprintf(L"OnBackupComplete sleeping 10 seconds.\n");
  187. Sleep(20000);
  188. }
  189. unsigned cComponents;
  190. pWriterComponents->GetComponentCount(&cComponents);
  191. for(unsigned iComponent = 0; iComponent < cComponents; iComponent++)
  192. {
  193. HRESULT hr;
  194. CComPtr<IVssComponent> pComponent;
  195. VSS_COMPONENT_TYPE ct;
  196. CComBSTR bstrLogicalPath;
  197. CComBSTR bstrComponentName;
  198. bool bBackupSucceeded;
  199. CHECK_SUCCESS(pWriterComponents->GetComponent(iComponent, &pComponent));
  200. CHECK_SUCCESS(pComponent->GetLogicalPath(&bstrLogicalPath));
  201. CHECK_SUCCESS(pComponent->GetComponentType(&ct));
  202. CHECK_SUCCESS(pComponent->GetComponentName(&bstrComponentName));
  203. CHECK_SUCCESS(pComponent->GetBackupSucceeded(&bBackupSucceeded));
  204. if (ct != VSS_CT_DATABASE)
  205. {
  206. wprintf(L"component type is incorrect\n");
  207. DebugBreak();
  208. }
  209. wprintf
  210. (
  211. L"Database %s\\%s backup %s.\n",
  212. bstrLogicalPath,
  213. bstrComponentName,
  214. bBackupSucceeded ? L"succeeded" : L"failed"
  215. );
  216. CComBSTR bstrMetadata;
  217. CHECK_SUCCESS(pComponent->GetBackupMetadata(&bstrMetadata));
  218. wprintf(L"BACKUPMETADATA=%s\n", bstrMetadata);
  219. }
  220. return true;
  221. }
  222. bool STDMETHODCALLTYPE CTestVssWriter::OnPreRestore(IN IVssWriterComponents *pComponent)
  223. {
  224. UNREFERENCED_PARAMETER(pComponent);
  225. return true;
  226. }
  227. bool STDMETHODCALLTYPE CTestVssWriter::OnPostRestore(IN IVssWriterComponents *pComponent)
  228. {
  229. UNREFERENCED_PARAMETER(pComponent);
  230. if (m_lWait & x_maskWaitPostRestore)
  231. {
  232. wprintf(L"OnPostRestore sleeping 10 seconds.\n");
  233. Sleep(10000);
  234. }
  235. return true;
  236. }
  237. bool STDMETHODCALLTYPE CTestVssWriter::OnAbort()
  238. {
  239. return true;
  240. }