basebackup_target.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*-------------------------------------------------------------------------
  2. *
  3. * basebackup_target.h
  4. * Extensibility framework for adding base backup targets.
  5. *
  6. * Portions Copyright (c) 2010-2022, PostgreSQL Global Development Group
  7. *
  8. * src/include/backup/basebackup_target.h
  9. *
  10. *-------------------------------------------------------------------------
  11. */
  12. #ifndef BASEBACKUP_TARGET_H
  13. #define BASEBACKUP_TARGET_H
  14. #include "backup/basebackup_sink.h"
  15. struct BaseBackupTargetHandle;
  16. typedef struct BaseBackupTargetHandle BaseBackupTargetHandle;
  17. /*
  18. * Extensions can call this function to create new backup targets.
  19. *
  20. * 'name' is the name of the new target.
  21. *
  22. * 'check_detail' is a function that accepts a target name and target detail
  23. * and either throws an error (if the target detail is not valid or some other
  24. * problem, such as a permissions issue, is detected) or returns a pointer to
  25. * the data that will be needed to create a bbsink implementing that target.
  26. * The second argumnt will be NULL if the TARGET_DETAIL option to the
  27. * BASE_BACKUP command was not specified.
  28. *
  29. * 'get_sink' is a function that creates the bbsink. The first argument
  30. * is the successor sink; the sink created by this function should always
  31. * forward to this sink. The second argument is the pointer returned by a
  32. * previous call to the 'check_detail' function.
  33. *
  34. * In practice, a user will type something like "pg_basebackup --target foo:bar
  35. * -Xfetch". That will cause the server to look for a backup target named
  36. * "foo". If one is found, the check_detail callback will be invoked for the
  37. * string "bar", and whatever that callback returns will be passed as the
  38. * second argument to the get_sink callback.
  39. */
  40. extern void BaseBackupAddTarget(char *name,
  41. void *(*check_detail) (char *, char *),
  42. bbsink *(*get_sink) (bbsink *, void *));
  43. /*
  44. * These functions are used by the core code to access base backup targets
  45. * added via BaseBackupAddTarget(). The core code will pass the TARGET and
  46. * TARGET_DETAIL strings obtained from the user to BaseBackupGetTargetHandle,
  47. * which will either throw an error (if the TARGET is not recognized or the
  48. * check_detail hook for that TARGET doesn't like the TARGET_DETAIL) or
  49. * return a BaseBackupTargetHandle object that can later be passed to
  50. * BaseBackupGetSink.
  51. *
  52. * BaseBackupGetSink constructs a bbsink implementing the desired target
  53. * using the BaseBackupTargetHandle and the successor bbsink. It does this
  54. * by arranging to call the get_sink() callback provided by the extension
  55. * that implements the base backup target.
  56. */
  57. extern BaseBackupTargetHandle *BaseBackupGetTargetHandle(char *target,
  58. char *target_detail);
  59. extern bbsink *BaseBackupGetSink(BaseBackupTargetHandle *handle,
  60. bbsink *next_sink);
  61. #endif