Last active
May 27, 2024 22:24
-
-
Save timabell/68d112d66623d9a4a3643c86a93debee to your computer and use it in GitHub Desktop.
tar+lz4 backup with progress - https://timwise.co.uk/2018/04/01/building-a-windows-10-development-vm-from-scratch/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# https://gist.github.com/timabell/68d112d66623d9a4a3643c86a93debee#file-backup-sh | |
# 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 | |
# * https://stackoverflow.com/questions/8228047/adding-timestamp-to-a-filename-with-mv-in-bash/8229220#8229220 | |
# 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..." | |
mountpoint=/media/tim/backup/ | |
cd "$mountpoint" | |
mkdir -p fox | |
cd fox | |
base=/home/ | |
src=tim | |
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." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -v | |
cd restorepath/ | |
pv /media/tim/WD6/thebackup.tar.lz4 | lz4 -dc - | tar -xv |
thanks for sharing
glad it's useful
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks for sharing