advanced.sh 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # For the pro users, here are some advanced features of borg, so you can impress your friends. ;)
  2. # Note: This screencast was made with borg version 1.1.0 – older or newer borg versions may behave differently.
  3. # First of all, we can use several environment variables for borg.
  4. # E.g. we do not want to type in our repo path and password again and again…
  5. export BORG_REPO='/media/backup/borgdemo'
  6. export BORG_PASSPHRASE='1234'
  7. # Problem solved, borg will use this automatically… :)
  8. # We'll use this right away…
  9. ## ADVANCED CREATION ##
  10. # We can also use some placeholders in our archive name…
  11. borg create --stats --progress --compression lz4 ::{user}-{now} Wallpaper
  12. # Notice the backup name.
  13. # And we can put completely different data, with different backup settings, in our backup. It will be deduplicated, anyway:
  14. borg create --stats --progress --compression zlib,6 --exclude ~/Downloads/big ::{user}-{now} ~/Downloads
  15. # Or let's backup a device via STDIN.
  16. sudo dd if=/dev/loop0 bs=10M | borg create --progress --stats ::specialbackup -
  17. # Let's continue with some simple things:
  18. ## USEFUL COMMANDS ##
  19. # You can show some information about an archive. You can even do it without needing to specify the archive name:
  20. borg info :: --last 1
  21. # So let's rename our last archive:
  22. borg rename ::specialbackup backup-block-device
  23. <up>
  24. borg info :: --last 1
  25. # A very important step if you choose keyfile mode (where the keyfile is only saved locally) is to export your keyfile and possibly print it, etc.
  26. borg key export :: --qr-code file.html # this creates a nice HTML, but when you want something simpler…
  27. < remove comment >
  28. < let there: borg check > --paper # this is a "manual input"-only backup (but it is also included in the --qr-code option)
  29. ## MAINTENANCE ##
  30. # Sometimes backups get broken or we want a regular "checkup" that everything is okay…
  31. borg check -v ::
  32. # Next problem: Usually you do not have infinite disk space. So you may need to prune your archive…
  33. # You can tune this in every detail. See the docs for details. Here only a simple example:
  34. borg prune --list --keep-last 1 --dry-run
  35. # When actually executing it in a script, you have to use it without the --dry-run option, of course.
  36. ## RESTORE ##
  37. # When you want to see the diff between two archives use this command.
  38. # E.g. what happened between the first two backups?
  39. borg diff ::backup1 backup2
  40. # Ah, we added a file, right…
  41. # There are also other ways to extract the data.
  42. # E.g. as a tar archive.
  43. borg export-tar --progress ::backup2 backup.tar.gz
  44. ls -l
  45. # You can mount an archive or even the whole repository:
  46. mkdir /tmp/mount
  47. borg mount :: /tmp/mount
  48. ls -la /tmp/mount
  49. borg umount /tmp/mount
  50. # That's it, but of course there is more to explore, so have a look at the docs.