serve_cmd.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import argparse
  2. from ._common import Highlander
  3. from ..constants import * # NOQA
  4. from ..helpers import parse_storage_quota
  5. from ..remote3 import RepositoryServer
  6. from ..logger import create_logger
  7. logger = create_logger()
  8. class ServeMixIn:
  9. def do_serve(self, args):
  10. """Start in server mode. This command is usually not used manually."""
  11. RepositoryServer(
  12. restrict_to_paths=args.restrict_to_paths,
  13. restrict_to_repositories=args.restrict_to_repositories,
  14. append_only=args.append_only,
  15. storage_quota=args.storage_quota,
  16. use_socket=args.use_socket,
  17. ).serve()
  18. def build_parser_serve(self, subparsers, common_parser, mid_common_parser):
  19. from ._common import process_epilog
  20. serve_epilog = process_epilog(
  21. """
  22. This command starts a repository server process.
  23. borg serve can currently support:
  24. - Getting automatically started via ssh when the borg client uses a ssh://...
  25. remote repository. In this mode, `borg serve` will live until that ssh connection
  26. gets terminated.
  27. - Getting started by some other means (not by the borg client) as a long-running socket
  28. server to be used for borg clients using a socket://... repository (see the `--socket`
  29. option if you do not want to use the default path for the socket and pid file).
  30. """
  31. )
  32. subparser = subparsers.add_parser(
  33. "serve",
  34. parents=[common_parser],
  35. add_help=False,
  36. description=self.do_serve.__doc__,
  37. epilog=serve_epilog,
  38. formatter_class=argparse.RawDescriptionHelpFormatter,
  39. help="start repository server process",
  40. )
  41. subparser.set_defaults(func=self.do_serve)
  42. subparser.add_argument(
  43. "--restrict-to-path",
  44. metavar="PATH",
  45. dest="restrict_to_paths",
  46. action="append",
  47. help="restrict repository access to PATH. "
  48. "Can be specified multiple times to allow the client access to several directories. "
  49. "Access to all sub-directories is granted implicitly; PATH doesn't need to point directly to a repository.",
  50. )
  51. subparser.add_argument(
  52. "--restrict-to-repository",
  53. metavar="PATH",
  54. dest="restrict_to_repositories",
  55. action="append",
  56. help="restrict repository access. Only the repository located at PATH "
  57. "(no sub-directories are considered) is accessible. "
  58. "Can be specified multiple times to allow the client access to several repositories. "
  59. "Unlike ``--restrict-to-path`` sub-directories are not accessible; "
  60. "PATH needs to point directly at a repository location. "
  61. "PATH may be an empty directory or the last element of PATH may not exist, in which case "
  62. "the client may initialize a repository there.",
  63. )
  64. subparser.add_argument(
  65. "--append-only",
  66. dest="append_only",
  67. action="store_true",
  68. help="only allow appending to repository segment files. Note that this only "
  69. "affects the low level structure of the repository, and running `delete` "
  70. "or `prune` will still be allowed. See :ref:`append_only_mode` in Additional "
  71. "Notes for more details.",
  72. )
  73. subparser.add_argument(
  74. "--storage-quota",
  75. metavar="QUOTA",
  76. dest="storage_quota",
  77. type=parse_storage_quota,
  78. default=None,
  79. action=Highlander,
  80. help="Override storage quota of the repository (e.g. 5G, 1.5T). "
  81. "When a new repository is initialized, sets the storage quota on the new "
  82. "repository as well. Default: no quota.",
  83. )