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.

152 lines
4.5 KiB

  1. //
  2. // sqlsnap.h Define the interface to the nt/sql snapshot handler.
  3. //
  4. // The idea here is for a pure interface, making it easy to keep the
  5. // abstraction maximized (can move to COM later, if we like).
  6. //
  7. // No C++ exceptions will be thrown across the interfaces.
  8. //
  9. // To use this interface, the calling process must invoke:
  10. // InitSQLEnvironment - once to setup the environment, establishing
  11. // the error and trace loggers.
  12. // The trace logger is optional, but an error logger must be provided.
  13. // The loggers are created by deriving from CLogFacility and implementing
  14. // a "WriteImplementation" method.
  15. //
  16. // Thereafter, calls to "CreateSqlSnapshot" are used to create snapshot objects
  17. // which encapsulate the operations needed to support storage snapshots.
  18. //
  19. // *****************************************
  20. // LIMITATIONS
  21. //
  22. // - only SIMPLE databases can be snapshot (trunc on checkpoint = 'true')
  23. // - there is no serialization of services starting or adding/changing file lists during the snapshot
  24. // - servers which are not started when the snapshot starts are skipped (non-torn databases will be
  25. // backed up fine, torn databases won't be detected).
  26. // - sql7.0 databases which are "un"-useable will prevent snapshots (the list of files can't be obtained).
  27. //
  28. #include <stdio.h>
  29. #include <stdarg.h>
  30. #include <windows.h>
  31. ////////////////////////////////////////////////////////////////////////
  32. // Standard foo for file name aliasing. This code block must be after
  33. // all includes of VSS header files.
  34. //
  35. #ifdef VSS_FILE_ALIAS
  36. #undef VSS_FILE_ALIAS
  37. #endif
  38. #define VSS_FILE_ALIAS "INCSQLSH"
  39. //
  40. ////////////////////////////////////////////////////////////////////////
  41. HRESULT InitSQLEnvironment();
  42. // Caller must provide a path checker interface.
  43. //
  44. class CCheckPath
  45. {
  46. public:
  47. virtual bool IsPathInSnapshot (const WCHAR* path) throw () = 0;
  48. };
  49. //-------------------------------------------------------------
  50. // A handler for snapshots.
  51. //
  52. class CSqlSnapshot
  53. {
  54. public:
  55. virtual ~CSqlSnapshot () throw () {};
  56. virtual HRESULT Prepare (
  57. CCheckPath* checker) throw () = 0;
  58. virtual HRESULT Freeze () throw () = 0;
  59. virtual HRESULT Thaw () throw () = 0;
  60. };
  61. extern "C" CSqlSnapshot* CreateSqlSnapshot () throw ();
  62. //-------------------------------------------------------------
  63. // An enumerator for SQL objects.
  64. //
  65. // An object of this class can have only one active query at
  66. // a time. Requesting a new enumeration will close any previous
  67. // partially fetched result.
  68. //
  69. #define MAX_SERVERNAME 128
  70. #define MAX_DBNAME 128
  71. struct ServerInfo
  72. {
  73. bool isOnline; // true if the server is ready for connections
  74. WCHAR name [MAX_SERVERNAME]; // null terminated name of server
  75. };
  76. struct DatabaseInfo
  77. {
  78. bool supportsFreeze; // true if a freeze operation is supported
  79. WCHAR name [MAX_DBNAME]; // null terminated name of database
  80. };
  81. struct DatabaseFileInfo
  82. {
  83. bool isLogFile; // true if this is a log file
  84. WCHAR name [MAX_PATH];
  85. };
  86. class CSqlEnumerator
  87. {
  88. public:
  89. virtual ~CSqlEnumerator () throw () {};
  90. virtual HRESULT FirstServer (
  91. ServerInfo* pServer) throw () = 0;
  92. virtual HRESULT NextServer (
  93. ServerInfo* pServer) throw () = 0;
  94. virtual HRESULT FirstDatabase (
  95. const WCHAR* pServerName,
  96. DatabaseInfo* pDbInfo) throw () = 0;
  97. virtual HRESULT NextDatabase (
  98. DatabaseInfo* pDbInfo) throw () = 0;
  99. virtual HRESULT FirstFile (
  100. const WCHAR* pServerName,
  101. const WCHAR* pDbName,
  102. DatabaseFileInfo* pFileInfo) throw () = 0;
  103. virtual HRESULT NextFile (
  104. DatabaseFileInfo* pFileInfo) throw () = 0;
  105. };
  106. extern "C" CSqlEnumerator* CreateSqlEnumerator () throw ();
  107. //------------------------------------------------------
  108. // HRESULTS returned by the interface.
  109. //
  110. // WARNING: I used facility = x78 arbitrarily!
  111. //
  112. #define SQLLIB_ERROR(code) MAKE_HRESULT(SEVERITY_ERROR, 0x78, code)
  113. #define SQLLIB_STATUS(code) MAKE_HRESULT(SEVERITY_SUCCESS, 0x78, code)
  114. // Status codes
  115. //
  116. #define S_SQLLIB_NOSERVERS SQLLIB_STATUS(1) // no SQLServers of interest (from Prepare)
  117. // Error codes
  118. //
  119. #define E_SQLLIB_GENERIC SQLLIB_ERROR(1) // something bad, check the errorlog
  120. #define E_SQLLIB_TORN_DB SQLLIB_ERROR(2) // database would be torn by the snapshot
  121. #define E_SQLLIB_NO_SUPPORT SQLLIB_ERROR(3) // 6.5 doesn't support snapshots
  122. #define E_SQLLIB_PROTO SQLLIB_ERROR(4) // protocol error (ex: freeze before prepare)
  123. #define E_SQLLIB_NONSIMPLE SQLLIB_ERROR(5) // only simple databases are supported