create.rst 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. .. include:: create.rst.inc
  2. Examples
  3. ~~~~~~~~
  4. ::
  5. # Backup ~/Documents into an archive named "my-documents"
  6. $ borg create /path/to/repo::my-documents ~/Documents
  7. # same, but list all files as we process them
  8. $ borg create --list /path/to/repo::my-documents ~/Documents
  9. # Backup /mnt/disk/docs, but strip path prefix using the slashdot hack
  10. $ borg create /path/to/repo::docs /mnt/disk/./docs
  11. # Backup ~/Documents and ~/src but exclude pyc files
  12. $ borg create /path/to/repo::my-files \
  13. ~/Documents \
  14. ~/src \
  15. --exclude '*.pyc'
  16. # Backup home directories excluding image thumbnails (i.e. only
  17. # /home/<one directory>/.thumbnails is excluded, not /home/*/*/.thumbnails etc.)
  18. $ borg create /path/to/repo::my-files /home \
  19. --exclude 'sh:home/*/.thumbnails'
  20. # Backup the root filesystem into an archive named "root-YYYY-MM-DD"
  21. # use zlib compression (good, but slow) - default is lz4 (fast, low compression ratio)
  22. $ borg create -C zlib,6 --one-file-system /path/to/repo::root-{now:%Y-%m-%d} /
  23. # Backup onto a remote host ("push" style) via ssh to port 2222,
  24. # logging in as user "borg" and storing into /path/to/repo
  25. $ borg create ssh://borg@backup.example.org:2222/path/to/repo::{fqdn}-root-{now} /
  26. # Backup a remote host locally ("pull" style) using sshfs
  27. $ mkdir sshfs-mount
  28. $ sshfs root@example.com:/ sshfs-mount
  29. $ cd sshfs-mount
  30. $ borg create /path/to/repo::example.com-root-{now:%Y-%m-%d} .
  31. $ cd ..
  32. $ fusermount -u sshfs-mount
  33. # Make a big effort in fine granular deduplication (big chunk management
  34. # overhead, needs a lot of RAM and disk space, see formula in internals
  35. # docs - same parameters as borg < 1.0 or attic):
  36. $ borg create --chunker-params buzhash,10,23,16,4095 /path/to/repo::small /smallstuff
  37. # Backup a raw device (must not be active/in use/mounted at that time)
  38. $ borg create --read-special --chunker-params fixed,4194304 /path/to/repo::my-sdx /dev/sdX
  39. # Backup a sparse disk image (must not be active/in use/mounted at that time)
  40. $ borg create --sparse --chunker-params fixed,4194304 /path/to/repo::my-disk my-disk.raw
  41. # No compression (none)
  42. $ borg create --compression none /path/to/repo::arch ~
  43. # Super fast, low compression (lz4, default)
  44. $ borg create /path/to/repo::arch ~
  45. # Less fast, higher compression (zlib, N = 0..9)
  46. $ borg create --compression zlib,N /path/to/repo::arch ~
  47. # Even slower, even higher compression (lzma, N = 0..9)
  48. $ borg create --compression lzma,N /path/to/repo::arch ~
  49. # Only compress compressible data with lzma,N (N = 0..9)
  50. $ borg create --compression auto,lzma,N /path/to/repo::arch ~
  51. # Use short hostname, user name and current time in archive name
  52. $ borg create /path/to/repo::{hostname}-{user}-{now} ~
  53. # Similar, use the same datetime format that is default as of borg 1.1
  54. $ borg create /path/to/repo::{hostname}-{user}-{now:%Y-%m-%dT%H:%M:%S} ~
  55. # As above, but add nanoseconds
  56. $ borg create /path/to/repo::{hostname}-{user}-{now:%Y-%m-%dT%H:%M:%S.%f} ~
  57. # Backing up relative paths by moving into the correct directory first
  58. $ cd /home/user/Documents
  59. # The root directory of the archive will be "projectA"
  60. $ borg create /path/to/repo::daily-projectA-{now:%Y-%m-%d} projectA
  61. # Use external command to determine files to archive
  62. # Use --paths-from-stdin with find to only backup files less than 1MB in size
  63. $ find ~ -size -1000k | borg create --paths-from-stdin /path/to/repo::small-files-only
  64. # Use --paths-from-command with find to only backup files from a given user
  65. $ borg create --paths-from-command /path/to/repo::joes-files -- find /srv/samba/shared -user joe
  66. # Use --paths-from-stdin with --paths-delimiter (for example, for filenames with newlines in them)
  67. $ find ~ -size -1000k -print0 | borg create \
  68. --paths-from-stdin \
  69. --paths-delimiter "\0" \
  70. /path/to/repo::smallfiles-handle-newline