quickstart.rst 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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 -v --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. Add the ``-v`` (or ``--verbose`` or ``--info``) option to adjust the log
  72. level to INFO and also use options like ``--progress`` or ``--list`` to
  73. get progress reporting during command execution.
  74. Automating backups
  75. ------------------
  76. The following example script backs up ``/home`` and ``/var/www`` to a remote
  77. server. The script also uses the :ref:`borg_prune` subcommand to maintain a
  78. certain number of old archives::
  79. #!/bin/sh
  80. REPOSITORY=username@remoteserver.com:backup
  81. # Backup all of /home and /var/www except a few
  82. # excluded directories
  83. borg create -v --stats \
  84. $REPOSITORY::'{hostname}-{now:%Y-%m-%d}' \
  85. /home \
  86. /var/www \
  87. --exclude '/home/*/.cache' \
  88. --exclude /home/Ben/Music/Justin\ Bieber \
  89. --exclude '*.pyc'
  90. # Use the `prune` subcommand to maintain 7 daily, 4 weekly and 6 monthly
  91. # archives of THIS machine. The '{hostname}-' prefix is very important to
  92. # limit prune's operation to this machine's archives and not apply to
  93. # other machine's archives also.
  94. borg prune -v $REPOSITORY --prefix '{hostname}-' \
  95. --keep-daily=7 --keep-weekly=4 --keep-monthly=6
  96. .. backup_compression:
  97. Backup compression
  98. ------------------
  99. Default is no compression, but we support different methods with high speed
  100. or high compression:
  101. If you have a fast repo storage and you want some compression: ::
  102. $ borg create --compression lz4 /path/to/repo::arch ~
  103. If you have a less fast repo storage and you want a bit more compression (N=0..9,
  104. 0 means no compression, 9 means high compression): ::
  105. $ borg create --compression zlib,N /path/to/repo::arch ~
  106. If you have a very slow repo storage and you want high compression (N=0..9, 0 means
  107. low compression, 9 means high compression): ::
  108. $ borg create --compression lzma,N /path/to/repo::arch ~
  109. You'll need to experiment a bit to find the best compression for your use case.
  110. Keep an eye on CPU load and throughput.
  111. .. _encrypted_repos:
  112. Repository encryption
  113. ---------------------
  114. Repository encryption can be enabled or disabled at repository creation time
  115. (the default is enabled, with `repokey` method)::
  116. $ borg init --encryption=none|repokey|keyfile PATH
  117. When repository encryption is enabled all data is encrypted using 256-bit AES_
  118. encryption and the integrity and authenticity is verified using `HMAC-SHA256`_.
  119. All data is encrypted on the client before being written to the repository. This
  120. means that an attacker who manages to compromise the host containing an
  121. encrypted archive will not be able to access any of the data, even while the backup
  122. is being made.
  123. |project_name| supports different methods to store the AES and HMAC keys.
  124. ``repokey`` mode
  125. The key is stored inside the repository (in its "config" file).
  126. Use this mode if you trust in your good passphrase giving you enough
  127. protection. The repository server never sees the plaintext key.
  128. ``keyfile`` mode
  129. The key is stored on your local disk (in ``~/.config/borg/keys/``).
  130. Use this mode if you want "passphrase and having-the-key" security.
  131. In both modes, the key is stored in encrypted form and can be only decrypted
  132. by providing the correct passphrase.
  133. For automated backups the passphrase can be specified using the
  134. `BORG_PASSPHRASE` environment variable.
  135. .. note:: Be careful about how you set that environment, see
  136. :ref:`this note about password environments <password_env>`
  137. for more information.
  138. .. warning:: The repository data is totally inaccessible without the key
  139. and the key passphrase.
  140. Make a backup copy of the key file (``keyfile`` mode) or repo config
  141. file (``repokey`` mode) and keep it at a safe place, so you still have
  142. the key in case it gets corrupted or lost. Also keep your passphrase
  143. at a safe place.
  144. The backup that is encrypted with that key/passphrase won't help you
  145. with that, of course.
  146. .. _remote_repos:
  147. Remote repositories
  148. -------------------
  149. |project_name| can initialize and access repositories on remote hosts if the
  150. host is accessible using SSH. This is fastest and easiest when |project_name|
  151. is installed on the remote host, in which case the following syntax is used::
  152. $ borg init user@hostname:/path/to/repo
  153. or::
  154. $ borg init ssh://user@hostname:port//path/to/repo
  155. Remote operations over SSH can be automated with SSH keys. You can restrict the
  156. use of the SSH keypair by prepending a forced command to the SSH public key in
  157. the remote server's `authorized_keys` file. This example will start |project_name|
  158. in server mode and limit it to a specific filesystem path::
  159. 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[...]
  160. If it is not possible to install |project_name| on the remote host,
  161. it is still possible to use the remote host to store a repository by
  162. mounting the remote filesystem, for example, using sshfs::
  163. $ sshfs user@hostname:/path/to /path/to
  164. $ borg init /path/to/repo
  165. $ fusermount -u /path/to