#1676 Fix BTRFS Details (#1756)

This commit is contained in:
Christian Rotzoll 2020-11-10 23:40:54 +01:00 committed by rootzoll
parent 020e4f8402
commit aa409c96aa
6 changed files with 128 additions and 17 deletions

View File

@ -67,6 +67,14 @@ if [ "${state}" = "copysource" ]; then
exit
fi
# check if copy blockchain over LAN to this RaspiBlitz was running
source <(/home/admin/config.scripts/blitz.copyblockchain.sh status)
if [ "${copyInProgress}" = "1" ]; then
echo "Detected interrupted COPY blochain process ..."
/home/admin/50copyHDD.sh
exit
fi
# signal that after bootstrap recover user dialog is needed
recoveredInfoExists=$(sudo ls /home/admin/raspiblitz.recover.info 2>/dev/null | grep -c '.info')
if [ ${recoveredInfoExists} -gt 0 ]; then

View File

@ -206,11 +206,6 @@ echo "*********************************************"
# if started with parameter "stop-after-script" - quit here
if [ "$1" == "stop-after-script" ]; then
if [ ${quickCheckOK} -eq 0 ]; then
echo "cleaning up .."
sudo rm -rf /mnt/hdd/bitcoin/blocks
sudo rm -rf /mnt/hdd/bitcoin/chainstate
fi
echo "DONE Copy"
exit 0
fi

View File

@ -78,7 +78,7 @@ copyHost()
echo "# install dependencies ..."
sudo apt-get install -y sshpass
sudo rm /root/.ssh/known_hosts
sudo rm /root/.ssh/known_hosts 2>/dev/nul
canLogin=$(sudo sshpass -p "${targetPassword}" ssh -t -o StrictHostKeyChecking=no bitcoin@${targetIP} "echo 'working'" 2>/dev/null | grep -c 'working')
if [ ${canLogin} -eq 0 ]; then
whiptail --msgbox "Password was not working for IP: ${targetIP}\n\n- check thats the correct IP for correct RaspiBlitz\n- check that you used PASSWORD A and had no typo\n- If you tried too often, wait 1h try again" 11 58 "" --title " Testing Target Password " --backtitle "RaspiBlitz - Copy Blockchain"
@ -104,11 +104,46 @@ copyHost()
sudo sshpass -p "${targetPassword}" rsync -avhW -e 'ssh -o StrictHostKeyChecking=no -p 22' /home/admin/copy_begin.time bitcoin@${targetIP}:/mnt/hdd/bitcoin
sudo rm -f /home/admin/copy_begin.time
# transfere blockchain data
sudo sshpass -p "${targetPassword}" rsync -avhW -e 'ssh -o StrictHostKeyChecking=no -p 22' --info=progress2 ./chainstate ./blocks bitcoin@${targetIP}:/mnt/hdd/bitcoin
sed -i "s/^state=.*/state=/g" /home/admin/raspiblitz.info
# repeat the syncing of directories until
# a) there are no files left to transfere (be robust against failing connections, etc)
# b) the user hits a key to break loop after report
while :
do
# transfere blockchain data
rm -f ./transferred.rsync
sudo sshpass -p "${targetPassword}" rsync -avhW -e 'ssh -o StrictHostKeyChecking=no -p 22' --info=progress2 --log-file=./transferred.rsync ./chainstate ./blocks bitcoin@${targetIP}:/mnt/hdd/bitcoin
# check result
# the idea is even after successfull transfer the loop will run a second time
# but on the second time there will be no files transfered (log lines are below 4)
# thats the signal that its done
linesInLogFile=$(wc -l ./transferred.rsync | cut -d " " -f 1)
if [ ${linesInLogFile} -lt 4 ]; then
echo ""
echo "OK all files transfered. DONE"
sleep 2
break
fi
# wait 20 seconds for user exiting loop
echo ""
echo -en "OK on sync loop done ... will test in another if all was transferred."
echo -en "PRESS X TO MANUALLY FINISH SYNCING"
read -n 1 -t 6 keyPressed
if [ "${keyPressed}" = "x" ]; then
echo ""
echo "Ending Sync ..."
sleep 2
break
fi
done
# transfere end flag
sed -i "s/^state=.*/state=/g" /home/admin/raspiblitz.info
date +%s > /home/admin/copy_end.time
sudo sshpass -p "${targetPassword}" rsync -avhW -e 'ssh -o StrictHostKeyChecking=no -p 22' /home/admin/copy_end.time bitcoin@${targetIP}:/mnt/hdd/bitcoin
sudo rm -f /home/admin/copy_end.time

View File

