usage.rst 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015
  1. .. include:: global.rst.inc
  2. .. highlight:: none
  3. .. _detailed_usage:
  4. Usage
  5. =====
  6. |project_name| consists of a number of commands. Each command accepts
  7. a number of arguments and options. The following sections will describe each
  8. command in detail.
  9. General
  10. -------
  11. Repository URLs
  12. ~~~~~~~~~~~~~~~
  13. **Local filesystem** (or locally mounted network filesystem):
  14. ``/path/to/repo`` - filesystem path to repo directory, absolute path
  15. ``path/to/repo`` - filesystem path to repo directory, relative path
  16. Also, stuff like ``~/path/to/repo`` or ``~other/path/to/repo`` works (this is
  17. expanded by your shell).
  18. Note: you may also prepend a ``file://`` to a filesystem path to get URL style.
  19. **Remote repositories** accessed via ssh user@host:
  20. ``user@host:/path/to/repo`` - remote repo, absolute path
  21. ``ssh://user@host:port/path/to/repo`` - same, alternative syntax, port can be given
  22. **Remote repositories with relative pathes** can be given using this syntax:
  23. ``user@host:path/to/repo`` - path relative to current directory
  24. ``user@host:~/path/to/repo`` - path relative to user's home directory
  25. ``user@host:~other/path/to/repo`` - path relative to other's home directory
  26. Note: giving ``user@host:/./path/to/repo`` or ``user@host:/~/path/to/repo`` or
  27. ``user@host:/~other/path/to/repo``is also supported, but not required here.
  28. **Remote repositories with relative pathes, alternative syntax with port**:
  29. ``ssh://user@host:port/./path/to/repo`` - path relative to current directory
  30. ``ssh://user@host:port/~/path/to/repo`` - path relative to user's home directory
  31. ``ssh://user@host:port/~other/path/to/repo`` - path relative to other's home directory
  32. If you frequently need the same repo URL, it is a good idea to set the
  33. ``BORG_REPO`` environment variable to set a default for the repo URL:
  34. ::
  35. export BORG_REPO='ssh://user@host:port/path/to/repo'
  36. Then just leave away the repo URL if only a repo URL is needed and you want
  37. to use the default - it will be read from BORG_REPO then.
  38. Use ``::`` syntax to give the repo URL when syntax requires giving a positional
  39. argument for the repo (e.g. ``borg mount :: /mnt``).
  40. Repository / Archive Locations
  41. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  42. Many commands want either a repository (just give the repo URL, see above) or
  43. an archive location, which is a repo URL followed by ``::archive_name``.
  44. Archive names must not contain the ``/`` (slash) character. For simplicity,
  45. maybe also avoid blanks or other characters that have special meaning on the
  46. shell or in a filesystem (borg mount will use the archive name as directory
  47. name).
  48. If you have set BORG_REPO (see above) and an archive location is needed, use
  49. ``::archive_name`` - the repo URL part is then read from BORG_REPO.
  50. Type of log output
  51. ~~~~~~~~~~~~~~~~~~
  52. The log level of the builtin logging configuration defaults to WARNING.
  53. This is because we want |project_name| to be mostly silent and only output
  54. warnings, errors and critical messages, unless output has been requested
  55. by supplying an option that implies output (eg, --list or --progress).
  56. Log levels: DEBUG < INFO < WARNING < ERROR < CRITICAL
  57. Use ``--debug`` to set DEBUG log level -
  58. to get debug, info, warning, error and critical level output.
  59. Use ``--info`` (or ``-v`` or ``--verbose``) to set INFO log level -
  60. to get info, warning, error and critical level output.
  61. Use ``--warning`` (default) to set WARNING log level -
  62. to get warning, error and critical level output.
  63. Use ``--error`` to set ERROR log level -
  64. to get error and critical level output.
  65. Use ``--critical`` to set CRITICAL log level -
  66. to get critical level output.
  67. While you can set misc. log levels, do not expect that every command will
  68. give different output on different log levels - it's just a possibility.
  69. .. warning:: Options --critical and --error are provided for completeness,
  70. their usage is not recommended as you might miss important information.
  71. Return codes
  72. ~~~~~~~~~~~~
  73. |project_name| can exit with the following return codes (rc):
  74. ::
  75. 0 = success (logged as INFO)
  76. 1 = warning (operation reached its normal end, but there were warnings -
  77. you should check the log, logged as WARNING)
  78. 2 = error (like a fatal error, a local or remote exception, the operation
  79. did not reach its normal end, logged as ERROR)
  80. 128+N = killed by signal N (e.g. 137 == kill -9)
  81. If you use ``--show-rc``, the return code is also logged at the indicated
  82. level as the last log entry.
  83. Environment Variables
  84. ~~~~~~~~~~~~~~~~~~~~~
  85. |project_name| uses some environment variables for automation:
  86. General:
  87. BORG_REPO
  88. When set, use the value to give the default repository location. If a command needs an archive
  89. parameter, you can abbreviate as `::archive`. If a command needs a repository parameter, you
  90. can either leave it away or abbreviate as `::`, if a positional parameter is required.
  91. BORG_PASSPHRASE
  92. When set, use the value to answer the passphrase question for encrypted repositories.
  93. It is used when a passphrase is needed to access a encrypted repo as well as when a new
  94. passphrase should be initially set when initializing an encrypted repo.
  95. See also BORG_NEW_PASSPHRASE.
  96. BORG_NEW_PASSPHRASE
  97. When set, use the value to answer the passphrase question when a **new** passphrase is asked for.
  98. This variable is checked first. If it is not set, BORG_PASSPHRASE will be checked also.
  99. Main usecase for this is to fully automate ``borg change-passphrase``.
  100. BORG_DISPLAY_PASSPHRASE
  101. When set, use the value to answer the "display the passphrase for verification" question when defining a new passphrase for encrypted repositories.
  102. BORG_LOGGING_CONF
  103. When set, use the given filename as INI_-style logging configuration.
  104. BORG_RSH
  105. When set, use this command instead of ``ssh``. This can be used to specify ssh options, such as
  106. a custom identity file ``ssh -i /path/to/private/key``. See ``man ssh`` for other options.
  107. BORG_REMOTE_PATH
  108. When set, use the given path/filename as remote path (default is "borg").
  109. Using ``--remote-path PATH`` commandline option overrides the environment variable.
  110. BORG_FILES_CACHE_TTL
  111. When set to a numeric value, this determines the maximum "time to live" for the files cache
  112. entries (default: 20). The files cache is used to quickly determine whether a file is unchanged.
  113. The FAQ explains this more detailled in: :ref:`always_chunking`
  114. TMPDIR
  115. where temporary files are stored (might need a lot of temporary space for some operations)
  116. Some automatic "answerers" (if set, they automatically answer confirmation questions):
  117. BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK=no (or =yes)
  118. For "Warning: Attempting to access a previously unknown unencrypted repository"
  119. BORG_RELOCATED_REPO_ACCESS_IS_OK=no (or =yes)
  120. For "Warning: The repository at location ... was previously located at ..."
  121. BORG_CHECK_I_KNOW_WHAT_I_AM_DOING=NO (or =YES)
  122. For "Warning: 'check --repair' is an experimental feature that might result in data loss."
  123. BORG_DELETE_I_KNOW_WHAT_I_AM_DOING=NO (or =YES)
  124. For "You requested to completely DELETE the repository *including* all archives it contains:"
  125. BORG_RECREATE_I_KNOW_WHAT_I_AM_DOING=NO (or =YES)
  126. For "recreate is an experimental feature."
  127. Note: answers are case sensitive. setting an invalid answer value might either give the default
  128. answer or ask you interactively, depending on whether retries are allowed (they by default are
  129. allowed). So please test your scripts interactively before making them a non-interactive script.
  130. Directories and files:
  131. BORG_KEYS_DIR
  132. Default to '~/.config/borg/keys'. This directory contains keys for encrypted repositories.
  133. BORG_KEY_FILE
  134. When set, use the given filename as repository key file.
  135. BORG_NONCES_DIR
  136. Default to '~/.config/borg/key-nonces'. This directory contains information borg uses to
  137. track its usage of NONCES ("numbers used once" - usually in encryption context).
  138. BORG_CACHE_DIR
  139. Default to '~/.cache/borg'. This directory contains the local cache and might need a lot
  140. of space for dealing with big repositories).
  141. Building:
  142. BORG_OPENSSL_PREFIX
  143. Adds given OpenSSL header file directory to the default locations (setup.py).
  144. BORG_LZ4_PREFIX
  145. Adds given LZ4 header file directory to the default locations (setup.py).
  146. BORG_LIBB2_PREFIX
  147. Adds given prefix directory to the default locations. If a 'include/blake2.h' is found Borg
  148. will be linked against the system libb2 instead of a bundled implementation. (setup.py)
  149. Please note:
  150. - be very careful when using the "yes" sayers, the warnings with prompt exist for your / your data's security/safety
  151. - also be very careful when putting your passphrase into a script, make sure it has appropriate file permissions
  152. (e.g. mode 600, root:root).
  153. .. _INI: https://docs.python.org/3.4/library/logging.config.html#configuration-file-format
  154. Resource Usage
  155. ~~~~~~~~~~~~~~
  156. |project_name| might use a lot of resources depending on the size of the data set it is dealing with.
  157. CPU:
  158. It won't go beyond 100% of 1 core as the code is currently single-threaded.
  159. Especially higher zlib and lzma compression levels use significant amounts
  160. of CPU cycles.
  161. Memory (RAM):
  162. The chunks index and the files index are read into memory for performance
  163. reasons.
  164. Compression, esp. lzma compression with high levels might need substantial
  165. amounts of memory.
  166. Temporary files:
  167. Reading data and metadata from a FUSE mounted repository will consume about
  168. the same space as the deduplicated chunks used to represent them in the
  169. repository.
  170. Cache files:
  171. Contains the chunks index and files index (plus a compressed collection of
  172. single-archive chunk indexes).
  173. Chunks index:
  174. Proportional to the amount of data chunks in your repo. Lots of chunks
  175. in your repo imply a big chunks index.
  176. It is possible to tweak the chunker params (see create options).
  177. Files index:
  178. Proportional to the amount of files in your last backup. Can be switched
  179. off (see create options), but next backup will be much slower if you do.
  180. Network:
  181. If your repository is remote, all deduplicated (and optionally compressed/
  182. encrypted) data of course has to go over the connection (ssh: repo url).
  183. If you use a locally mounted network filesystem, additionally some copy
  184. operations used for transaction support also go over the connection. If
  185. you backup multiple sources to one target repository, additional traffic
  186. happens for cache resynchronization.
  187. In case you are interested in more details, please read the internals documentation.
  188. File systems
  189. ~~~~~~~~~~~~
  190. We strongly recommend against using Borg (or any other database-like
  191. software) on non-journaling file systems like FAT, since it is not
  192. possible to assume any consistency in case of power failures (or a
  193. sudden disconnect of an external drive or similar failures).
  194. While Borg uses a data store that is resilient against these failures
  195. when used on journaling file systems, it is not possible to guarantee
  196. this with some hardware -- independent of the software used. We don't
  197. know a list of affected hardware.
  198. If you are suspicious whether your Borg repository is still consistent
  199. and readable after one of the failures mentioned above occured, run
  200. ``borg check --verify-data`` to make sure it is consistent.
  201. Units
  202. ~~~~~
  203. To display quantities, |project_name| takes care of respecting the
  204. usual conventions of scale. Disk sizes are displayed in `decimal
  205. <https://en.wikipedia.org/wiki/Decimal>`_, using powers of ten (so
  206. ``kB`` means 1000 bytes). For memory usage, `binary prefixes
  207. <https://en.wikipedia.org/wiki/Binary_prefix>`_ are used, and are
  208. indicated using the `IEC binary prefixes
  209. <https://en.wikipedia.org/wiki/IEC_80000-13#Prefixes_for_binary_multiples>`_,
  210. using powers of two (so ``KiB`` means 1024 bytes).
  211. Date and Time
  212. ~~~~~~~~~~~~~
  213. We format date and time conforming to ISO-8601, that is: YYYY-MM-DD and
  214. HH:MM:SS (24h clock).
  215. For more information about that, see: https://xkcd.com/1179/
  216. Unless otherwise noted, we display local date and time.
  217. Internally, we store and process date and time as UTC.
  218. Common options
  219. ~~~~~~~~~~~~~~
  220. All |project_name| commands share these options:
  221. .. include:: usage/common-options.rst.inc
  222. .. include:: usage/init.rst.inc
  223. Examples
  224. ~~~~~~~~
  225. ::
  226. # Local repository (default is to use encryption in repokey mode)
  227. $ borg init /path/to/repo
  228. # Local repository (no encryption)
  229. $ borg init --encryption=none /path/to/repo
  230. # Remote repository (accesses a remote borg via ssh)
  231. $ borg init user@hostname:backup
  232. # Remote repository (store the key your home dir)
  233. $ borg init --encryption=keyfile user@hostname:backup
  234. .. include:: usage/create.rst.inc
  235. Examples
  236. ~~~~~~~~
  237. ::
  238. # Backup ~/Documents into an archive named "my-documents"
  239. $ borg create /path/to/repo::my-documents ~/Documents
  240. # same, but list all files as we process them
  241. $ borg create --list /path/to/repo::my-documents ~/Documents
  242. # Backup ~/Documents and ~/src but exclude pyc files
  243. $ borg create /path/to/repo::my-files \
  244. ~/Documents \
  245. ~/src \
  246. --exclude '*.pyc'
  247. # Backup home directories excluding image thumbnails (i.e. only
  248. # /home/*/.thumbnails is excluded, not /home/*/*/.thumbnails)
  249. $ borg create /path/to/repo::my-files /home \
  250. --exclude 're:^/home/[^/]+/\.thumbnails/'
  251. # Do the same using a shell-style pattern
  252. $ borg create /path/to/repo::my-files /home \
  253. --exclude 'sh:/home/*/.thumbnails'
  254. # Backup the root filesystem into an archive named "root-YYYY-MM-DD"
  255. # use zlib compression (good, but slow) - default is no compression
  256. $ borg create -C zlib,6 /path/to/repo::root-{now:%Y-%m-%d} / --one-file-system
  257. # Backup a remote host locally ("pull" style) using sshfs
  258. $ mkdir sshfs-mount
  259. $ sshfs root@example.com:/ sshfs-mount
  260. $ cd sshfs-mount
  261. $ borg create /path/to/repo::example.com-root-{now:%Y-%m-%d} .
  262. $ cd ..
  263. $ fusermount -u sshfs-mount
  264. # Make a big effort in fine granular deduplication (big chunk management
  265. # overhead, needs a lot of RAM and disk space, see formula in internals
  266. # docs - same parameters as borg < 1.0 or attic):
  267. $ borg create --chunker-params 10,23,16,4095 /path/to/repo::small /smallstuff
  268. # Backup a raw device (must not be active/in use/mounted at that time)
  269. $ dd if=/dev/sdx bs=10M | borg create /path/to/repo::my-sdx -
  270. # No compression (default)
  271. $ borg create /path/to/repo::arch ~
  272. # Super fast, low compression
  273. $ borg create --compression lz4 /path/to/repo::arch ~
  274. # Less fast, higher compression (N = 0..9)
  275. $ borg create --compression zlib,N /path/to/repo::arch ~
  276. # Even slower, even higher compression (N = 0..9)
  277. $ borg create --compression lzma,N /path/to/repo::arch ~
  278. # Use short hostname, user name and current time in archive name
  279. $ borg create /path/to/repo::{hostname}-{user}-{now} ~
  280. $ borg create /path/to/repo::{hostname}-{user}-{now:%Y-%m-%d_%H:%M:%S} ~
  281. .. include:: usage/extract.rst.inc
  282. Examples
  283. ~~~~~~~~
  284. ::
  285. # Extract entire archive
  286. $ borg extract /path/to/repo::my-files
  287. # Extract entire archive and list files while processing
  288. $ borg extract --list /path/to/repo::my-files
  289. # Verify whether an archive could be successfully extracted, but do not write files to disk
  290. $ borg extract --dry-run /path/to/repo::my-files
  291. # Extract the "src" directory
  292. $ borg extract /path/to/repo::my-files home/USERNAME/src
  293. # Extract the "src" directory but exclude object files
  294. $ borg extract /path/to/repo::my-files home/USERNAME/src --exclude '*.o'
  295. # Restore a raw device (must not be active/in use/mounted at that time)
  296. $ borg extract --stdout /path/to/repo::my-sdx | dd of=/dev/sdx bs=10M
  297. .. Note::
  298. Currently, extract always writes into the current working directory ("."),
  299. so make sure you ``cd`` to the right place before calling ``borg extract``.
  300. .. include:: usage/check.rst.inc
  301. .. include:: usage/rename.rst.inc
  302. Examples
  303. ~~~~~~~~
  304. ::
  305. $ borg create /path/to/repo::archivename ~
  306. $ borg list /path/to/repo
  307. archivename Mon, 2016-02-15 19:50:19
  308. $ borg rename /path/to/repo::archivename newname
  309. $ borg list /path/to/repo
  310. newname Mon, 2016-02-15 19:50:19
  311. .. include:: usage/list.rst.inc
  312. Examples
  313. ~~~~~~~~
  314. ::
  315. $ borg list /path/to/repo
  316. Monday Mon, 2016-02-15 19:15:11
  317. repo Mon, 2016-02-15 19:26:54
  318. root-2016-02-15 Mon, 2016-02-15 19:36:29
  319. newname Mon, 2016-02-15 19:50:19
  320. ...
  321. $ borg list /path/to/repo::root-2016-02-15
  322. drwxr-xr-x root root 0 Mon, 2016-02-15 17:44:27 .
  323. drwxrwxr-x root root 0 Mon, 2016-02-15 19:04:49 bin
  324. -rwxr-xr-x root root 1029624 Thu, 2014-11-13 00:08:51 bin/bash
  325. lrwxrwxrwx root root 0 Fri, 2015-03-27 20:24:26 bin/bzcmp -> bzdiff
  326. -rwxr-xr-x root root 2140 Fri, 2015-03-27 20:24:22 bin/bzdiff
  327. ...
  328. $ borg list /path/to/repo::archiveA --list-format="{mode} {user:6} {group:6} {size:8d} {isomtime} {path}{extra}{NEWLINE}"
  329. drwxrwxr-x user user 0 Sun, 2015-02-01 11:00:00 .
  330. drwxrwxr-x user user 0 Sun, 2015-02-01 11:00:00 code
  331. drwxrwxr-x user user 0 Sun, 2015-02-01 11:00:00 code/myproject
  332. -rw-rw-r-- user user 1416192 Sun, 2015-02-01 11:00:00 code/myproject/file.ext
  333. ...
  334. .. include:: usage/diff.rst.inc
  335. Examples
  336. ~~~~~~~~
  337. ::
  338. $ borg init testrepo
  339. $ mkdir testdir
  340. $ cd testdir
  341. $ echo asdf > file1
  342. $ dd if=/dev/urandom bs=1M count=4 > file2
  343. $ touch file3
  344. $ borg create ../testrepo::archive1 .
  345. $ chmod a+x file1
  346. $ echo "something" >> file2
  347. $ borg create ../testrepo::archive2 .
  348. $ rm file3
  349. $ touch file4
  350. $ borg create ../testrepo::archive3 .
  351. $ cd ..
  352. $ borg diff testrepo::archive1 archive2
  353. [-rw-r--r-- -> -rwxr-xr-x] file1
  354. +135 B -252 B file2
  355. $ borg diff testrepo::archive2 archive3
  356. added 0 B file4
  357. removed 0 B file3
  358. $ borg diff testrepo::archive1 archive3
  359. [-rw-r--r-- -> -rwxr-xr-x] file1
  360. +135 B -252 B file2
  361. added 0 B file4
  362. removed 0 B file3
  363. .. include:: usage/delete.rst.inc
  364. Examples
  365. ~~~~~~~~
  366. ::
  367. # delete a single backup archive:
  368. $ borg delete /path/to/repo::Monday
  369. # delete the whole repository and the related local cache:
  370. $ borg delete /path/to/repo
  371. You requested to completely DELETE the repository *including* all archives it contains:
  372. repo Mon, 2016-02-15 19:26:54
  373. root-2016-02-15 Mon, 2016-02-15 19:36:29
  374. newname Mon, 2016-02-15 19:50:19
  375. Type 'YES' if you understand this and want to continue: YES
  376. .. include:: usage/prune.rst.inc
  377. Examples
  378. ~~~~~~~~
  379. Be careful, prune is a potentially dangerous command, it will remove backup
  380. archives.
  381. The default of prune is to apply to **all archives in the repository** unless
  382. you restrict its operation to a subset of the archives using ``--prefix``.
  383. When using ``--prefix``, be careful to choose a good prefix - e.g. do not use a
  384. prefix "foo" if you do not also want to match "foobar".
  385. It is strongly recommended to always run ``prune -v --list --dry-run ...``
  386. first so you will see what it would do without it actually doing anything.
  387. There is also a visualized prune example in ``docs/misc/prune-example.txt``.
  388. ::
  389. # Keep 7 end of day and 4 additional end of week archives.
  390. # Do a dry-run without actually deleting anything.
  391. $ borg prune -v --list --dry-run --keep-daily=7 --keep-weekly=4 /path/to/repo
  392. # Same as above but only apply to archive names starting with the hostname
  393. # of the machine followed by a "-" character:
  394. $ borg prune -v --list --keep-daily=7 --keep-weekly=4 --prefix='{hostname}-' /path/to/repo
  395. # Keep 7 end of day, 4 additional end of week archives,
  396. # and an end of month archive for every month:
  397. $ borg prune -v --list --keep-daily=7 --keep-weekly=4 --keep-monthly=-1 /path/to/repo
  398. # Keep all backups in the last 10 days, 4 additional end of week archives,
  399. # and an end of month archive for every month:
  400. $ borg prune -v --list --keep-within=10d --keep-weekly=4 --keep-monthly=-1 /path/to/repo
  401. .. include:: usage/info.rst.inc
  402. Examples
  403. ~~~~~~~~
  404. ::
  405. $ borg info /path/to/repo::root-2016-02-15
  406. Name: root-2016-02-15
  407. Fingerprint: 57c827621f21b000a8d363c1e163cc55983822b3afff3a96df595077a660be50
  408. Hostname: myhostname
  409. Username: root
  410. Time (start): Mon, 2016-02-15 19:36:29
  411. Time (end): Mon, 2016-02-15 19:39:26
  412. Command line: /usr/local/bin/borg create --list -C zlib,6 /path/to/repo::root-2016-02-15 / --one-file-system
  413. Number of files: 38100
  414. Original size Compressed size Deduplicated size
  415. This archive: 1.33 GB 613.25 MB 571.64 MB
  416. All archives: 1.63 GB 853.66 MB 584.12 MB
  417. Unique chunks Total chunks
  418. Chunk index: 36858 48844
  419. .. include:: usage/mount.rst.inc
  420. .. include:: usage/umount.rst.inc
  421. Examples
  422. ~~~~~~~~
  423. borg mount
  424. ++++++++++
  425. ::
  426. $ borg mount /path/to/repo::root-2016-02-15 /tmp/mymountpoint
  427. $ ls /tmp/mymountpoint
  428. bin boot etc home lib lib64 lost+found media mnt opt root sbin srv tmp usr var
  429. $ borg umount /tmp/mymountpoint
  430. ::
  431. $ borg mount -o versions /path/to/repo /tmp/mymountpoint
  432. $ ls -l /tmp/mymountpoint/home/user/doc.txt/
  433. total 24
  434. -rw-rw-r-- 1 user group 12357 Aug 26 21:19 doc.txt.cda00bc9
  435. -rw-rw-r-- 1 user group 12204 Aug 26 21:04 doc.txt.fa760f28
  436. $ fusermount -u /tmp/mymountpoint
  437. borgfs
  438. ++++++
  439. ::
  440. $ echo '/mnt/backup /tmp/myrepo fuse.borgfs defaults,noauto 0 0' >> /etc/fstab
  441. $ echo '/mnt/backup::root-2016-02-15 /tmp/myarchive fuse.borgfs defaults,noauto 0 0' >> /etc/fstab
  442. $ mount /tmp/myrepo
  443. $ mount /tmp/myarchive
  444. $ ls /tmp/myrepo
  445. root-2016-02-01 root-2016-02-2015
  446. $ ls /tmp/myarchive
  447. bin boot etc home lib lib64 lost+found media mnt opt root sbin srv tmp usr var
  448. .. Note::
  449. ``borgfs`` will be automatically provided if you used a distribution
  450. package, ``pip`` or ``setup.py`` to install |project_name|. Users of the
  451. standalone binary will have to manually create a symlink (see
  452. :ref:`pyinstaller-binary`).
  453. .. include:: usage/key_export.rst.inc
  454. .. include:: usage/key_import.rst.inc
  455. .. include:: usage/change-passphrase.rst.inc
  456. Examples
  457. ~~~~~~~~
  458. ::
  459. # Create a key file protected repository
  460. $ borg init --encryption=keyfile -v /path/to/repo
  461. Initializing repository at "/path/to/repo"
  462. Enter new passphrase:
  463. Enter same passphrase again:
  464. Remember your passphrase. Your data will be inaccessible without it.
  465. Key in "/root/.config/borg/keys/mnt_backup" created.
  466. Keep this key safe. Your data will be inaccessible without it.
  467. Synchronizing chunks cache...
  468. Archives: 0, w/ cached Idx: 0, w/ outdated Idx: 0, w/o cached Idx: 0.
  469. Done.
  470. # Change key file passphrase
  471. $ borg change-passphrase -v /path/to/repo
  472. Enter passphrase for key /root/.config/borg/keys/mnt_backup:
  473. Enter new passphrase:
  474. Enter same passphrase again:
  475. Remember your passphrase. Your data will be inaccessible without it.
  476. Key updated
  477. Fully automated using environment variables:
  478. ::
  479. $ BORG_NEW_PASSPHRASE=old borg init repo
  480. # now "old" is the current passphrase.
  481. $ BORG_PASSPHRASE=old BORG_NEW_PASSPHRASE=new borg change-passphrase repo
  482. # now "new" is the current passphrase.
  483. .. include:: usage/serve.rst.inc
  484. Examples
  485. ~~~~~~~~
  486. borg serve has special support for ssh forced commands (see ``authorized_keys``
  487. example below): it will detect that you use such a forced command and extract
  488. the value of the ``--restrict-to-path`` option(s).
  489. It will then parse the original command that came from the client, makes sure
  490. that it is also ``borg serve`` and enforce path restriction(s) as given by the
  491. forced command. That way, other options given by the client (like ``--info`` or
  492. ``--umask``) are preserved (and are not fixed by the forced command).
  493. ::
  494. # Allow an SSH keypair to only run borg, and only have access to /path/to/repo.
  495. # Use key options to disable unneeded and potentially dangerous SSH functionality.
  496. # This will help to secure an automated remote backup system.
  497. $ cat ~/.ssh/authorized_keys
  498. command="borg serve --restrict-to-path /path/to/repo",no-pty,no-agent-forwarding,no-port-forwarding,no-X11-forwarding,no-user-rc ssh-rsa AAAAB3[...]
  499. .. include:: usage/upgrade.rst.inc
  500. Examples
  501. ~~~~~~~~
  502. ::
  503. # Upgrade the borg repository to the most recent version.
  504. $ borg upgrade -v /path/to/repo
  505. making a hardlink copy in /path/to/repo.upgrade-2016-02-15-20:51:55
  506. opening attic repository with borg and converting
  507. no key file found for repository
  508. converting repo index /path/to/repo/index.0
  509. converting 1 segments...
  510. converting borg 0.xx to borg current
  511. no key file found for repository
  512. .. include:: usage/recreate.rst.inc
  513. Examples
  514. ~~~~~~~~
  515. ::
  516. # Make old (Attic / Borg 0.xx) archives deduplicate with Borg 1.x archives
  517. # Archives created with Borg 1.1+ and the default chunker params are skipped (archive ID stays the same)
  518. $ borg recreate /mnt/backup --chunker-params default --progress
  519. # Create a backup with little but fast compression
  520. $ borg create /mnt/backup::archive /some/files --compression lz4
  521. # Then compress it - this might take longer, but the backup has already completed, so no inconsistencies
  522. # from a long-running backup job.
  523. $ borg recreate /mnt/backup::archive --compression zlib,9
  524. # Remove unwanted files from all archives in a repository
  525. $ borg recreate /mnt/backup -e /home/icke/Pictures/drunk_photos
  526. # Change archive comment
  527. $ borg create --comment "This is a comment" /mnt/backup::archivename ~
  528. $ borg info /mnt/backup::archivename
  529. Name: archivename
  530. Fingerprint: ...
  531. Comment: This is a comment
  532. ...
  533. $ borg recreate --comment "This is a better comment" /mnt/backup::archivename
  534. $ borg info /mnt/backup::archivename
  535. Name: archivename
  536. Fingerprint: ...
  537. Comment: This is a better comment
  538. ...
  539. .. include:: usage/with-lock.rst.inc
  540. .. include:: usage/break-lock.rst.inc
  541. Miscellaneous Help
  542. ------------------
  543. .. include:: usage/help.rst.inc
  544. Debug Commands
  545. --------------
  546. There is a ``borg debug`` command that has some subcommands which are all
  547. **not intended for normal use** and **potentially very dangerous** if used incorrectly.
  548. For example, ``borg debug put-obj`` and ``borg debug delete-obj`` will only do
  549. what their name suggests: put objects into repo / delete objects from repo.
  550. Please note:
  551. - they will not update the chunks cache (chunks index) about the object
  552. - they will not update the manifest (so no automatic chunks index resync is triggered)
  553. - they will not check whether the object is in use (e.g. before delete-obj)
  554. - they will not update any metadata which may point to the object
  555. They exist to improve debugging capabilities without direct system access, e.g.
  556. in case you ever run into some severe malfunction. Use them only if you know
  557. what you are doing or if a trusted |project_name| developer tells you what to do.
  558. Additional Notes
  559. ----------------
  560. Here are misc. notes about topics that are maybe not covered in enough detail in the usage section.
  561. Item flags
  562. ~~~~~~~~~~
  563. ``borg create --list`` outputs a list of all files, directories and other
  564. file system items it considered (no matter whether they had content changes
  565. or not). For each item, it prefixes a single-letter flag that indicates type
  566. and/or status of the item.
  567. If you are interested only in a subset of that output, you can give e.g.
  568. ``--filter=AME`` and it will only show regular files with A, M or E status (see
  569. below).
  570. A uppercase character represents the status of a regular file relative to the
  571. "files" cache (not relative to the repo -- this is an issue if the files cache
  572. is not used). Metadata is stored in any case and for 'A' and 'M' also new data
  573. chunks are stored. For 'U' all data chunks refer to already existing chunks.
  574. - 'A' = regular file, added (see also :ref:`a_status_oddity` in the FAQ)
  575. - 'M' = regular file, modified
  576. - 'U' = regular file, unchanged
  577. - 'E' = regular file, an error happened while accessing/reading *this* file
  578. A lowercase character means a file type other than a regular file,
  579. borg usually just stores their metadata:
  580. - 'd' = directory
  581. - 'b' = block device
  582. - 'c' = char device
  583. - 'h' = regular file, hardlink (to already seen inodes)
  584. - 's' = symlink
  585. - 'f' = fifo
  586. Other flags used include:
  587. - 'i' = backup data was read from standard input (stdin)
  588. - '-' = dry run, item was *not* backed up
  589. - 'x' = excluded, item was *not* backed up
  590. - '?' = missing status code (if you see this, please file a bug report!)
  591. --chunker-params
  592. ~~~~~~~~~~~~~~~~
  593. The chunker params influence how input files are cut into pieces (chunks)
  594. which are then considered for deduplication. They also have a big impact on
  595. resource usage (RAM and disk space) as the amount of resources needed is
  596. (also) determined by the total amount of chunks in the repository (see
  597. `Indexes / Caches memory usage` for details).
  598. ``--chunker-params=10,23,16,4095`` results in a fine-grained deduplication
  599. and creates a big amount of chunks and thus uses a lot of resources to manage
  600. them. This is good for relatively small data volumes and if the machine has a
  601. good amount of free RAM and disk space.
  602. ``--chunker-params=19,23,21,4095`` (default) results in a coarse-grained
  603. deduplication and creates a much smaller amount of chunks and thus uses less
  604. resources. This is good for relatively big data volumes and if the machine has
  605. a relatively low amount of free RAM and disk space.
  606. If you already have made some archives in a repository and you then change
  607. chunker params, this of course impacts deduplication as the chunks will be
  608. cut differently.
  609. In the worst case (all files are big and were touched in between backups), this
  610. will store all content into the repository again.
  611. Usually, it is not that bad though:
  612. - usually most files are not touched, so it will just re-use the old chunks
  613. it already has in the repo
  614. - files smaller than the (both old and new) minimum chunksize result in only
  615. one chunk anyway, so the resulting chunks are same and deduplication will apply
  616. If you switch chunker params to save resources for an existing repo that
  617. already has some backup archives, you will see an increasing effect over time,
  618. when more and more files have been touched and stored again using the bigger
  619. chunksize **and** all references to the smaller older chunks have been removed
  620. (by deleting / pruning archives).
  621. If you want to see an immediate big effect on resource usage, you better start
  622. a new repository when changing chunker params.
  623. For more details, see :ref:`chunker_details`.
  624. --read-special
  625. ~~~~~~~~~~~~~~
  626. The --read-special option is special - you do not want to use it for normal
  627. full-filesystem backups, but rather after carefully picking some targets for it.
  628. The option ``--read-special`` triggers special treatment for block and char
  629. device files as well as FIFOs. Instead of storing them as such a device (or
  630. FIFO), they will get opened, their content will be read and in the backup
  631. archive they will show up like a regular file.
  632. Symlinks will also get special treatment if (and only if) they point to such
  633. a special file: instead of storing them as a symlink, the target special file
  634. will get processed as described above.
  635. One intended use case of this is backing up the contents of one or multiple
  636. block devices, like e.g. LVM snapshots or inactive LVs or disk partitions.
  637. You need to be careful about what you include when using ``--read-special``,
  638. e.g. if you include ``/dev/zero``, your backup will never terminate.
  639. Restoring such files' content is currently only supported one at a time via
  640. ``--stdout`` option (and you have to redirect stdout to where ever it shall go,
  641. maybe directly into an existing device file of your choice or indirectly via
  642. ``dd``).
  643. To some extent, mounting a backup archive with the backups of special files
  644. via ``borg mount`` and then loop-mounting the image files from inside the mount
  645. point will work. If you plan to access a lot of data in there, it likely will
  646. scale and perform better if you do not work via the FUSE mount.
  647. Example
  648. +++++++
  649. Imagine you have made some snapshots of logical volumes (LVs) you want to backup.
  650. .. note::
  651. For some scenarios, this is a good method to get "crash-like" consistency
  652. (I call it crash-like because it is the same as you would get if you just
  653. hit the reset button or your machine would abrubtly and completely crash).
  654. This is better than no consistency at all and a good method for some use
  655. cases, but likely not good enough if you have databases running.
  656. Then you create a backup archive of all these snapshots. The backup process will
  657. see a "frozen" state of the logical volumes, while the processes working in the
  658. original volumes continue changing the data stored there.
  659. You also add the output of ``lvdisplay`` to your backup, so you can see the LV
  660. sizes in case you ever need to recreate and restore them.
  661. After the backup has completed, you remove the snapshots again. ::
  662. $ # create snapshots here
  663. $ lvdisplay > lvdisplay.txt
  664. $ borg create --read-special /path/to/repo::arch lvdisplay.txt /dev/vg0/*-snapshot
  665. $ # remove snapshots here
  666. Now, let's see how to restore some LVs from such a backup. ::
  667. $ borg extract /path/to/repo::arch lvdisplay.txt
  668. $ # create empty LVs with correct sizes here (look into lvdisplay.txt).
  669. $ # we assume that you created an empty root and home LV and overwrite it now:
  670. $ borg extract --stdout /path/to/repo::arch dev/vg0/root-snapshot > /dev/vg0/root
  671. $ borg extract --stdout /path/to/repo::arch dev/vg0/home-snapshot > /dev/vg0/home
  672. .. _append_only_mode:
  673. Append-only mode
  674. ~~~~~~~~~~~~~~~~
  675. A repository can be made "append-only", which means that Borg will never overwrite or
  676. delete committed data (append-only refers to the segment files, but borg will also
  677. reject to delete the repository completely). This is useful for scenarios where a
  678. backup client machine backups remotely to a backup server using ``borg serve``, since
  679. a hacked client machine cannot delete backups on the server permanently.
  680. To activate append-only mode, edit the repository ``config`` file and add a line
  681. ``append_only=1`` to the ``[repository]`` section (or edit the line if it exists).
  682. In append-only mode Borg will create a transaction log in the ``transactions`` file,
  683. where each line is a transaction and a UTC timestamp.
  684. In addition, ``borg serve`` can act as if a repository is in append-only mode with
  685. its option ``--append-only``. This can be very useful for fine-tuning access control
  686. in ``.ssh/authorized_keys`` ::
  687. command="borg serve --append-only ..." ssh-rsa <key used for not-always-trustable backup clients>
  688. command="borg serve ..." ssh-rsa <key used for backup management>
  689. Example
  690. +++++++
  691. Suppose an attacker remotely deleted all backups, but your repository was in append-only
  692. mode. A transaction log in this situation might look like this: ::
  693. transaction 1, UTC time 2016-03-31T15:53:27.383532
  694. transaction 5, UTC time 2016-03-31T15:53:52.588922
  695. transaction 11, UTC time 2016-03-31T15:54:23.887256
  696. transaction 12, UTC time 2016-03-31T15:55:54.022540
  697. transaction 13, UTC time 2016-03-31T15:55:55.472564
  698. From your security logs you conclude the attacker gained access at 15:54:00 and all
  699. the backups where deleted or replaced by compromised backups. From the log you know
  700. that transactions 11 and later are compromised. Note that the transaction ID is the
  701. name of the *last* file in the transaction. For example, transaction 11 spans files 6
  702. to 11.
  703. In a real attack you'll likely want to keep the compromised repository
  704. intact to analyze what the attacker tried to achieve. It's also a good idea to make this
  705. copy just in case something goes wrong during the recovery. Since recovery is done by
  706. deleting some files, a hard link copy (``cp -al``) is sufficient.
  707. The first step to reset the repository to transaction 5, the last uncompromised transaction,
  708. is to remove the ``hints.N`` and ``index.N`` files in the repository (these two files are
  709. always expendable). In this example N is 13.
  710. Then remove or move all segment files from the segment directories in ``data/`` starting
  711. with file 6::
  712. rm data/**/{6..13}
  713. That's all to it.
  714. Drawbacks
  715. +++++++++
  716. As data is only appended, and nothing removed, commands like ``prune`` or ``delete``
  717. won't free disk space, they merely tag data as deleted in a new transaction.
  718. Be aware that as soon as you write to the repo in non-append-only mode (e.g. prune,
  719. delete or create archives from an admin machine), it will remove the deleted objects
  720. permanently (including the ones that were already marked as deleted, but not removed,
  721. in append-only mode).
  722. Note that you can go back-and-forth between normal and append-only operation by editing
  723. the configuration file, it's not a "one way trip".
  724. Further considerations
  725. ++++++++++++++++++++++
  726. Append-only mode is not respected by tools other than Borg. ``rm`` still works on the
  727. repository. Make sure that backup client machines only get to access the repository via
  728. ``borg serve``.
  729. Ensure that no remote access is possible if the repository is temporarily set to normal mode
  730. for e.g. regular pruning.
  731. Further protections can be implemented, but are outside of Borg's scope. For example,
  732. file system snapshots or wrapping ``borg serve`` to set special permissions or ACLs on
  733. new data files.