quickstart.rst 8.8 KB

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