quickstart.rst 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. .. include:: global.rst.inc
  2. .. _quickstart:
  3. Quick Start
  4. ===========
  5. This chapter will get you started with |project_name|. The first section
  6. presents a simple step by step example that uses |project_name| to backup data.
  7. The next section continues by showing how backups can be automated.
  8. Important note about free space
  9. -------------------------------
  10. Before you start creating backups, please make sure that there is *always*
  11. a good amount of free space on the filesystem that has your backup repository
  12. (and also on ~/.cache). A few GB should suffice for most hard-drive sized
  13. repositories. See also :ref:`cache-memory-usage`.
  14. If |project_name| runs out of disk space, it tries to free as much space as it
  15. can while aborting the current operation safely, which allows to free more space
  16. by deleting/pruning archives. This mechanism is not bullet-proof though.
  17. If you *really* run out of disk space, it can be hard or impossible to free space,
  18. because |project_name| needs free space to operate - even to delete backup
  19. archives. There is a ``--save-space`` option for some commands, but even with
  20. that |project_name| will need free space to operate.
  21. You can use some monitoring process or just include the free space information
  22. in your backup log files (you check them regularly anyway, right?).
  23. Also helpful:
  24. - create a big file as a "space reserve", that you can delete to free space
  25. - if you use LVM: use a LV + a filesystem that you can resize later and have
  26. some unallocated PEs you can add to the LV.
  27. - consider using quotas
  28. - use `prune` regularly
  29. A step by step example
  30. ----------------------
  31. 1. Before a backup can be made a repository has to be initialized::
  32. $ borg init /path/to/repo
  33. 2. Backup the ``~/src`` and ``~/Documents`` directories into an archive called
  34. *Monday*::
  35. $ borg create /path/to/repo::Monday ~/src ~/Documents
  36. 3. The next day create a new archive called *Tuesday*::
  37. $ borg create --stats /path/to/repo::Tuesday ~/src ~/Documents
  38. This backup will be a lot quicker and a lot smaller since only new never
  39. before seen data is stored. The ``--stats`` option causes |project_name| to
  40. output statistics about the newly created archive such as the amount of unique
  41. data (not shared with other archives)::
  42. ------------------------------------------------------------------------------
  43. Archive name: Tuesday
  44. Archive fingerprint: bd31004d58f51ea06ff735d2e5ac49376901b21d58035f8fb05dbf866566e3c2
  45. Time (start): Tue, 2016-02-16 18:15:11
  46. Time (end): Tue, 2016-02-16 18:15:11
  47. Duration: 0.19 seconds
  48. Number of files: 127
  49. ------------------------------------------------------------------------------
  50. Original size Compressed size Deduplicated size
  51. This archive: 4.16 MB 4.17 MB 26.78 kB
  52. All archives: 8.33 MB 8.34 MB 4.19 MB
  53. Unique chunks Total chunks
  54. Chunk index: 132 261
  55. ------------------------------------------------------------------------------
  56. 4. List all archives in the repository::
  57. $ borg list /path/to/repo
  58. Monday Mon, 2016-02-15 19:14:44
  59. Tuesday Tue, 2016-02-16 19:15:11
  60. 5. List the contents of the *Monday* archive::
  61. $ borg list /path/to/repo::Monday
  62. drwxr-xr-x user group 0 Mon, 2016-02-15 18:22:30 home/user/Documents
  63. -rw-r--r-- user group 7961 Mon, 2016-02-15 18:22:30 home/user/Documents/Important.doc
  64. ...
  65. 6. Restore the *Monday* archive::
  66. $ borg extract /path/to/repo::Monday
  67. 7. Recover disk space by manually deleting the *Monday* archive::
  68. $ borg delete /path/to/repo::Monday
  69. .. Note::
  70. Borg is quiet by default (it works on WARNING log level).
  71. You can use options like ``--progress`` or ``--list`` to get specific
  72. reports during command execution. You can also add the ``-v`` (or
  73. ``--verbose`` or ``--info``) option to adjust the log level to INFO to
  74. get other informational messages.
  75. Automating backups
  76. ------------------
  77. The following example script backs up ``/home`` and ``/var/www`` to a remote
  78. server. The script also uses the :ref:`borg_prune` subcommand to maintain a
  79. certain number of old archives:
  80. ::
  81. #!/bin/sh
  82. # setting this, so the repo does not need to be given on the commandline:
  83. export BORG_REPO=username@remoteserver.com:backup
  84. # setting this, so you won't be asked for your passphrase - make sure the
  85. # script has appropriate owner/group and mode, e.g. root.root 600:
  86. export BORG_PASSPHRASE=mysecret
  87. # Backup most important stuff:
  88. borg create --stats -C lz4 ::'{hostname}-{now:%Y-%m-%d}' \
  89. /etc \
  90. /home \
  91. /var \
  92. --exclude '/home/*/.cache' \
  93. --exclude '*.pyc'
  94. # Use the `prune` subcommand to maintain 7 daily, 4 weekly and 6 monthly
  95. # archives of THIS machine. The '{hostname}-' prefix is very important to
  96. # limit prune's operation to this machine's archives and not apply to
  97. # other machine's archives also.
  98. borg prune -v --prefix '{hostname}-' \
  99. --keep-daily=7 --keep-weekly=4 --keep-monthly=6
  100. .. backup_compression:
  101. Backup compression
  102. ------------------
  103. Default is no compression, but we support different methods with high speed
  104. or high compression:
  105. If you have a fast repo storage and you want some compression: ::
  106. $ borg create --compression lz4 /path/to/repo::arch ~
  107. If you have a less fast repo storage and you want a bit more compression (N=0..9,
  108. 0 means no compression, 9 means high compression): ::
  109. $ borg create --compression zlib,N /path/to/repo::arch ~
  110. If you have a very slow repo storage and you want high compression (N=0..9, 0 means
  111. low compression, 9 means high compression): ::
  112. $ borg create --compression lzma,N /path/to/repo::arch ~
  113. You'll need to experiment a bit to find the best compression for your use case.
  114. Keep an eye on CPU load and throughput.
  115. .. _encrypted_repos:
  116. Repository encryption
  117. ---------------------
  118. Repository encryption can be enabled or disabled at repository creation time
  119. (the default is enabled, with `repokey` method)::
  120. $ borg init --encryption=none|repokey|keyfile PATH
  121. When repository encryption is enabled all data is encrypted using 256-bit AES_
  122. encryption and the integrity and authenticity is verified using `HMAC-SHA256`_.
  123. All data is encrypted on the client before being written to the repository. This
  124. means that an attacker who manages to compromise the host containing an
  125. encrypted archive will not be able to access any of the data, even while the backup
  126. is being made.
  127. |project_name| supports different methods to store the AES and HMAC keys.
  128. ``repokey`` mode
  129. The key is stored inside the repository (in its "config" file).
  130. Use this mode if you trust in your good passphrase giving you enough
  131. protection. The repository server never sees the plaintext key.
  132. ``keyfile`` mode
  133. The key is stored on your local disk (in ``~/.config/borg/keys/``).
  134. Use this mode if you want "passphrase and having-the-key" security.
  135. In both modes, the key is stored in encrypted form and can be only decrypted
  136. by providing the correct passphrase.
  137. For automated backups the passphrase can be specified using the
  138. `BORG_PASSPHRASE` environment variable.
  139. .. note:: Be careful about how you set that environment, see
  140. :ref:`this note about password environments <password_env>`
  141. for more information.
  142. .. warning:: The repository data is totally inaccessible without the key
  143. and the key passphrase.
  144. Make a backup copy of the key file (``keyfile`` mode) or repo config
  145. file (``repokey`` mode) and keep it at a safe place, so you still have
  146. the key in case it gets corrupted or lost. Also keep your passphrase
  147. at a safe place.
  148. The backup that is encrypted with that key/passphrase won't help you
  149. with that, of course.
  150. .. _remote_repos:
  151. Remote repositories
  152. -------------------
  153. |project_name| can initialize and access repositories on remote hosts if the
  154. host is accessible using SSH. This is fastest and easiest when |project_name|
  155. is installed on the remote host, in which case the following syntax is used::
  156. $ borg init user@hostname:/path/to/repo
  157. or::
  158. $ borg init ssh://user@hostname:port//path/to/repo
  159. Remote operations over SSH can be automated with SSH keys. You can restrict the
  160. use of the SSH keypair by prepending a forced command to the SSH public key in
  161. the remote server's `authorized_keys` file. This example will start |project_name|
  162. in server mode and limit it to a specific filesystem path::
  163. 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[...]
  164. If it is not possible to install |project_name| on the remote host,
  165. it is still possible to use the remote host to store a repository by
  166. mounting the remote filesystem, for example, using sshfs::
  167. $ sshfs user@hostname:/path/to /path/to
  168. $ borg init /path/to/repo
  169. $ fusermount -u /path/to