#1676 Fix BTRFS migration (#1823)

This commit is contained in:
Christian Rotzoll 2020-11-30 14:14:49 +01:00 committed by rootzoll
parent 8736370b58
commit c9e5cf2783
4 changed files with 63 additions and 21 deletions

View File

@ -416,6 +416,17 @@ case $CHOICE in
;;
MIGRATION)
sudo /home/admin/config.scripts/blitz.migration.sh "import-gui"
# on error clean & repeat
if [ "$?" = "1" ]; then
echo
echo "# clean and unmount for next try"
sudo rm -f ${defaultZipPath}/raspiblitz-*.tar.gz 2>/dev/null
sudo umount /mnt/hdd 2>/dev/null
sudo umount /mnt/storage 2>/dev/null
sudo umount /mnt/temp 2>/dev/null
sleep 2
/home/admin/00raspiblitz.sh
fi
exit 0
;;
CONTINUE)

View File

@ -78,7 +78,7 @@ copyHost()
echo "# install dependencies ..."
sudo apt-get install -y sshpass
sudo rm /root/.ssh/known_hosts 2>/dev/nul
sudo rm /root/.ssh/known_hosts 2>/dev/null
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"

View File

@ -95,18 +95,26 @@ if [ "$1" = "status" ]; then
else
testsize=0
fi
#echo "# line($line)"
#echo "# testname(${testname}) testdevice(${testdevice}) testpartition(${testpartition}) testsize(${testsize})"
# count partitions
testpartitioncount=$(sudo fdisk -l | grep /dev/$testdevice | wc -l)
# do not count line with disk info
testpartitioncount=$((testpartitioncount-1))
testpartitioncount=0
if [ ${#testdevice} -gt 0 ]; then
testpartitioncount=$(sudo fdisk -l | grep /dev/$testdevice | wc -l)
# do not count line with disk info
testpartitioncount=$((testpartitioncount-1))
fi
#echo "# testpartitioncount($testpartitioncount)"
#echo "# testpartitioncount(${testpartitioncount})"
#echo "# OSPartition(${OSPartition})"
#echo "# hdd(${hdd})"
if [ $testpartitioncount -gt 0 ]; then
# if a partition was found - make sure to skip OS partition
if [ "$testpartition" != "$OSPartition" ]; then
# make sure to use the biggest
if [ ${testsize} -gt ${sizeDataPartition} ]; then
sizeDataPartition=${testsize}
@ -115,20 +123,26 @@ if [ "$1" = "status" ]; then
fi
fi
else
# make sure to use the biggest
# default hdd set, when there is no OSpartition and there might ne no partitions at all
if [ "${OSPartition}" = "root" ] && [ "${hdd}" = "" ] && [ "${testdevice}" != "" ]; then
hdd="${testdevice}"
fi
# make sure to use the biggest
if [ ${testsize} -gt ${sizeDataPartition} ]; then
# Partion to be created is smaller than disk so this is not correct (but close)
sizeDataPartition=$(sudo fdisk -l /dev/$testdevice | grep GiB | cut -d " " -f 5)
hddDataPartition="${testdevice}1"
hdd="${testdevice}"
fi
fi
fi
done < .lsblk.tmp
rm -f .lsblk.tmp 1>/dev/null 2>/dev/null
if [ ${#hddDataPartition} -lt 4 ]; then
echo "# WARNING: found invalid partition (${ddDataPartition}) - redacting"
if [ "${hddPartitionCandidate}" != "" ] && [ ${#hddDataPartition} -lt 4 ]; then
echo "# WARNING: found invalid partition (${hddDataPartition}) - redacting"
hddDataPartition=""
fi
@ -136,8 +150,12 @@ if [ "$1" = "status" ]; then
echo "isSSD=${isSSD}"
echo "hddCandidate='${hdd}'"
hddBytes=$(sudo fdisk -l /dev/$hdd | grep GiB | cut -d " " -f 5)
hddGigaBytes=$(echo "scale=0; ${hddBytes}/1024/1024/1024" | bc -l)
hddBytes=0
hddGigaBytes=0
if [ "${hdd}" != "" ]; then
hddBytes=$(sudo fdisk -l /dev/$hdd | grep GiB | cut -d " " -f 5)
hddGigaBytes=$(echo "scale=0; ${hddBytes}/1024/1024/1024" | bc -l)
fi
echo "hddBytes=${hddBytes}"
echo "hddGigaBytes=${hddGigaBytes}"
@ -317,7 +335,7 @@ if [ "$1" = "status" ]; then
do
devMounted=$(lsblk -o MOUNTPOINT,NAME | grep "$disk" | grep -c "^/")
# is raid candidate when not mounted and not the data drive cadidate (hdd/ssd)
if [ ${devMounted} -eq 0 ] && [ "${disk}" != "${hdd}" ]; then
if [ ${devMounted} -eq 0 ] && [ "${disk}" != "${hdd}" ] && [ "${hdd}" != "" ]; then
sizeBytes=$(lsblk -o NAME,SIZE -b | grep "^${disk}" | awk '$1=$1' | cut -d " " -f 2)
sizeGigaBytes=$(echo "scale=0; ${sizeBytes}/1024/1024/1024" | bc -l)
vedorname=$(lsblk -o NAME,VENDOR | grep "^${disk}" | awk '$1=$1' | cut -d " " -f 2)
@ -1155,7 +1173,7 @@ if [ "$1" = "tempmount" ]; then
sudo mkdir -p /mnt/temp 1>/dev/null
sudo mount -t btrfs -o degraded -o subvol=WORKINGDIR /dev/${hddBTRFS}1 /mnt/hdd
sudo mount -t btrfs -o subvol=WORKINGDIR /dev/${hddBTRFS}2 /mnt/storage
sudo mount -o uid=${bitcoinUID},gid=${bitcoinGID} /dev/${hddBTRFS}3 /mnt/temp
sudo mount -o umask=0000,uid=${bitcoinUID},gid=${bitcoinGID} /dev/${hddBTRFS}3 /mnt/temp
# check result
isMountedA=$(df | grep -c "/mnt/hdd")
@ -1288,7 +1306,9 @@ if [ "$1" = "link" ]; then
sudo chown -R bitcoin:bitcoin /mnt/hdd/app-storage
sudo chown -R bitcoin:bitcoin /mnt/hdd/app-data
sudo chown -R bitcoin:bitcoin /mnt/hdd/temp
sudo chmod -R 766 /mnt/hdd/temp
sudo chmod -R 777 /mnt/temp
sudo chmod -R 777 /mnt/hdd/temp
sudo chmod 777 /mnt
# write info files about what directories are for

View File

@ -252,6 +252,7 @@ if [ "$1" = "import" ]; then
sudo cp /mnt/hdd/backup_bitcoin/bitcoin.conf /mnt/hdd/bitcoin/bitcoin.conf
sudo cp /mnt/hdd/backup_bitcoin/wallet.dat /mnt/hdd/bitcoin/wallet.dat 2>/dev/null
sudo chown bitcoin:bitcoin -R /mnt/hdd/bitcoin
sudo chown bitcoin:bitcoin -R /mnt/storage/bitcoin 2>/dev/null
fi
if [ -d "/mnt/hdd/backup_litecoin" ]; then
echo "# Copying back litecoin backup data .."
@ -259,6 +260,7 @@ if [ "$1" = "import" ]; then
sudo cp /mnt/hdd/backup_litecoin/litecoin.conf /mnt/hdd/litecoin/litecoin.conf
sudo cp /mnt/hdd/backup_litecoin/wallet.dat /mnt/hdd/litecoin/wallet.dat 2>/dev/null
sudo chown bitcoin:bitcoin -R /mnt/hdd/litecoin
sudo chown bitcoin:bitcoin -R /mnt/storage/litecoin 2>/dev/null
fi
echo "# OK done - you may now want to:"
@ -293,8 +295,6 @@ if [ "$1" = "import-gui" ]; then
exit 1
fi
# ask format for new HDD/SSD
OPTIONS=()
# check if HDD/SSD contains Bitcoin Blockchain
@ -356,6 +356,9 @@ if [ "$1" = "import-gui" ]; then
exit 1
fi
# make sure all directories betare propper linked
sudo /home/admin/config.scripts/blitz.datadrive.sh link
# make sure that temp directory exists and can be written by admin
sudo mkdir -p ${defaultZipPath}
sudo chmod 777 -R ${defaultZipPath}
@ -383,14 +386,18 @@ if [ "$1" = "import-gui" ]; then
if [ ${countZips} -eq 0 ]; then
echo
echo "FAIL: Was not able to detect uploaded file in ${defaultZipPath}"
exit 0
echo "error='no file found'"
sleep 3
exit 1
fi
# in case of multiple files
if [ ${countZips} -gt 1 ]; then
echo
echo "FAIL: Multiple possible files detected in ${defaultZipPath}"
exit 0
echo "# FAIL: Multiple possible files detected in ${defaultZipPath}"
echo "error='multiple files'"
sleep 3
exit 1
fi
# restore upload
@ -399,7 +406,9 @@ if [ "$1" = "import-gui" ]; then
source <(sudo /home/admin/config.scripts/blitz.migration.sh "import")
if [ ${#error} -gt 0 ]; then
echo
echo "FAIL: Was not able to restore data --> ${error}"
echo "# FAIL: Was not able to restore data"
echo "error='${error}'"
sleep 3
exit 1
fi
@ -408,6 +417,8 @@ if [ "$1" = "import-gui" ]; then
if [ ${#network} -eq 0 ]; then
echo
echo "FAIL: No raspiblitz.conf found afer migration restore"
echo "error='migration contains no raspiblitz.conf'"
sleep 3
exit 1
fi