Skip to content

Instantly share code, notes, and snippets.

@bigntallmike
Created February 1, 2022 06:29
Show Gist options
  • Save bigntallmike/6b12eec785003eb5481f0e2445b05782 to your computer and use it in GitHub Desktop.
Save bigntallmike/6b12eec785003eb5481f0e2445b05782 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# Make a local compressed copy of a backup file, typically being delivered by SSH
#
# Consider:
# xfsdump -l0 -M "$BACKUPNAME" -L "fullbackup" - /home | ssh $REMOTE "compressincomingbackup $BACKUPNAME"
#
# Copyright 2022 Michael T. Babcock
# Licensed to use freely under LGPL or MIT at user's discretion
STORAGE="/var/backups"
TARGET="$STORAGE/$1.xd.xz"
LOGFILE="$STORAGE/transfer-`date +%Y%m%d%H%M%S.log`"
# How much data to buffer between network traffic and compression
BUFFER="128M"
# How many cores to use for compression
CPU=4
if [ "x$1" = "x" ]; then
echo "Specify filename on command-line"
exit 1
fi
echo "Starting backup to $TARGET:" | tee $LOGFILE
bfr -v -p -b$BUFFER - 2>>$LOGFILE \
| nice -n10 \
xz -4 -T$CPU -c - > $TARGET
SUCCESS=$?
echo "."
echo "Done backup (returned: $SUCCESS) -- verifying:" | tee -a $LOGFILE
nice -n10 xz -tv $TARGET 2>&1 | tee -a $LOGFILE
echo "Verify returned $?" | tee -a $LOGFILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment