usage.rst 39 KB

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