syncthing-versioning.7 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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 "SYNCTHING-VERSIONING" "7" "Jun 02, 2024" "v1.27.7" "Syncthing"
  31. .SH NAME
  32. syncthing-versioning \- Keep automatic backups of deleted files by other nodes
  33. .sp
  34. Syncthing supports archiving the old version of a file when it is deleted or
  35. replaced with a newer version from the cluster. This is called “file
  36. versioning” and uses one of the available \fIversioning strategies\fP described
  37. below. File versioning is configured per folder, on a per\-device basis, and
  38. defaults to “no file versioning”, i.e. no old copies of files are kept.
  39. .sp
  40. \fBNOTE:\fP
  41. .INDENT 0.0
  42. .INDENT 3.5
  43. Versioning applies to changes received \fIfrom other devices\fP\&. That is, if
  44. Alice has versioning turned on and Bob changes a file, the old version
  45. will be archived on Alice’s computer when that change is synced from
  46. Bob. If Alice changes a file locally on her own computer Syncthing will
  47. not and can not archive the old version.
  48. .UNINDENT
  49. .UNINDENT
  50. .sp
  51. The applicable configuration options for each versioning strategy are described
  52. below. For most of them it’s possible to specify where the versions are stored,
  53. with the default being the \fB\&.stversions\fP folder inside the shared folder path.
  54. If you set a custom version path, please ensure that it’s on the same partition
  55. or filesystem as the regular folder path, as moving files there may otherwise
  56. fail.
  57. .SH TRASH CAN FILE VERSIONING
  58. .sp
  59. This versioning strategy emulates the common “trash can” approach. When a file
  60. is deleted or replaced due to a change on a remote device, it is moved to
  61. the trash can in the \fB\&.stversions\fP folder. If a file with the same name was
  62. already in the trash can it is replaced.
  63. .sp
  64. A \fI\%configuration option\fP is
  65. available to clean the trash can from files older than a specified number of
  66. days. If this is set to a positive number of days, files will be removed when
  67. they have been in the trash can that long. Setting this to zero prevents any
  68. files from being removed from the trash can automatically.
  69. .SH SIMPLE FILE VERSIONING
  70. .sp
  71. With “Simple File Versioning” files are moved to the \fB\&.stversions\fP folder when
  72. replaced or deleted on a remote device. In addition to the
  73. \fI\%cleanoutDays\fP option, this strategy also takes a
  74. value in an input titled “Keep Versions” which tells Syncthing how many old
  75. versions of the file it should \fI\%keep\fP\&. For
  76. example, if you set this value to 5, if a file is replaced 5 times on a remote
  77. device, you will see 5 time\-stamped versions on that file in the \fB\&.stversions\fP
  78. folder on the other devices sharing the same folder.
  79. .SH STAGGERED FILE VERSIONING
  80. .sp
  81. With “Staggered File Versioning” files are also moved to the \fB\&.stversions\fP
  82. folder when replaced or deleted on a remote device (just like “Simple File
  83. Versioning”), however, versions are automatically deleted if they are older than
  84. the maximum age or exceed the number of files allowed in an interval.
  85. .sp
  86. The following intervals are used and they each have a maximum number of files
  87. that will be kept for each.
  88. .INDENT 0.0
  89. .TP
  90. .B 1 Hour
  91. For the first hour, the oldest version in every 30\-seconds interval is
  92. kept.
  93. .TP
  94. .B 1 Day
  95. For the first day, the oldest version in every hour is kept.
  96. .TP
  97. .B 30 Days
  98. For the first 30 days, the oldest version in every day is kept.
  99. .TP
  100. .B Until Maximum Age
  101. Until maximum age, the oldest version in every week is kept.
  102. .TP
  103. .B Maximum Age
  104. The maximum time to keep a version in days. For example, to keep replaced or
  105. deleted files in the \fB\&.stversions\fP folder for an entire year, use 365. If
  106. only for 10 days, use 10. Corresponds to the
  107. \fI\%maxAge\fP option.
  108. \fBNote: Set to 0 to keep versions forever.\fP
  109. .UNINDENT
  110. .sp
  111. This means that there is only one version in each interval and as files age they
  112. will be deleted unless when the interval they are entering is empty. By keeping
  113. the oldest versions this versioning scheme preserves the file if it is
  114. overwritten.
  115. .sp
  116. For more info, check the \X'tty: link https://github.com/syncthing/syncthing/blob/main/lib/versioner/staggered_test.go#L32'\fI\%unit test file\fP <\fBhttps://github.com/syncthing/syncthing/blob/main/lib/versioner/staggered_test.go#L32\fP>\X'tty: link'
  117. that shows which versions are deleted for a specific run.
  118. .SH EXTERNAL FILE VERSIONING
  119. .sp
  120. This versioning strategy delegates the decision on what to do to an
  121. \fI\%external command\fP (e.g. a program or a
  122. command line script). Just prior to a file being replaced, the command will be
  123. executed. The file needs to be removed from the folder in the process, or
  124. otherwise Syncthing will report an error. The command can use the following
  125. templated arguments:
  126. .INDENT 0.0
  127. .TP
  128. .B %FOLDER_PATH%
  129. Path to the folder
  130. .TP
  131. .B %FILE_PATH%
  132. Path to the file within the folder
  133. .UNINDENT
  134. .sp
  135. Note that the former expands to the path of the actual Syncthing folder,
  136. and the latter to the path inside that folder. For instance, if you use
  137. the default \fBSync\fP folder in Windows, and the full path to the file is
  138. \fBC:\eUsers\eUser\eSync\eFamily photos\eIMG_2021\-03\-01.jpg\fP, then the
  139. \fB%FOLDER_PATH%\fP will be \fBC:\eUsers\eUser\eSync\fP, and the
  140. \fB%FILE_PATH%\fP will be \fBFamily photos\eIMG_2021\-03\-01.jpg\fP\&.
  141. .SS Example for Unixes
  142. .sp
  143. Let’s say I want to keep the latest version of each file as they are replaced
  144. or removed; essentially I want a “trash can”\-like behavior. For this, I create
  145. the following script and store it as \fB/Users/jb/bin/onlylatest.sh\fP (i.e. the
  146. \fBbin\fP directory in my home directory):
  147. .INDENT 0.0
  148. .INDENT 3.5
  149. .sp
  150. .EX
  151. #!/bin/sh
  152. set \-eu
  153. # Where I want my versions stored
  154. versionspath=~/.trashcan
  155. # The parameters we get from Syncthing
  156. folderpath=\(dq$1\(dq
  157. filepath=\(dq$2\(dq
  158. # First ensure the dir where we need to store the file exists
  159. outpath=$(dirname \(dq$versionspath/$filepath\(dq)
  160. mkdir \-p \(dq$outpath\(dq
  161. # Then move the file there
  162. mv \-f \(dq$folderpath/$filepath\(dq \(dq$versionspath/$filepath\(dq
  163. .EE
  164. .UNINDENT
  165. .UNINDENT
  166. .sp
  167. I must ensure that the script has execute permissions (\fBchmod 755
  168. onlylatest.sh\fP), then configure Syncthing with command \fB/Users/jb/bin/onlylatest.sh %FOLDER_PATH% %FILE_PATH%\fP
  169. .sp
  170. Let’s assume I have a folder “default” in ~/Sync, and that within that folder
  171. there is a file \fBdocs/letter.txt\fP that is being replaced or deleted. The
  172. script will be called as if I ran this from the command line:
  173. .INDENT 0.0
  174. .INDENT 3.5
  175. .sp
  176. .EX
  177. $ /Users/jb/bin/onlylatest.sh /Users/jb/Sync docs/letter.txt
  178. .EE
  179. .UNINDENT
  180. .UNINDENT
  181. .sp
  182. The script will then move the file in question to
  183. \fB~/.trashcan/docs/letter.txt\fP, replacing any previous version of that letter
  184. that may already have been there.
  185. .SS Examples for Windows
  186. .SS Move to a given folder using the command prompt (CMD)
  187. .sp
  188. On Windows we can use a batch script to perform the same “trash can”\-like
  189. behavior as mentioned above. I created the following script and saved it as
  190. \fBC:\eUsers\emfrnd\eScripts\eonlylatest.bat\fP\&.
  191. .INDENT 0.0
  192. .INDENT 3.5
  193. .sp
  194. .EX
  195. @echo off
  196. rem Enable UTF\-8 encoding to deal with multilingual folder and file names
  197. chcp 65001
  198. rem We need command extensions for md to create intermediate folders in one go
  199. setlocal enableextensions
  200. rem Where I want my versions stored
  201. set \(dqversions_path=%USERPROFILE%\e.trashcan\(dq
  202. rem The parameters we get from Syncthing, \(aq~\(aq removes quotes if any
  203. set \(dqfolder_path=%~1\(dq
  204. set \(dqfile_path=%~2\(dq
  205. rem First ensure the dir where we need to store the file exists
  206. for %%f in (\(dq%versions_path%\e%file_path%\(dq) do set \(dqoutput_path=%%~dpf\(dq
  207. if not exist \(dq%output_path%\(dq md \(dq%output_path%\(dq || exit /b
  208. rem Finally move the file, overwrite existing file if any
  209. move /y \(dq%folder_path%\e%file_path%\(dq \(dq%versions_path%\e%file_path%\(dq
  210. .EE
  211. .UNINDENT
  212. .UNINDENT
  213. .sp
  214. Finally, I set \fB\(dqC:\eUsers\emfrnd\eScripts\eonlylatest.bat\(dq \(dq%FOLDER_PATH%\(dq
  215. \(dq%FILE_PATH%\(dq\fP as the command name in Syncthing.
  216. .SS Move to the Recycle Bin using PowerShell
  217. .sp
  218. We can use PowerShell to send files directly to the Recycle Bin, which
  219. mimics the behaviour of deleting them using the Windows Explorer.
  220. Firstly, create the following script and save it in your preferred
  221. location, e.g. \fBC:\eUsers\eUser\eScripts\eSendToRecycleBin.ps1\fP\&.
  222. .INDENT 0.0
  223. .INDENT 3.5
  224. .sp
  225. .EX
  226. # PowerShell has no native method to recycle files, so we use Visual
  227. # Basic to perform the operation. If succeeded, we also include the
  228. # recycled file in the Syncthing\(aqs DEBUG output.
  229. Add\-Type \-AssemblyName Microsoft.VisualBasic
  230. [Microsoft.VisualBasic.FileIO.FileSystem]::DeleteFile($args,\(aqOnlyErrorDialogs\(aq,\(aqSendToRecycleBin\(aq)
  231. if ($?) {
  232. Write\-Output (\(dqRecycled \(dq + $args + \(dq.\(dq)
  233. }
  234. .EE
  235. .UNINDENT
  236. .UNINDENT
  237. .sp
  238. Alternatively, the script can be expanded to send only deleted files to
  239. the Recycle Bin, and permanently delete modified ones, which makes it
  240. more consistent with how the Explorer works.
  241. .INDENT 0.0
  242. .INDENT 3.5
  243. .sp
  244. .EX
  245. # PowerShell has no native method to recycle files, so we use Visual
  246. # Basic to perform the operation.
  247. Add\-Type \-AssemblyName Microsoft.VisualBasic
  248. # We need to test if a Syncthing .tmp file exists. If it does, we assume
  249. # a modification and delete the existing file. If if does not, we assume
  250. # a deletion and recycle the current file. If succeeded, we also include
  251. # the deleted/recycled file in the Syncthing\(aqs DEBUG output.
  252. if (Test\-Path \-LiteralPath ((Split\-Path \-Path $args) + \(dq\e~syncthing~\(dq + (Split\-Path \-Path $args \-Leaf) + \(dq.tmp\(dq)) {
  253. [Microsoft.VisualBasic.FileIO.FileSystem]::DeleteFile($args,\(aqOnlyErrorDialogs\(aq,\(aqDeletePermanently\(aq)
  254. if ($?) {
  255. Write\-Output (\(dqDeleted \(dq + $args + \(dq.\(dq)
  256. }
  257. } else {
  258. [Microsoft.VisualBasic.FileIO.FileSystem]::DeleteFile($args,\(aqOnlyErrorDialogs\(aq,\(aqSendToRecycleBin\(aq)
  259. if ($?) {
  260. Write\-Output (\(dqRecycled \(dq + $args + \(dq.\(dq)
  261. }
  262. }
  263. .EE
  264. .UNINDENT
  265. .UNINDENT
  266. .sp
  267. Finally, we set the command name in Syncthing to \fBpowershell.exe
  268. \-ExecutionPolicy Bypass \-File \(dqC:\eUsers\eUser\eScripts\eSendToRecycleBin.ps1\(dq
  269. \(dq%FOLDER_PATH%\e%FILE_PATH%\(dq\fP\&.
  270. .sp
  271. The only caveat that you should be aware of is that if your Syncthing
  272. folder is located on a portable storage, such as a USB stick, or if you
  273. have the Recycle Bin disabled, then the script will end up deleting all
  274. files permanently.
  275. .SH CONFIGURATION PARAMETER REFERENCE
  276. .sp
  277. The versioning settings are grouped into their own section of each folder in the
  278. \X'tty: link #config-option-folder.versioning'\fI\%configuration file\fP\X'tty: link'\&. The following shows an
  279. example of such a section in the XML:
  280. .INDENT 0.0
  281. .INDENT 3.5
  282. .sp
  283. .EX
  284. <folder id=\(dq...\(dq>
  285. <versioning type=\(dqsimple\(dq>
  286. <cleanupIntervalS>3600</cleanupIntervalS>
  287. <fsPath></fsPath>
  288. <fsType>basic</fsType>
  289. <param key=\(dqcleanoutDays\(dq val=\(dq0\(dq></param>
  290. <param key=\(dqkeep\(dq val=\(dq5\(dq></param>
  291. </versioning>
  292. </folder>
  293. .EE
  294. .UNINDENT
  295. .UNINDENT
  296. .INDENT 0.0
  297. .TP
  298. .B versioning.type
  299. Selects one of the versioning strategies: \fBtrashcan\fP, \fBsimple\fP,
  300. \fBstaggered\fP, \fBexternal\fP or leave empty to disable versioning completely.
  301. .UNINDENT
  302. .INDENT 0.0
  303. .TP
  304. .B versioning.fsPath
  305. Overrides the path where old versions of files are stored and defaults to
  306. \fB\&.stversions\fP if left empty. An absolute or relative path can be
  307. specified. The latter is interpreted relative to the shared folder path, if
  308. the \fI\%fsType\fP is configured as \fBbasic\fP\&. Ignored
  309. for the \fBexternal\fP versioning strategy.
  310. .sp
  311. This option used to be stored under the keys \fBfsPath\fP or \fBversionsPath\fP
  312. in the \fI\%params\fP element.
  313. .UNINDENT
  314. .INDENT 0.0
  315. .TP
  316. .B versioning.fsType
  317. The internal file system implementation used to access this versions folder.
  318. Only applies if \fI\%fsPath\fP is also set non\-empty,
  319. otherwise the \X'tty: link #config-option-folder.filesystemtype'\fI\%filesystemType\fP\X'tty: link' from the folder element is used
  320. instead. Refer to that option description for possible values. Ignored for
  321. the \fBexternal\fP versioning strategy.
  322. .sp
  323. This option used to be stored under the key \fBfsType\fP in the
  324. \fI\%params\fP element.
  325. .UNINDENT
  326. .INDENT 0.0
  327. .TP
  328. .B versioning.cleanupIntervalS
  329. The interval, in seconds, for running cleanup in the versions folder. Zero
  330. to disable periodic cleaning. Limited to one year (31536000 seconds).
  331. Ignored for the \fBexternal\fP versioning strategy.
  332. .sp
  333. This option used to be stored under the key \fBcleanInterval\fP in the
  334. \fI\%params\fP element.
  335. .UNINDENT
  336. .INDENT 0.0
  337. .TP
  338. .B versioning.params
  339. Each versioning strategy can have configuration parameters specific to its
  340. implementation under this element.
  341. .UNINDENT
  342. .INDENT 0.0
  343. .TP
  344. .B versioning.params.cleanoutDays
  345. The number of days to keep files in the versions folder. Zero means to keep
  346. forever. Older elements encountered during cleanup are removed.
  347. .UNINDENT
  348. .INDENT 0.0
  349. .TP
  350. .B versioning.params.keep
  351. The number of old versions to keep, per file.
  352. .UNINDENT
  353. .INDENT 0.0
  354. .TP
  355. .B versioning.params.maxAge
  356. The maximum time to keep a version, in seconds. Zero means to keep forever.
  357. .UNINDENT
  358. .INDENT 0.0
  359. .TP
  360. .B versioning.params.command
  361. External command to execute for storing a file version about to be replaced
  362. or deleted. If the path to the application contains spaces, it should be
  363. quoted.
  364. .UNINDENT
  365. .SH AUTHOR
  366. The Syncthing Authors
  367. .SH COPYRIGHT
  368. 2014-2019, The Syncthing Authors
  369. .\" Generated by docutils manpage writer.
  370. .