quickstart.rst 8.3 KB

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