basic.tcl 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/usr/bin/env expect
  2. if {[file isdirectory /media/backup/borgdemo] == 0} {
  3. send_user "Please, run basic-prepare.sh first\n"
  4. exit 1
  5. }
  6. # Configuration for send -h
  7. # Tries to emulate a human typing
  8. # Tweak this if typing is too fast or too slow
  9. set send_human {.05 .1 1 .01 .2}
  10. # The screencast uses relative paths "Wallpaper"
  11. # We should not mess with the contents of whatever cwd happened to be
  12. cd [exec mktemp -d]
  13. file mkdir Wallpaper/bigcollection
  14. exec touch Wallpaper/deer.jpg
  15. set script {
  16. # Here you'll see some basic commands to start working with borg.
  17. # Note: This teaser screencast was made with borg version TODO: put version number here – older or newer borg versions may behave differently.
  18. # But let's start.
  19. # First of all, you can always get help:
  20. borg help
  21. # These are a lot of commands, so better we start with a few:
  22. # Let's create a repo on an external drive…
  23. borg init --encryption=repokey /media/backup/borgdemo
  24. # This uses the repokey encryption. You may look at "borg help init" or the online doc at https://borgbackup.readthedocs.io/ for other modes.
  25. # So now, let's create our first (compressed) backup.
  26. borg create --stats --progress --compression lz4 /media/backup/borgdemo::backup1 Wallpaper
  27. # That's nice, so far.
  28. # So let's add a new file…
  29. echo "new nice file" > Wallpaper/newfile.txt
  30. borg create --stats --progress --compression lz4 /media/backup/borgdemo::backup2 Wallpaper
  31. # Wow, this was a lot faster!
  32. # Notice the "Deduplicated size" for "This archive"!
  33. # Borg recognized that most files did not change and deduplicated them.
  34. # But what happens, when we move a dir and create a new backup?
  35. mv Wallpaper/bigcollection Wallpaper/bigcollection_NEW
  36. borg create --stats --progress --compression lz4 /media/backup/borgdemo::backup3 Wallpaper
  37. # Still quite fast…
  38. # But when you look at the "deduplicated file size" again, you see that borg also recognized that only the dir and not the files changed in this backup.
  39. # Now lets look into a repo.
  40. borg list /media/backup/borgdemo
  41. # You'll see a list of all backups.
  42. # You can also use the same command to look into an archive. But we better filter the output here:
  43. borg list /media/backup/borgdemo::backup3 | grep 'deer.jpg'
  44. # Oh, we found our picture. Now extract it…
  45. mv Wallpaper Wallpaper.orig
  46. borg extract /media/backup/borgdemo::backup3 Wallpaper/deer.jpg
  47. # And check that it's the same:
  48. diff -s Wallpaper/deer.jpg Wallpaper.orig/deer.jpg
  49. # And, of course, we can also create remote repos via ssh when borg is setup there. This command creates a new remote repo in a subdirectory called "demo":
  50. # TODO: remote repo
  51. # borg init --encryption=repokey borgdemo@remoteserver.example:./demo
  52. # Easy, isn't it? That's all you need to know for basic usage.
  53. # If you want to see more, have a look at the screencast showing the "advanced usage".
  54. # In any case, enjoy using borg!
  55. }
  56. foreach line [split [string trimleft $script] \n] {
  57. send_user "$ "
  58. send_user -h $line\n
  59. spawn -noecho /bin/sh -c $line
  60. expect {
  61. "Enter new passphrase: " {
  62. send -h "correct horse battery staple\n"
  63. exp_continue
  64. }
  65. "Enter same passphrase again: " {
  66. send -h "correct horse battery staple\n"
  67. exp_continue
  68. }
  69. "Enter passphrase for key /media/backup/borgdemo: " {
  70. send -h "correct horse battery staple\n"
  71. exp_continue
  72. }
  73. -ex {Do you want your passphrase to be displayed for verification? [yN]: } {
  74. send \n
  75. exp_continue
  76. }
  77. eof
  78. }
  79. }