quickstart.rst 7.7 KB

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