Files
scripts/Bit-Frigger-Tarballer

31 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
# Script to export the Bit Frigger's rootfs to a zstd tarball periodically
FINAL_DIR="/Red-Vol/Backups/Bit-Frigger/Tarball"
#Check for root permissions
if [[ $(whoami) != "root" ]]; then
echo "Please run this script as root or with sudo."
exit
fi
#Create directory if it does not exist
if [[ ! -d $FINAL_DIR ]]; then
echo "Destination directory $FINAL_DIR does not exist. Creating..."
mkdir $FINAL_DIR
echo "Changing ownership to shmick."
chown -r shmick:shmick $FINAL_DIR
else
echo "Destination directory exists."
fi
#Sync everything to it
echo "Gathering files for the tarball"
rsync -aHAXSv --progress --exclude=/dev --exclude=/Red-Vol --exclude=/proc --exclude=/rksmb --exclude=/sys --exclude="/.snapshots" --exclude="/run" --exclude="/tmp" "/" "$FINAL_DIR"
#And tar it with ZSTD
echo "Compressing tarball"
cd $FINAL_DIR
echo "Working in directory $(pwd)"
if [[ -f "$FINAL_DIR/Bit-Frigger.tar" ]]; then
tar rvf Bit-Frigger.tar $(pwd) && echo "Running xz..." && xz -vv -z --threads=0 -9 Bit-Frigger.tar --memlimit=$(free -h | grep -v Swap | grep -v total | awk '{print $NF}')
else
tar cvf Bit-Frigger.tar $(pwd) && echo "Running xz..." && xz -vv -z --threads=0 -9 Bit-Frigger.tar --memlimit=$(free -h | grep -v Swap | grep -v total | awk '{print $NF}')
fi