Browse Source

#437 basic background backup script

master
Christian Rotzoll 6 years ago
parent
commit
6e1af3a3a0
  1. 69
      home.admin/_background.sh

69
home.admin/_background.sh

@ -151,6 +151,33 @@ do
fi
###############################
# SCB Monitoring
###############################
# check every 1min
recheckSCB=$(($counter % 60))
if [ ${recheckSCB} -eq 1 ]; then
echo "SCB Monitoring ..."
# check if channel.backup exists
scbExists=$(sudo ls /mnt/hdd/lnd/data/chain/${network}/${chain}net/channel.backup 2>/dev/null | grep -c 'channel.backup')
if [ ${scbExists} -eq 1 ]; then
echo "Found Channel Backup File .. check if changed .."
md5checksumORG=$(sudo md5sum /mnt/hdd/lnd/data/chain/${network}/${chain}net/channel.backup 2>/dev/null | head -n1 | cut -d " " -f1)
md5checksumCPY=$(sudo md5sum /home/admin/.lnd/data/chain/${network}/${chain}net/channel.backup 2>/dev/null | head -n1 | cut -d " " -f1)
if [ "${md5checksumORG}" != "${md5checksumCPY}" ]; then
echo "--> Channel Backup File changed"
sudo mkdir -p /home/admin/.lnd/data/chain/${network}/${chain}net/ 2>/dev/null
sudp cp /mnt/hdd/lnd/data/chain/${network}/${chain}net/channel.backup /home/admin/.lnd/data/chain/${network}/${chain}net/channel.backup
echo "OK channel.backup copied to '/home/admin/.lnd/data/chain/${network}/${chain}net/channel.backup'"
else
echo "Channel Backup File not changed."
fi
else
echo "No Channel Backup File .."
fi
fi
###############################
# LND MONITOR LOST SYNC
###############################
@ -159,78 +186,78 @@ do
recheckSync=$(($counter % 300))
if [ ${recheckSync} -eq 1 ]; then
source ${configFile}
echo "LND MONITOR LOST SYNC ..."
#echo "LND MONITOR LOST SYNC ..."
lndSynced=$(sudo -u bitcoin /usr/local/bin/lncli --chain=${network} --network=${chain}net getinfo 2>/dev/null | jq -r '.synced_to_chain' | grep -c true)
echo "lndSynced(${lndSynced})"
echo "syncedSince(${syncedSince})"
echo "lastSyncState(${lastSyncState})"
#echo "lndSynced(${lndSynced})"
#echo "syncedSince(${syncedSince})"
#echo "lastSyncState(${lastSyncState})"
if [ ${lndSynced} -eq ${lastSyncState} ]; then
echo "no sync change"
if [ ${lndSynced} -eq 1 ]; then
echo "all is good - LND still in sync now for:"
#echo "all is good - LND still in sync now for:"
actualSecondsTimestamp=$(date +%s)
secondsInSync=$(echo "${actualSecondsTimestamp}-"${syncedSince} | bc)
echo "${secondsInSync} seconds"
#echo "${secondsInSync} seconds"
# when >10min in sync
if [ ${secondsInSync} -gt 600 ]; then
echo "LND in sync for longer then 10 minutes"
if [ ${secondsInSync} -gt 3600 ]; then
#echo "LND in sync for longer then 1 hour"
if [ "${backupTorrentSeeding}" == "on" ]; then
echo "Backup Torrent Seeding is ON - check if already running"
#echo "Backup Torrent Seeding is ON - check if already running"
source <(sudo -u admin /home/admin/50torrentHDD.sh status)
if [ "${baseSeeding}" == "0" ] || [ "${updateSeeding}" == "0" ]; then
echo "---> STARTING Backup Torrent Seeding"
sudo -u admin /home/admin/50torrentHDD.sh backup-torrent-hosting
else
echo "Backup Torrent Seeding - already running"
#echo "Backup Torrent Seeding - already running"
fi
else
echo "Backup Torrent Seeding is OFF"
#echo "Backup Torrent Seeding is OFF"
fi
fi
else
echo "still not in sync"
#echo "still not in sync"
if [ ${syncedSince} -gt 0 ]; then
echo "was in sync at least once since rinning but lost now for:"
#echo "was in sync at least once since rinning but lost now for:"
actualSecondsTimestamp=$(date +%s)
secondsOutOfSync=$(echo "${actualSecondsTimestamp}-"${syncedSince} | bc)
echo "${secondsOutOfSync} seconds"
#echo "${secondsOutOfSync} seconds"
# when >10min out of sync
if [ ${secondsOutOfSync} -gt 600 ]; then
echo "! LND fell out of sync for longer then 10 minutes !"
#echo "! LND fell out of sync for longer then 10 minutes !"
if [ "${backupTorrentSeeding}" == "on" ]; then
echo "Backup Torrent Seeding is ON - check if still running"
#echo "Backup Torrent Seeding is ON - check if still running"
source <(sudo -u admin /home/admin/50torrentHDD.sh status)
if [ "${baseSeeding}" == "1" ] || [ "${updateSeeding}" == "1" ]; then
echo "---> STOPPING Backup Torrent Seeding"
sudo -u admin /home/admin/50torrentHDD.sh stop
else
echo "No Backup Torrent Seeding - already stopped"
#echo "No Backup Torrent Seeding - already stopped"
fi
else
echo "Backup Torrent Seeding is OFF"
#echo "Backup Torrent Seeding is OFF"
fi
fi
# when >1h out of sync
if [ ${secondsOutOfSync} -gt 3600 ]; then
echo "!!!! LND fell out of sync for longer then 1 hour !!!"
# echo "!!!! LND fell out of sync for longer then 1 hour !!!"
# TODO: When auto-unlock is ON --> consider implementing restart (this sometimes help)
fi
else
echo "LND was never in sync since since started (could be multiple reasons - dont act)"
#echo "LND was never in sync since since started (could be multiple reasons - dont act)"
fi
fi
else
echo "sync change detected"
if [ ${lastSyncState} -eq 1 ] && [ ${lndSynced} -eq 0 ]; then
echo "--> LND SNC LOST"
echo "--> LND SYNC LOST"
else
if [ ${syncedSince} -eq 0 ]; then
echo "--> LND SYNC GAINED"

Loading…
Cancel
Save