usage.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. .. include:: global.rst.inc
  2. .. _detailed_usage:
  3. Usage
  4. =====
  5. |project_name| consists of a number of commands. Each command accepts
  6. a number of arguments and options. The following sections will describe each
  7. command in detail.
  8. Quiet by default
  9. ----------------
  10. Like most UNIX commands |project_name| is quiet by default but the ``-v`` or
  11. ``--verbose`` option can be used to get the program to output more status
  12. messages as it is processing.
  13. Return codes
  14. ------------
  15. |project_name| can exit with the following return codes (rc):
  16. ::
  17. 0 no error, normal termination
  18. 1 some error occurred (this can be a complete or a partial failure)
  19. 128+N killed by signal N (e.g. 137 == kill -9)
  20. Note: we are aware that more distinct return codes might be useful, but it is
  21. not clear yet which return codes should be used for which precise conditions.
  22. See issue #61 for a discussion about that. Depending on the outcome of the
  23. discussion there, return codes may change in future (the only thing rather sure
  24. is that 0 will always mean some sort of success and "not 0" will always mean
  25. some sort of warning / error / failure - but the definition of success might
  26. change).
  27. Environment Variables
  28. ---------------------
  29. |project_name| uses some environment variables for automation:
  30. Specifying a passphrase:
  31. BORG_PASSPHRASE
  32. When set, use the value to answer the passphrase question for encrypted repositories.
  33. Some "yes" sayers (if set, they automatically confirm that you really want to do X even if there is that warning):
  34. BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK
  35. For "Warning: Attempting to access a previously unknown unencrypted repository"
  36. BORG_RELOCATED_REPO_ACCESS_IS_OK
  37. For "Warning: The repository at location ... was previously located at ..."
  38. BORG_CHECK_I_KNOW_WHAT_I_AM_DOING
  39. For "Warning: 'check --repair' is an experimental feature that might result in data loss."
  40. Directories:
  41. BORG_KEYS_DIR
  42. Default to '~/.borg/keys'. This directory contains keys for encrypted repositories.
  43. BORG_CACHE_DIR
  44. Default to '~/.cache/borg'. This directory contains the local cache and might need a lot
  45. of space for dealing with big repositories).
  46. Building:
  47. BORG_OPENSSL_PREFIX
  48. Adds given OpenSSL header file directory to the default locations (setup.py).
  49. General:
  50. TMPDIR
  51. where temporary files are stored (might need a lot of temporary space for some operations)
  52. Please note:
  53. - be very careful when using the "yes" sayers, the warnings with prompt exist for your / your data's security/safety
  54. - also be very careful when putting your passphrase into a script, make sure it has appropriate file permissions
  55. (e.g. mode 600, root:root).
  56. Resource Usage
  57. --------------
  58. |project_name| might use a lot of resources depending on the size of the data set it is dealing with.
  59. CPU:
  60. It won't go beyond 100% of 1 core as the code is currently single-threaded.
  61. Especially higher zlib and lzma compression levels use significant amounts
  62. of CPU cycles.
  63. Memory (RAM):
  64. The chunks index and the files index are read into memory for performance
  65. reasons.
  66. Compression, esp. lzma compression with high levels might need substantial
  67. amounts of memory.
  68. Temporary files:
  69. Reading data and metadata from a FUSE mounted repository will consume about
  70. the same space as the deduplicated chunks used to represent them in the
  71. repository.
  72. Cache files:
  73. Contains the chunks index and files index (plus a compressed collection of
  74. single-archive chunk indexes).
  75. Chunks index:
  76. Proportional to the amount of data chunks in your repo. Lots of small chunks
  77. in your repo imply a big chunks index. You may need to tweak the chunker
  78. params (see create options) if you have a lot of data and you want to keep
  79. the chunks index at some reasonable size.
  80. Files index:
  81. Proportional to the amount of files in your last backup. Can be switched
  82. off (see create options), but next backup will be much slower if you do.
  83. Network:
  84. If your repository is remote, all deduplicated (and optionally compressed/
  85. encrypted) data of course has to go over the connection (ssh: repo url).
  86. If you use a locally mounted network filesystem, additionally some copy
  87. operations used for transaction support also go over the connection. If
  88. you backup multiple sources to one target repository, additional traffic
  89. happens for cache resynchronization.
  90. In case you are interested in more details, please read the internals documentation.
  91. .. include:: usage/init.rst.inc
  92. Examples
  93. ~~~~~~~~
  94. ::
  95. # Local repository
  96. $ borg init /mnt/backup
  97. # Remote repository (accesses a remote borg via ssh)
  98. $ borg init user@hostname:backup
  99. # Encrypted remote repository, store the key in the repo
  100. $ borg init --encryption=repokey user@hostname:backup
  101. # Encrypted remote repository, store the key your home dir
  102. $ borg init --encryption=keyfile user@hostname:backup
  103. Important notes about encryption:
  104. Use encryption! Repository encryption protects you e.g. against the case that
  105. an attacker has access to your backup repository.
  106. But be careful with the key / the passphrase:
  107. ``--encryption=passphrase`` is DEPRECATED and will be removed in next major release.
  108. This mode has very fundamental, unfixable problems (like you can never change
  109. your passphrase or the pbkdf2 iteration count for an existing repository, because
  110. the encryption / decryption key is directly derived from the passphrase).
  111. If you want "passphrase-only" security, just use the ``repokey`` mode. The key will
  112. be stored inside the repository (in its "config" file). In above mentioned
  113. attack scenario, the attacker will have the key (but not the passphrase).
  114. If you want "passphrase and having-the-key" security, use the ``keyfile`` mode.
  115. The key will be stored in your home directory (in ``.borg/keys``). In the attack
  116. scenario, the attacker who has just access to your repo won't have the key (and
  117. also not the passphrase).
  118. Make a backup copy of the key file (``keyfile`` mode) or repo config file
  119. (``repokey`` mode) and keep it at a safe place, so you still have the key in
  120. case it gets corrupted or lost.
  121. The backup that is encrypted with that key won't help you with that, of course.
  122. Make sure you use a good passphrase. Not too short, not too simple. The real
  123. encryption / decryption key is encrypted with / locked by your passphrase.
  124. If an attacker gets your key, he can't unlock and use it without knowing the
  125. passphrase. In ``repokey`` and ``keyfile`` modes, you can change your passphrase
  126. for existing repos.
  127. .. include:: usage/create.rst.inc
  128. Examples
  129. ~~~~~~~~
  130. ::
  131. # Backup ~/Documents into an archive named "my-documents"
  132. $ borg create /mnt/backup::my-documents ~/Documents
  133. # Backup ~/Documents and ~/src but exclude pyc files
  134. $ borg create /mnt/backup::my-files \
  135. ~/Documents \
  136. ~/src \
  137. --exclude '*.pyc'
  138. # Backup the root filesystem into an archive named "root-YYYY-MM-DD"
  139. NAME="root-`date +%Y-%m-%d`"
  140. $ borg create /mnt/backup::$NAME / --do-not-cross-mountpoints
  141. # Backup huge files with little chunk management overhead
  142. $ borg create --chunker-params 19,23,21,4095 /mnt/backup::VMs /srv/VMs
  143. # Backup a raw device (must not be active/in use/mounted at that time)
  144. $ dd if=/dev/sda bs=10M | borg create /mnt/backup::my-sda -
  145. # No compression (default)
  146. $ borg create /mnt/backup::repo ~
  147. # Super fast, low compression
  148. $ borg create --compression lz4 /mnt/backup::repo ~
  149. # Less fast, higher compression (N = 0..9)
  150. $ borg create --compression zlib,N /mnt/backup::repo ~
  151. # Even slower, even higher compression (N = 0..9)
  152. $ borg create --compression lzma,N /mnt/backup::repo ~
  153. .. include:: usage/extract.rst.inc
  154. Examples
  155. ~~~~~~~~
  156. ::
  157. # Extract entire archive
  158. $ borg extract /mnt/backup::my-files
  159. # Extract entire archive and list files while processing
  160. $ borg extract -v /mnt/backup::my-files
  161. # Extract the "src" directory
  162. $ borg extract /mnt/backup::my-files home/USERNAME/src
  163. # Extract the "src" directory but exclude object files
  164. $ borg extract /mnt/backup::my-files home/USERNAME/src --exclude '*.o'
  165. Note: currently, extract always writes into the current working directory ("."),
  166. so make sure you ``cd`` to the right place before calling ``borg extract``.
  167. .. include:: usage/check.rst.inc
  168. .. include:: usage/delete.rst.inc
  169. .. include:: usage/list.rst.inc
  170. Examples
  171. ~~~~~~~~
  172. ::
  173. $ borg list /mnt/backup
  174. my-files Thu Aug 1 23:33:22 2013
  175. my-documents Thu Aug 1 23:35:43 2013
  176. root-2013-08-01 Thu Aug 1 23:43:55 2013
  177. root-2013-08-02 Fri Aug 2 15:18:17 2013
  178. ...
  179. $ borg list /mnt/backup::root-2013-08-02
  180. drwxr-xr-x root root 0 Jun 05 12:06 .
  181. lrwxrwxrwx root root 0 May 31 20:40 bin -> usr/bin
  182. drwxr-xr-x root root 0 Aug 01 22:08 etc
  183. drwxr-xr-x root root 0 Jul 15 22:07 etc/ImageMagick-6
  184. -rw-r--r-- root root 1383 May 22 22:25 etc/ImageMagick-6/colors.xml
  185. ...
  186. .. include:: usage/prune.rst.inc
  187. Examples
  188. ~~~~~~~~
  189. ::
  190. # Keep 7 end of day and 4 additional end of week archives:
  191. $ borg prune /mnt/backup --keep-daily=7 --keep-weekly=4
  192. # Same as above but only apply to archive names starting with "foo":
  193. $ borg prune /mnt/backup --keep-daily=7 --keep-weekly=4 --prefix=foo
  194. # Keep 7 end of day, 4 additional end of week archives,
  195. # and an end of month archive for every month:
  196. $ borg prune /mnt/backup --keep-daily=7 --keep-weekly=4 --keep-monthly=-1
  197. # Keep all backups in the last 10 days, 4 additional end of week archives,
  198. # and an end of month archive for every month:
  199. $ borg prune /mnt/backup --keep-within=10d --keep-weekly=4 --keep-monthly=-1
  200. .. include:: usage/info.rst.inc
  201. Examples
  202. ~~~~~~~~
  203. ::
  204. $ borg info /mnt/backup::root-2013-08-02
  205. Name: root-2013-08-02
  206. Fingerprint: bc3902e2c79b6d25f5d769b335c5c49331e6537f324d8d3badcb9a0917536dbb
  207. Hostname: myhostname
  208. Username: root
  209. Time: Fri Aug 2 15:18:17 2013
  210. Command line: /usr/bin/borg create --stats /mnt/backup::root-2013-08-02 / --do-not-cross-mountpoints
  211. Number of files: 147429
  212. Original size: 5344169493 (4.98 GB)
  213. Compressed size: 1748189642 (1.63 GB)
  214. Unique data: 64805454 (61.80 MB)
  215. .. include:: usage/mount.rst.inc
  216. Examples
  217. ~~~~~~~~
  218. ::
  219. $ borg mount /mnt/backup::root-2013-08-02 /tmp/mymountpoint
  220. $ ls /tmp/mymountpoint
  221. bin boot etc lib lib64 mnt opt root sbin srv usr var
  222. $ fusermount -u /tmp/mymountpoint
  223. .. include:: usage/change-passphrase.rst.inc
  224. Examples
  225. ~~~~~~~~
  226. ::
  227. # Create a key file protected repository
  228. $ borg init --encryption=keyfile /mnt/backup
  229. Initializing repository at "/mnt/backup"
  230. Enter passphrase (empty for no passphrase):
  231. Enter same passphrase again:
  232. Key file "/home/USER/.borg/keys/mnt_backup" created.
  233. Keep this file safe. Your data will be inaccessible without it.
  234. # Change key file passphrase
  235. $ borg change-passphrase /mnt/backup
  236. Enter passphrase for key file /home/USER/.borg/keys/mnt_backup:
  237. New passphrase:
  238. Enter same passphrase again:
  239. Key file "/home/USER/.borg/keys/mnt_backup" updated
  240. .. include:: usage/serve.rst.inc
  241. Examples
  242. ~~~~~~~~
  243. ::
  244. # Allow an SSH keypair to only run |project_name|, and only have access to /mnt/backup.
  245. # This will help to secure an automated remote backup system.
  246. $ cat ~/.ssh/authorized_keys
  247. command="borg serve --restrict-to-path /mnt/backup" ssh-rsa AAAAB3[...]