Instantly share code, notes, and snippets.

Embed
What would you like to do?
tar+lz4 backup with progress
#!/bin/bash -v
# backing up a vm
cd /media/tim/WD6/
base="/home/tim/VirtualBox VMs"
src=win10-2018
mv $src.tar.lz4 $src.tar.lz4.old
ls -lh "$base/$src"
du -sh "$base/$src"
df -h "$base"
df -h .
du -sb "$base/$src"
du -sb "$base/$src" | awk '{print $1}'
tar -cpC "$base" "$src" -P | pv -s $(du -sb "$base/$src" | awk '{print $1}') | lz4 >> "$src.tar.lz4"
# output like this:
# 8.79GiB 0:00:43 [ 205MiB/s] [=====================================================================> ] 99%
#!/bin/sh -v
# lz4 is better than gz for large backups because you end up I/O bound on disk instead of CPU bound
# refs:
# * https://stackoverflow.com/questions/24063846/how-to-use-tar-with-lz4#24086155
# * https://superuser.com/questions/168749/is-there-a-way-to-see-any-tar-progress-per-file/665181#665181
# Note that progress is inaccurate and variable because it's based on input bytes processed vs total, but the speed is limited by
# output bytes to the spinning rust backup disk, and the ratio varies with the compressability of the input data.
sudo apt update
sudo apt install liblz4-tool pv
# backing up a home folder
cd /media/tim/spinning-rust-external-hdd
base=/home/
src=tim
tar -cpC $base $src -P | pv -s $(du -sb $base/$src | awk '{print $1}') | lz4 >> 2018-03-15-home.tar.lz4
#!/bin/sh -v
cd restorepath/
pv /media/tim/WD6/thebackup.tar.lz4 | lz4 -dc - | tar -xv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment