usage.rst 41 KB

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