borg-serve.1 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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-06-18" "" "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.
  39. .sp
  40. borg serve can currently support:
  41. .INDENT 0.0
  42. .IP \(bu 2
  43. Getting automatically started via ssh when the borg client uses a <ssh://> \&...
  44. remote repository. In this mode, \fIborg serve\fP will live until that ssh connection
  45. gets terminated.
  46. .IP \(bu 2
  47. Getting started by some other means (not by the borg client) as a long\-running socket
  48. server to be used for borg clients using a socket://... repository (see the \fI\-\-socket\fP
  49. option if you do not want to use the default path for the socket and pid file).
  50. .UNINDENT
  51. .sp
  52. Please note that \fIborg serve\fP does not support giving a specific repository via the
  53. \fI\-\-repo\fP option or \fIBORG_REPO\fP environment variable. It is always the borg client which
  54. specifies the repo to use when talking to \fIborg serve\fP\&.
  55. .sp
  56. The \-\-permissions option allows enforcing repository permissions:
  57. .INDENT 0.0
  58. .IP \(bu 2
  59. \fIall\fP: All permissions are granted (default, permissions system is not used)
  60. .IP \(bu 2
  61. \fIno\-delete\fP: Allow reading and writing, disallow deleting and overwriting data.
  62. New archives can be created, existing archives can not be deleted. New chunks can
  63. be added, existing chunks can not be deleted or overwritten.
  64. .IP \(bu 2
  65. \fIwrite\-only\fP: Allow writing, disallow reading data.
  66. New archives can be created, existing archives can not be read.
  67. New chunks can be added, existing chunks can not be read, deleted or overwritten.
  68. .IP \(bu 2
  69. \fIread\-only\fP: Allow reading, disallow writing or deleting data.
  70. Existing archives can be read, but no archives can be created or deleted.
  71. .UNINDENT
  72. .SH OPTIONS
  73. .sp
  74. See \fIborg\-common(1)\fP for common options of Borg commands.
  75. .SS options
  76. .INDENT 0.0
  77. .TP
  78. .BI \-\-restrict\-to\-path \ PATH
  79. 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 point directly to a repository.
  80. .TP
  81. .BI \-\-restrict\-to\-repository \ PATH
  82. 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 point directly 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.
  83. .TP
  84. .B \-\-permissions
  85. Set repository permission mode. Overrides BORG_REPO_PERMISSIONS environment variable.
  86. .UNINDENT
  87. .SH EXAMPLES
  88. .sp
  89. \fBborg serve\fP has special support for ssh forced commands (see \fBauthorized_keys\fP
  90. example below): if the environment variable SSH_ORIGINAL_COMMAND is set it will
  91. ignore some options given on the command line and use the values from the
  92. variable instead. This only applies to a carefully controlled allowlist of safe
  93. options. This list currently contains:
  94. .INDENT 0.0
  95. .IP \(bu 2
  96. Options that control the log level and debug topics printed
  97. such as \fB\-\-verbose\fP, \fB\-\-info\fP, \fB\-\-debug\fP, \fB\-\-debug\-topic\fP, etc.
  98. .IP \(bu 2
  99. \fB\-\-lock\-wait\fP to allow the client to control how long to wait before
  100. giving up and aborting the operation when another process is holding a lock.
  101. .UNINDENT
  102. .sp
  103. Environment variables (such as BORG_XXX) contained in the original
  104. command sent by the client are \fInot\fP interpreted, but ignored. If BORG_XXX environment
  105. variables should be set on the \fBborg serve\fP side, then these must be set in system\-specific
  106. locations like \fB/etc/environment\fP or in the forced command itself (example below).
  107. .INDENT 0.0
  108. .INDENT 3.5
  109. .sp
  110. .EX
  111. # Allow an SSH keypair to run only borg, and only have access to /path/to/repo.
  112. # Use key options to disable unneeded and potentially dangerous SSH functionality.
  113. # This will help to secure an automated remote backup system.
  114. $ cat ~/.ssh/authorized_keys
  115. command=\(dqborg serve \-\-restrict\-to\-path /path/to/repo\(dq,restrict ssh\-rsa AAAAB3[...]
  116. # Specify repository permissions for an SSH keypair.
  117. $ cat ~/.ssh/authorized_keys
  118. command=\(dqborg serve \-\-permissions=read\-only\(dq,restrict ssh\-rsa AAAAB3[...]
  119. # Set a BORG_XXX environment variable on the \(dqborg serve\(dq side
  120. $ cat ~/.ssh/authorized_keys
  121. command=\(dqBORG_XXX=value borg serve [...]\(dq,restrict ssh\-rsa [...]
  122. .EE
  123. .UNINDENT
  124. .UNINDENT
  125. .sp
  126. \fBNOTE:\fP
  127. .INDENT 0.0
  128. .INDENT 3.5
  129. The examples above use the \fBrestrict\fP directive and assume a POSIX
  130. compliant shell set as the user\(aqs login shell.
  131. This does automatically block potential dangerous ssh features, even when
  132. they are added in a future update. Thus, this option should be preferred.
  133. .sp
  134. If you\(aqre using openssh\-server < 7.2, however, you have to specify explicitly
  135. the ssh features to restrict and cannot simply use the restrict option as it
  136. has been introduced in v7.2. We recommend to use
  137. \fBno\-port\-forwarding,no\-X11\-forwarding,no\-pty,no\-agent\-forwarding,no\-user\-rc\fP
  138. in this case.
  139. .UNINDENT
  140. .UNINDENT
  141. .sp
  142. Details about sshd usage: sshd(8) <https://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man8/sshd.8>
  143. .SS SSH Configuration
  144. .sp
  145. \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\&.
  146. .sp
  147. In order to avoid this, it is recommended to perform the following additional SSH configuration:
  148. .sp
  149. Either in the client side\(aqs \fB~/.ssh/config\fP file, or in the client\(aqs \fB/etc/ssh/ssh_config\fP file:
  150. .INDENT 0.0
  151. .INDENT 3.5
  152. .sp
  153. .EX
  154. Host backupserver
  155. ServerAliveInterval 10
  156. ServerAliveCountMax 30
  157. .EE
  158. .UNINDENT
  159. .UNINDENT
  160. .sp
  161. Replacing \fBbackupserver\fP with the hostname, FQDN or IP address of the borg server.
  162. .sp
  163. 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.
  164. .sp
  165. On the server side\(aqs \fBsshd\fP configuration file (typically \fB/etc/ssh/sshd_config\fP):
  166. .INDENT 0.0
  167. .INDENT 3.5
  168. .sp
  169. .EX
  170. ClientAliveInterval 10
  171. ClientAliveCountMax 30
  172. .EE
  173. .UNINDENT
  174. .UNINDENT
  175. .sp
  176. This will cause the server to send a keep alive 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.
  177. .sp
  178. If you then run borg commands with \fB\-\-lock\-wait 600\fP, this gives sufficient time for the borg serve processes to terminate after the SSH connection is torn down after the 300 second wait for the keepalives to fail.
  179. .sp
  180. You may, of course, modify the timeout values demonstrated above to values that suit your environment and use case.
  181. .sp
  182. When the client is untrusted, it is a good idea to set the backup
  183. user\(aqs shell to a simple implementation (\fB/bin/sh\fP is only an example and may or may
  184. not be such a simple implementation):
  185. .INDENT 0.0
  186. .INDENT 3.5
  187. .sp
  188. .EX
  189. chsh \-s /bin/sh BORGUSER
  190. .EE
  191. .UNINDENT
  192. .UNINDENT
  193. .sp
  194. Because the configured shell is used by openssh <https://www.openssh.com/>
  195. to execute the command configured through the \fBauthorized_keys\fP file
  196. using \fB\(dq$SHELL\(dq \-c \(dq$COMMAND\(dq\fP,
  197. setting a minimal shell implementation reduces the attack surface
  198. compared to when a feature\-rich and complex shell implementation is
  199. used.
  200. .SH SEE ALSO
  201. .sp
  202. \fIborg\-common(1)\fP
  203. .SH AUTHOR
  204. The Borg Collective
  205. .\" Generated by docutils manpage writer.
  206. .