Automate the advanced usage screencast

This commit is contained in:
Andrey Bienkowski 2022-02-20 14:24:49 +03:00 committed by Thomas Waldmann
parent bff922a9ba
commit df0e8599de
2 changed files with 109 additions and 2 deletions

View File

@ -2,7 +2,7 @@ Vagrant.configure("2") do |config|
config.vm.box = "debian/bullseye64"
config.vm.provision "install dependencies", type: "shell", inline: <<-SHELL
apt-get update
apt-get install -y wget expect gpg asciinema ssh adduser
apt-get install -y wget expect gpg asciinema ssh adduser fuse
SHELL
config.vm.provision "record install", type: "shell", inline: <<-SHELL
gpg --recv-keys "6D5B EF9A DD20 7580 5747 B70F 9F88 FB52 FAF7 B393"
@ -16,9 +16,13 @@ Vagrant.configure("2") do |config|
rm -r ~/.ssh/ || true
deluser --remove-home borgdemo || true
# In case we have skipped "record install"
wget https://github.com/borgbackup/borg/releases/download/1.1.0b6/borg-linux64
install --owner root --group root --mode 755 borg-linux64 /usr/local/bin/borg
mkdir -p /media/backup/borgdemo
adduser borgdemo
adduser --disabled-password borgdemo
echo '127.0.0.1 remoteserver.example' >> /etc/hosts
ssh-keygen -f ~/.ssh/id_rsa -N ''
ssh-keyscan remoteserver.example > ~/.ssh/known_hosts
@ -27,4 +31,24 @@ Vagrant.configure("2") do |config|
asciinema rec -c 'expect /vagrant/basic.tcl' --overwrite /vagrant/basic.json
SHELL
config.vm.provision "record advanced usage", type: "shell", inline: <<-SHELL
rm -r /media/backup/borgdemo || true
# In case we have skipped "record install"
wget https://github.com/borgbackup/borg/releases/download/1.1.0b6/borg-linux64
install --owner root --group root --mode 755 borg-linux64 /usr/local/bin/borg
mkdir -p /media/backup/borgdemo
mkdir -p Wallpaper
mkdir -p ~/Downloads/big
dd if=/dev/zero of=loopbackfile.img bs=100M count=4
losetup /dev/loop0 loopbackfile.img
# TODO: emulate basic.tcl
export BORG_PASSPHRASE='1234'
borg init --encryption=repokey /media/backup/borgdemo
unset BORG_PASSPHRASE
asciinema rec -c 'expect /vagrant/advanced.tcl' --overwrite /vagrant/advanced.json
SHELL
end

View File

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