Part 2: Compress and Backup

This tutorial explains how you can make a backup of SBFspot.db
Because we're backing up to USB memory, we will compress the file first

Create backup script:
sudo nano /usr/local/bin/sbfspot.3/


# If USB memory is almost full (90%), log a warning


dst="/home/pi/smadata/backup_usb/SBFspot_$(date +"%Y%m%d").tar.gz"

# Compress the db
tar cfz $dst -P $src

# Check if backup exists
if [ ! -f "$dst" ]; then
	echo "ERROR: Backup file $dst is not found. Something has gone wrong.">>$logfile
	echo "Backup completed successfully.">>$logfile
	# Get disk usage in percent
	df_used=$(df /home/pi/smadata/backup_usb | grep -o '[0-9]\{1,\}%')
	# Drop last char (%)

	#If used space exceeds threshold, log it
	if [ $df_used -gt $df_threshold ]; then
		echo "WARNING: Backup disk has reached the $df_threshold% threshold. The actual used space is $df_used%">>$logfile

Make script executable;
sudo chmod a+x /usr/local/bin/sbfspot.3/

To run the script the end of each day, setup a cron job:
crontab -e
55 23 * * * /usr/local/bin/sbfspot.3/

Next: Compress and Backup

Last edited Thu at 9:40 PM by SBF, version 5