create.rst 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. .. include:: create.rst.inc
  2. .. note::
  3. Archive series and performance: In Borg 2, archives that share the same NAME form an "archive series".
  4. The files cache is maintained per series. For best performance on repeated backups, reuse the same
  5. NAME every time you run ``borg create`` for the same dataset (e.g. always use ``my-documents``).
  6. Frequently changing the NAME (for example by embedding date/time like ``my-documents-2025-11-10``)
  7. prevents cache reuse and forces Borg to re-scan and re-chunk files, which can make incremental
  8. backups vastly slower. Only vary the NAME if you intentionally want to start a new series.
  9. If you must vary the archive name but still want cache reuse across names, see the advanced
  10. knobs described in :ref:`upgradenotes2` (``BORG_FILES_CACHE_SUFFIX`` and ``BORG_FILES_CACHE_TTL``),
  11. but the recommended approach is to keep a stable NAME per series.
  12. Examples
  13. ~~~~~~~~
  14. ::
  15. # Backup ~/Documents into an archive named "my-documents"
  16. $ borg create my-documents ~/Documents
  17. # same, but list all files as we process them
  18. $ borg create --list my-documents ~/Documents
  19. # Backup /mnt/disk/docs, but strip path prefix using the slashdot hack
  20. $ borg create --repo /path/to/repo docs /mnt/disk/./docs
  21. # Backup ~/Documents and ~/src but exclude pyc files
  22. $ borg create my-files \
  23. ~/Documents \
  24. ~/src \
  25. --exclude '*.pyc'
  26. # Backup home directories excluding image thumbnails (i.e. only
  27. # /home/<one directory>/.thumbnails is excluded, not /home/*/*/.thumbnails etc.)
  28. $ borg create my-files /home --exclude 'sh:home/*/.thumbnails'
  29. # Back up the root filesystem into an archive named "root-archive"
  30. # Use zlib compression (good, but slow) — default is LZ4 (fast, low compression ratio)
  31. $ borg create -C zlib,6 --one-file-system root-archive /
  32. # Backup into an archive name like FQDN-root
  33. $ borg create '{fqdn}-root' /
  34. # Back up a remote host locally ("pull" style) using SSHFS
  35. $ mkdir sshfs-mount
  36. $ sshfs root@example.com:/ sshfs-mount
  37. $ cd sshfs-mount
  38. $ borg create example.com-root .
  39. $ cd ..
  40. $ fusermount -u sshfs-mount
  41. # Make a big effort in fine-grained deduplication (big chunk management
  42. # overhead, needs a lot of RAM and disk space; see the formula in the internals docs):
  43. $ borg create --chunker-params buzhash,10,23,16,4095 small /smallstuff
  44. # Backup a raw device (must not be active/in use/mounted at that time)
  45. $ borg create --read-special --chunker-params fixed,4194304 my-sdx /dev/sdX
  46. # Backup a sparse disk image (must not be active/in use/mounted at that time)
  47. $ borg create --sparse --chunker-params fixed,4194304 my-disk my-disk.raw
  48. # No compression (none)
  49. $ borg create --compression none arch ~
  50. # Super fast, low compression (lz4, default)
  51. $ borg create arch ~
  52. # Less fast, higher compression (zlib, N = 0..9)
  53. $ borg create --compression zlib,N arch ~
  54. # Even slower, even higher compression (lzma, N = 0..9)
  55. $ borg create --compression lzma,N arch ~
  56. # Only compress compressible data with lzma,N (N = 0..9)
  57. $ borg create --compression auto,lzma,N arch ~
  58. # Use the short hostname and username as the archive name
  59. $ borg create '{hostname}-{user}' ~
  60. # Back up relative paths by moving into the correct directory first
  61. $ cd /home/user/Documents
  62. # The root directory of the archive will be "projectA"
  63. $ borg create 'daily-projectA' projectA
  64. # Use external command to determine files to archive
  65. # Use --paths-from-stdin with find to back up only files less than 1 MB in size
  66. $ find ~ -size -1000k | borg create --paths-from-stdin small-files-only
  67. # Use --paths-from-command with find to back up files from only a given user
  68. $ borg create --paths-from-command joes-files -- find /srv/samba/shared -user joe
  69. # Use --paths-from-stdin with --paths-delimiter (for example, for filenames with newlines in them)
  70. $ find ~ -size -1000k -print0 | borg create \
  71. --paths-from-stdin \
  72. --paths-delimiter "\0" \
  73. smallfiles-handle-newline