Last active
March 4, 2021 18:01
-
-
Save caseypugh/b501db936cfa17fc73662b970849adec to your computer and use it in GitHub Desktop.
Free up space on your DIY helium hotspot
This file contains hidden or 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 | |
# Download this script to your computer and upload it to your hotspot using scp | |
# scp /Path/to/refresh-blockchain.sh hotspot_ssh_address:/home/pi | |
# | |
# SSH into hotspot, and edit your crontab (sudo crontab -e) and add this: | |
# 0 8 * * * /home/pi/refresh-blockchain.sh >> /home/pi/refresh-blockchain.log 2>&1 | |
DATA_PATH=/home/pi/miner_data | |
DATA_BACKUP_PATH=/home/pi/miner_data_bak | |
percent_used_disk_space=$(df -Bm | grep /dev/root | egrep -o "[0-9]+%" | egrep -o "[0-9]+") | |
threshold=90 | |
echo "Total disk space usage: $percent_used_disk_space%" | |
if (( $percent_used_disk_space >= $threshold )); then | |
echo "Running low on space!" | |
echo "Making a snapshot backup..." | |
docker exec miner miner snapshot take /var/data/snapshot.bin | |
echo "Stopping the miner..." | |
docker stop miner | |
echo "Moving $DATA_PATH TO $DATA_BACKUP_PATH" | |
mv $DATA_PATH $DATA_BACKUP_PATH | |
mkdir $DATA_PATH | |
echo "Copying the keys over to new miner data folder" | |
cp -r $DATA_BACKUP_PATH/miner $DATA_PATH | |
echo "Moving the snapshot over" | |
cp $DATA_BACKUP_PATH/snapshot.bin $DATA_PATH | |
echo "Starting miner back up" | |
docker start miner | |
echo "Deleting backup folder." | |
sudo rm -rf $DATA_BACKUP_PATH | |
echo "Importing snapshot..." | |
docker exec miner miner snapshot load /var/data/snapshot.bin | |
echo "Deleting snapshot" | |
rm $DATA_PATH/snapshot.bin | |
disk_space=$(df -Bm | grep /dev/root | egrep -o "[0-9]+%") | |
echo; echo "Complete! Total disk space usage: $disk_space" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment