advanced.tcl 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # Configuration for send -h
  2. # Tries to emulate a human typing
  3. # Tweak this if typing is too fast or too slow
  4. set send_human {.05 .1 1 .01 .2}
  5. set script {
  6. # For the pro users, here are some advanced features of borg, so you can impress your friends. ;)
  7. # Note: This screencast was made with __BORG_VERSION__ – older or newer borg versions may behave differently.
  8. # First of all, we can use several environment variables for borg.
  9. # E.g. we do not want to type in our repo path and password again and again…
  10. export BORG_REPO='/media/backup/borgdemo'
  11. export BORG_PASSPHRASE='1234'
  12. # Problem solved, borg will use this automatically… :)
  13. # We'll use this right away…
  14. ## ADVANCED CREATION ##
  15. # We can also use some placeholders in our archive name…
  16. borg create --stats --progress --compression lz4 ::{user}-{now} Wallpaper
  17. # Notice the backup name.
  18. # And we can put completely different data, with different backup settings, in our backup. It will be deduplicated, anyway:
  19. borg create --stats --progress --compression zlib,6 --exclude ~/Downloads/big ::{user}-{now} ~/Downloads
  20. # Or let's backup a device via STDIN.
  21. sudo dd if=/dev/loop0 bs=10M | borg create --progress --stats ::specialbackup -
  22. # Let's continue with some simple things:
  23. ## USEFUL COMMANDS ##
  24. # You can show some information about an archive. You can even do it without needing to specify the archive name:
  25. borg info :: --last 1
  26. # So let's rename our last archive:
  27. borg rename ::specialbackup backup-block-device
  28. borg info :: --last 1
  29. # 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.
  30. borg key export --qr-html :: file.html # this creates a nice HTML, but when you want something simpler…
  31. borg key export --paper :: # this is a "manual input"-only backup (but it is also included in the --qr-code option)
  32. ## MAINTENANCE ##
  33. # Sometimes backups get broken or we want a regular "checkup" that everything is okay…
  34. borg check -v ::
  35. # Next problem: Usually you do not have infinite disk space. So you may need to prune your archive…
  36. # You can tune this in every detail. See the docs for details. Here only a simple example:
  37. borg prune --list --keep-last 1 --dry-run
  38. # When actually executing it in a script, you have to use it without the --dry-run option, of course.
  39. ## RESTORE ##
  40. # When you want to see the diff between two archives use this command.
  41. # E.g. what happened between the first two backups?
  42. borg diff ::backup1 backup2
  43. # Ah, we added a file, right…
  44. # There are also other ways to extract the data.
  45. # E.g. as a tar archive.
  46. borg export-tar --progress ::backup2 backup.tar.gz
  47. ls -l
  48. # You can mount an archive or even the whole repository:
  49. mkdir /tmp/mount
  50. borg mount :: /tmp/mount
  51. ls -la /tmp/mount
  52. borg umount /tmp/mount
  53. # That's it, but of course there is more to explore, so have a look at the docs.
  54. }
  55. set script [string trim $script]
  56. set script [string map [list __BORG_VERSION__ [exec borg -V]] $script]
  57. set script [split $script \n]
  58. set ::env(PS1) "$ "
  59. set stty_init -echo
  60. spawn -noecho /bin/sh
  61. foreach line $script {
  62. expect "$ "
  63. send_user -h $line\n
  64. send $line\n
  65. }
  66. expect "$ "