basic.tcl 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. # Here you'll see some basic commands to start working with borg.
  7. # Note: This teaser screencast was made with __BORG_VERSION__ – older or newer borg versions may behave differently.
  8. # But let's start.
  9. # First of all, you can always get help:
  10. borg help
  11. # These are a lot of commands, so better we start with a few:
  12. # Let's create a repo on an external drive…
  13. borg init --encryption=repokey /media/backup/borgdemo
  14. # This uses the repokey encryption. You may look at "borg help init" or the online doc at https://borgbackup.readthedocs.io/ for other modes.
  15. # So now, let's create our first (compressed) backup.
  16. borg create --stats --progress --compression lz4 /media/backup/borgdemo::backup1 Wallpaper
  17. # That's nice, so far.
  18. # So let's add a new file…
  19. echo "new nice file" > Wallpaper/newfile.txt
  20. borg create --stats --progress --compression lz4 /media/backup/borgdemo::backup2 Wallpaper
  21. # Wow, this was a lot faster!
  22. # Notice the "Deduplicated size" for "This archive"!
  23. # Borg recognized that most files did not change and deduplicated them.
  24. # But what happens, when we move a dir and create a new backup?
  25. mv Wallpaper/bigcollection Wallpaper/bigcollection_NEW
  26. borg create --stats --progress --compression lz4 /media/backup/borgdemo::backup3 Wallpaper
  27. # Still quite fast…
  28. # 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.
  29. # Now lets look into a repo.
  30. borg list /media/backup/borgdemo
  31. # You'll see a list of all backups.
  32. # You can also use the same command to look into an archive. But we better filter the output here:
  33. borg list /media/backup/borgdemo::backup3 | grep 'deer.jpg'
  34. # Oh, we found our picture. Now extract it…
  35. mv Wallpaper Wallpaper.orig
  36. borg extract /media/backup/borgdemo::backup3 Wallpaper/deer.jpg
  37. # And check that it's the same:
  38. diff -s Wallpaper/deer.jpg Wallpaper.orig/deer.jpg
  39. # 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":
  40. borg init --encryption=repokey borgdemo@remoteserver.example:./demo
  41. # Easy, isn't it? That's all you need to know for basic usage.
  42. # If you want to see more, have a look at the screencast showing the "advanced usage".
  43. # In any case, enjoy using borg!
  44. }
  45. set script [string trim $script]
  46. set script [string map [list __BORG_VERSION__ [exec borg -V]] $script]
  47. set script [split $script \n]
  48. foreach line $script {
  49. send_user "$ "
  50. send_user -h $line\n
  51. spawn -noecho /bin/sh -c $line
  52. expect {
  53. "Enter new passphrase: " {
  54. send -h "correct horse battery staple\n"
  55. exp_continue
  56. }
  57. "Enter same passphrase again: " {
  58. send -h "correct horse battery staple\n"
  59. exp_continue
  60. }
  61. "Enter passphrase for key /media/backup/borgdemo: " {
  62. send -h "correct horse battery staple\n"
  63. exp_continue
  64. }
  65. -ex {Do you want your passphrase to be displayed for verification? [yN]: } {
  66. send \n
  67. exp_continue
  68. }
  69. eof
  70. }
  71. }