backup/tar_backup/backup
2024-08-25 14:36:50 -04:00

53 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
if [ $# -ne 1 ]; then
echo "Usage: $0 <backup_location>"
exit 1
fi
BACKUP_LOCATION="${1}backup-${HOSTNAME}-$(date +%Y-%m-%d).tar"
echo $BACKUP_LOCATION
COMPRESS=false
rm -f $BACKUP_LOCATION
echo '
________ ________ ________ ___ __ ___ ___ ________ _________ ________ ________ ___
|\ __ \|\ __ \|\ ____\|\ \|\ \ |\ \|\ \|\ __ \ |\___ ___\\ __ \|\ __ \|\ \
\ \ \|\ /\ \ \|\ \ \ \___|\ \ \/ /|\ \ \\\ \ \ \|\ \ \|___ \ \_\ \ \|\ \ \ \|\ \ \ \
\ \ __ \ \ __ \ \ \ \ \ ___ \ \ \\\ \ \ ____\ \ \ \ \ \ \\\ \ \ \\\ \ \ \
\ \ \|\ \ \ \ \ \ \ \____\ \ \\ \ \ \ \\\ \ \ \___| \ \ \ \ \ \\\ \ \ \\\ \ \ \_____
\ \_______\ \__\ \__\ \_______\ \__\\ \__\ \_______\ \__\ \ \__\ \ \_______\ \_______\ \_______\
\|_______|\|__|\|__|\|_______|\|__| \|__|\|_______|\|__| \|__| \|_______|\|_______|\|_______|'
echo ""
echo 'backing up the following folders:'
echo -e "\e[32m-------------------------------------------"
cat *.bak
echo ""
echo ""
echo -e "\e[0mStarting Backup"
SIZE=`python3 -c "print($(cat *.bak | tr '\n' '\0' | xargs -0 du -sk | cut -f 1 | tr '\n' '+')0)"`
tar -cpT *.bak -f - 2>/dev/null | pv -p -s ${SIZE}k > $BACKUP_LOCATION
echo ""
if [ "$COMPRESS" = true ];
then
echo -e "\e[0mCompressing Backup"
gzip $BACKUP_LOCATION
echo -e "\e[0mRemoving Uncompressed Backup"
rm -f $BACKUP_LOCATION
fi
echo -e "\e[0mBackup Done"