quickstart.rst 8.9 KB

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