@ -0,0 +1,57 @@
#!/bin/bash
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
echo "# managing the copy of blockchain data over LAN"
echo "# blitz.copyblockchain.sh [status]"
echo "error='missing parameters'"
exit 1
fi
# load basic system settings
source /home/admin/raspiblitz.info 2>/dev/null
source /mnt/hdd/raspiblitz.conf 2>/dev/null
# check that blockchain is set & supported
if [ "${network}" != "bitcoin" ] && [ "${network}" != "litecoin" ]; then
echo "blockchain='{$network}'"
echo "error='blockchain type missing or not supported'"
exit 1
fi
# check that HDD is available
isMounted=$(sudo df | grep -c /mnt/hdd)
if [ "${isMounted}" != "1" ]; then
echo "error='no datadrive is mounted'"
exit 1
fi
###################
# STATUS
###################
# check if copy is in progress
copyBeginTime=$(cat /mnt/hdd/${network}/copy_begin.time 2>/dev/null | tr -cd '[[:digit:]]')
if [ ${#copyBeginTime} -eq 0 ]; then
copyBeginTime=0
fi
copyEndTime=$(cat /mnt/hdd/${network}/copy_end.time 2>/dev/null | tr -cd '[[:digit:]]')
if [ ${#copyEndTime} -eq 0 ]; then
copyEndTime=0
fi
copyInProgress=0
if [ ${copyBeginTime} -gt ${copyEndTime} ]; then
copyInProgress=1
fi
# output status data & exit
if [ "$1" = "status" ]; then
echo "# blitz.copyblockchain.sh"
echo "copyInProgress=${copyInProgress}"
echo "copyBeginTime=${copyBeginTime}"
echo "copyEndTime=${copyEndTime}"
exit 1
fi
# if no other
echo "error='unkown command'"
exit 1

View File

@ -236,7 +236,13 @@ if [ "$1" = "status" ]; then
# STATUS INFO WHEN MOUNTED
# output data drive
hddDataPartition=$(df | grep "/mnt/hdd$" | cut -d " " -f 1 | cut -d "/" -f 3)
if [ ${isBTRFS} -eq 1 ]; then
# on btrfs date the storage partition as the data partition
hddDataPartition=$(df | grep "/mnt/storage$" | cut -d " " -f 1 | cut -d "/" -f 3)
else
# on ext4 its the whole /mnt/hdd
hddDataPartition=$(df | grep "/mnt/hdd$" | cut -d " " -f 1 | cut -d "/" -f 3)
fi
hdd=$(echo $hddDataPartition | sed 's/[0-9]*//g')
hddFormat=$(lsblk -o FSTYPE,NAME,TYPE | grep part | grep "${hddDataPartition}" | cut -d " " -f 1)
if [ "${hddFormat}" = "ext4" ]; then
@ -1208,15 +1214,19 @@ if [ "$1" = "link" ]; then
>&2 echo "# Creating BTRFS setup links"
>&2 echo "# - linking blockchains into /mnt/hdd"
if [ $(ls /mnt/hdd/bitcoin 2>/dev/null | grep -c 'bitcoin') -eq 0 ]; then
if [ $(ls -F /mnt/hdd/bitcoin | grep -c '/mnt/hdd/bitcoin@') -eq 0 ]; then
sudo mkdir -p /mnt/storage/bitcoin
sudo cp -R /mnt/hdd/bitcoin/* /mnt/storage/bitcoin 2>/dev/null
sudo chown -R bitcoin:bitcoin /mnt/storage/bitcoin
sudo rm -r /mnt/hdd/bitcoin
sudo ln -s /mnt/storage/bitcoin /mnt/hdd/bitcoin
sudo rm /mnt/storage/bitcoin/bitcoin 2>/dev/null
fi
if [ $(ls /mnt/hdd/litecoin 2>/dev/null | grep -c 'litecoin') -eq 0 ]; then
if [ $(ls -F /mnt/hdd/litecoin | grep -c '/mnt/hdd/litecoin@') -eq 0 ]; then
sudo mkdir -p /mnt/storage/litecoin
sudo cp -R /mnt/hdd/litecoin/* /mnt/storage/litecoin 2>/dev/null
sudo chown -R bitcoin:bitcoin /mnt/storage/litecoin
sudo rm -r /mnt/hdd/litecoin
sudo ln -s /mnt/storage/litecoin /mnt/hdd/litecoin
sudo rm /mnt/storage/litecoin/litecoin 2>/dev/null
fi

View File

@ -103,8 +103,12 @@ if [ "$1" = "export" ]; then
# get md5 checksum
echo "# Building checksum (can take also a while) ..."
md5checksum=$(md5sum ${defaultZipPath}/raspiblitz-export-temp.tar.gz | head -n1 | cut -d " " -f1)
echo "# md5checksum=${md5checksum}"
echo "md5checksum=${md5checksum}"
# get byte size
bytesize=$(wc -c ${defaultZipPath}/raspiblitz-export-temp.tar.gz | cut -d " " -f 1)
echo "bytesize=${bytesize}"
# final renaming
name="raspiblitz${blitzname}${datestamp}-${md5checksum}.tar.gz"
echo "exportpath='${defaultZipPath}'"
@ -154,7 +158,11 @@ if [ "$1" = "export-gui" ]; then
echo "${scpDownloadWin}"
echo ""
echo "Use password A to authenticate file transfer."
echo
echo
echo "To check if you downloaded the file correctly:"
echo "md5-checksum --> ${md5checksum}"
echo "byte-size --> ${bytesize}"
echo
echo "Your Lightning node is now stopped. After download press ENTER to shutdown your raspiblitz."
echo "To complete the data migration follow then instructions on the github FAQ."
echo
@ -362,9 +370,7 @@ if [ "$1" = "import-gui" ]; then
echo
echo "ON YOUR LAPTOP open a new terminal and change into"
echo "the directory where your migration file is and"
echo "COPY, PASTE AND EXECUTE THE FOLLOWING COMMAND for Linux or MacOS:"
echo "scp -r './raspiblitz-*.tar.gz admin@${localip}:${defaultZipPath}'"
echo "OR for Windows:"
echo "COPY, PASTE AND EXECUTE THE FOLLOWING COMMAND:"
echo "scp -r ./raspiblitz-*.tar.gz admin@${localip}:${defaultZipPath}"
echo ""
echo "Use password 'raspiblitz' to authenticate file transfer."