borg-serve.1 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. .\" Man page generated from reStructuredText.
  2. .
  3. .
  4. .nr rst2man-indent-level 0
  5. .
  6. .de1 rstReportMargin
  7. \\$1 \\n[an-margin]
  8. level \\n[rst2man-indent-level]
  9. level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
  10. -
  11. \\n[rst2man-indent0]
  12. \\n[rst2man-indent1]
  13. \\n[rst2man-indent2]
  14. ..
  15. .de1 INDENT
  16. .\" .rstReportMargin pre:
  17. . RS \\$1
  18. . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
  19. . nr rst2man-indent-level +1
  20. .\" .rstReportMargin post:
  21. ..
  22. .de UNINDENT
  23. . RE
  24. .\" indent \\n[an-margin]
  25. .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
  26. .nr rst2man-indent-level -1
  27. .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
  28. .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
  29. ..
  30. .TH "BORG-SERVE" "1" "2025-10-31" "" "borg backup tool"
  31. .SH NAME
  32. borg-serve \- Start in server mode. This command is usually not used manually.
  33. .SH SYNOPSIS
  34. .sp
  35. borg [common options] serve [options]
  36. .SH DESCRIPTION
  37. .sp
  38. This command starts a repository server process. This command is usually not used manually.
  39. .SH OPTIONS
  40. .sp
  41. See \fIborg\-common(1)\fP for common options of Borg commands.
  42. .SS options
  43. .INDENT 0.0
  44. .TP
  45. .BI \-\-restrict\-to\-path \ PATH
  46. restrict repository access to PATH. Can be specified multiple times to allow the client access to several directories. Access to all sub\-directories is granted implicitly; PATH doesn\(aqt need to directly point to a repository.
  47. .TP
  48. .BI \-\-restrict\-to\-repository \ PATH
  49. restrict repository access. Only the repository located at PATH (no sub\-directories are considered) is accessible. Can be specified multiple times to allow the client access to several repositories. Unlike \fB\-\-restrict\-to\-path\fP sub\-directories are not accessible; PATH needs to directly point at a repository location. PATH may be an empty directory or the last element of PATH may not exist, in which case the client may initialize a repository there.
  50. .TP
  51. .B \-\-append\-only
  52. only allow appending to repository segment files. Note that this only affects the low level structure of the repository, and running \fIdelete\fP or \fIprune\fP will still be allowed. See \fIappend_only_mode\fP in Additional Notes for more details.
  53. .TP
  54. .BI \-\-storage\-quota \ QUOTA
  55. Override storage quota of the repository (e.g. 5G, 1.5T). When a new repository is initialized, sets the storage quota on the new repository as well. Default: no quota.
  56. .UNINDENT
  57. .SH EXAMPLES
  58. .sp
  59. \fBborg serve\fP has special support for SSH forced commands (see \fBauthorized_keys\fP
  60. example below): if the environment variable SSH_ORIGINAL_COMMAND is set it will
  61. ignore some options given on the command line and use the values from the
  62. variable instead. This only applies to a carefully controlled allowlist of safe
  63. options. This list currently contains:
  64. .INDENT 0.0
  65. .IP \(bu 2
  66. Options that control the log level and debug topics printed
  67. such as \fB\-\-verbose\fP, \fB\-\-info\fP, \fB\-\-debug\fP, \fB\-\-debug\-topic\fP, etc.
  68. .IP \(bu 2
  69. \fB\-\-lock\-wait\fP to allow the client to control how long to wait before
  70. giving up and aborting the operation when another process is holding a lock.
  71. .UNINDENT
  72. .sp
  73. Environment variables (such as BORG_XXX) contained in the original
  74. command sent by the client are \fInot\fP interpreted; they are ignored. If BORG_XXX environment
  75. variables need to be set on the \fBborg serve\fP side, then these must be set in system\-specific
  76. locations like \fB/etc/environment\fP or in the forced command itself (example below).
  77. .INDENT 0.0
  78. .INDENT 3.5
  79. .sp
  80. .EX
  81. # Allow an SSH key pair to only run borg, and only have access to /path/to/repo.
  82. # Use key options to disable unneeded and potentially dangerous SSH functionality.
  83. # This helps secure an automated remote backup system.
  84. $ cat ~/.ssh/authorized_keys
  85. command=\(dqborg serve \-\-restrict\-to\-path /path/to/repo\(dq,restrict ssh\-rsa AAAAB3[...]
  86. # Set a BORG_XXX environment variable on the \(ga\(gaborg serve\(ga\(ga side.
  87. $ cat ~/.ssh/authorized_keys
  88. command=\(dqBORG_XXX=value borg serve [...]\(dq,restrict ssh\-rsa [...]
  89. .EE
  90. .UNINDENT
  91. .UNINDENT
  92. .sp
  93. \fBNOTE:\fP
  94. .INDENT 0.0
  95. .INDENT 3.5
  96. The examples above use the \fBrestrict\fP directive and assume a POSIX\-compliant
  97. shell set as the user\(aqs login shell.
  98. This automatically blocks potentially dangerous SSH features, even when
  99. they are added in a future update. Thus, this option should be preferred.
  100. .sp
  101. If you\(aqre using OpenSSH server < 7.2, however, you have to explicitly specify
  102. the SSH features to restrict and cannot simply use the \fBrestrict\fP option as it
  103. was introduced in v7.2. We recommend using
  104. \fBno\-port\-forwarding,no\-X11\-forwarding,no\-pty,no\-agent\-forwarding,no\-user\-rc\fP
  105. in this case.
  106. .UNINDENT
  107. .UNINDENT
  108. .sp
  109. Details about sshd usage: sshd(8) <https://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man8/sshd.8>
  110. .SS SSH Configuration
  111. .sp
  112. \fBborg serve\fP\(aqs pipes (\fBstdin\fP/\fBstdout\fP/\fBstderr\fP) are connected to the \fBsshd\fP process on the server side. In the event that the SSH connection between \fBborg serve\fP and the client is disconnected or stuck abnormally (for example, due to a network outage), it can take a long time for \fBsshd\fP to notice the client is disconnected. In the meantime, \fBsshd\fP continues running, and as a result so does the \fBborg serve\fP process holding the lock on the repository. This can cause subsequent \fBborg\fP operations on the remote repository to fail with the error: \fBFailed to create/acquire the lock\fP\&.
  113. .sp
  114. In order to avoid this, it is recommended to perform the following additional SSH configuration:
  115. .sp
  116. Either in the client side\(aqs \fB~/.ssh/config\fP file, or in the client\(aqs \fB/etc/ssh/ssh_config\fP file:
  117. .INDENT 0.0
  118. .INDENT 3.5
  119. .sp
  120. .EX
  121. Host backupserver
  122. ServerAliveInterval 10
  123. ServerAliveCountMax 30
  124. .EE
  125. .UNINDENT
  126. .UNINDENT
  127. .sp
  128. Replace \fBbackupserver\fP with the hostname, FQDN, or IP address of the Borg server.
  129. .sp
  130. This will cause the client to send a keepalive to the server every 10 seconds. If 30 consecutive keepalives are sent without a response (a time of 300 seconds), the SSH client process will be terminated, causing the Borg process to terminate gracefully.
  131. .sp
  132. On the server side\(aqs \fBsshd\fP configuration file (typically \fB/etc/ssh/sshd_config\fP):
  133. .INDENT 0.0
  134. .INDENT 3.5
  135. .sp
  136. .EX
  137. ClientAliveInterval 10
  138. ClientAliveCountMax 30
  139. .EE
  140. .UNINDENT
  141. .UNINDENT
  142. .sp
  143. This will cause the server to send a keepalive to the client every 10 seconds. If 30 consecutive keepalives are sent without a response (a time of 300 seconds), the server\(aqs sshd process will be terminated, causing the \fBborg serve\fP process to terminate gracefully and release the lock on the repository.
  144. .sp
  145. If you then run Borg commands with \fB\-\-lock\-wait 600\fP, this gives sufficient time for the \fBborg serve\fP processes to terminate after the SSH connection is torn down following the 300\-second wait for the keepalives to fail.
  146. .sp
  147. You may, of course, modify the timeout values demonstrated above to values that suit your environment and use case.
  148. .sp
  149. When the client is untrusted, it is a good idea to set the backup
  150. user\(aqs shell to a simple implementation (\fB/bin/sh\fP is only an example and may or may
  151. not be such a simple implementation):
  152. .INDENT 0.0
  153. .INDENT 3.5
  154. .sp
  155. .EX
  156. chsh \-s /bin/sh BORGUSER
  157. .EE
  158. .UNINDENT
  159. .UNINDENT
  160. .sp
  161. Because the configured shell is used by openssh <https://www.openssh.com/>
  162. to execute the command configured through the \fBauthorized_keys\fP file
  163. using \fB\(dq$SHELL\(dq \-c \(dq$COMMAND\(dq\fP,
  164. setting a minimal shell implementation reduces the attack surface
  165. compared to when a feature\-rich and complex shell implementation is
  166. used.
  167. .SH SEE ALSO
  168. .sp
  169. \fIborg\-common(1)\fP
  170. .SH AUTHOR
  171. The Borg Collective
  172. .\" Generated by docutils manpage writer.
  173. .