2
0

quickstart.rst 8.6 KB

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