Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#!/bin/bash -v
# backing up a vm
cd /media/tim/WD6/
base="/home/tim/VirtualBox VMs"
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%
# lz4 is better than gz for large backups because you end up I/O bound on disk instead of CPU bound
# refs:
# *
# *
# *
# 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
# set up folder on backup drive
echo "Opening/creating backup folder..."
cd "$mountpoint"
mkdir -p fox
cd fox
echo "Getting source folder size..."
#size_human=`du -sh "$base/$src"`
size_bytes=`du -sb "$base/$src" | awk '{print $1}'`
echo "$size_bytes bytes to backup."
echo "Backing up..."
tar -cpC $base $src -P | pv -s "$size_bytes" | lz4 >> "$(date -d "today" +"%Y%m%d-%H%M")-home.tar.lz4"
echo "Done."
#!/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