Your Name il y a 3 ans
Parent
commit
1d9e9fddf5
4 fichiers modifiés avec 236 ajouts et 3 suppressions
  1. 2 1
      README.md
  2. 232 0
      backup/restore_backup.sh
  3. 1 1
      backup/upload_bootstrap.sh
  4. 1 1
      upload_mega.sh

+ 2 - 1
README.md

@@ -18,7 +18,8 @@ Script permettant :
 Script permettant:
 - Compression des fichiers blk*.dat et txleveldb en bootstrap.dat.tar.xz
 - Generation des fichiers de controle d'archive (md5sum)
--Upload des fichiers sur le serveur FTP
+- Upload des fichiers sur le serveur FTP
+- Upload des fichiers sur mega.io
 
 >./upload_bootstrap.sh
 

+ 232 - 0
backup/restore_backup.sh

@@ -0,0 +1,232 @@
+#!/bin/bash
+set -e
+version=4.4
+date=03/05/2021
+pixz_i=""
+pigz_i=""
+swap_was="0"
+ftp_i=0
+pv_i=0
+cifs_i=0
+retry_flag=0
+daemon_on=0
+
+echo -e "\e[97mOkcash Blockchain Restore Backup(FTP) v$version ($date)\e[0m"
+echo -e "wareck : wareck@gmail.com"
+echo -e ""
+bt_version="`curl -s http://wareck.free.fr/crypto/okcash/bootstrap_backup/bootstrap_v.txt | awk 'NR==1 {print$3;exit}'`"
+bt_parts="`curl -s http://wareck.free.fr/crypto/okcash/bootstrap_backup/bootstrap_v.txt | awk 'NR==2 {print$2; exit}'`"
+echo -e "Boostrap.dat file : $bt_version => $bt_parts parts"
+
+
+function init {
+if ps -ef | grep -v grep | grep okcashd >/dev/null
+then
+daemon_on=1
+echo -e "\n\e[93mStopping Okcashd :\e[0m"
+okcashd stop 2>/dev/null || true && sudo /etc/init.d/cron stop 2>/dev/null || true
+sleep 1
+if  ps -ef | grep -v grep | grep okcashd >/dev/null ; then killall -9 okcashd; fi
+sleep 1
+if [ -f /usr/local/bin/okcashd ];then sudo mv /usr/local/bin/okcashd /usr/local/bin/okcashd_old |true ;fi
+if  ps -ef | grep -v grep | grep okcashd >/dev/null ; then killall -9 okcashd; fi
+echo "Done."
+fi
+
+if [ "`systemctl is-active watchdog.service`" = "active" ]
+then
+echo -e "\n\e[93mStopping watchdog :\e[0m"
+sudo systemctl stop watchdog >/dev/null
+echo "Done."
+fi
+if [ -d /home/$USER/scripts/ledstatus/ ];then sudo python /home/$USER/scripts/ledstatus/led_off.py; fi
+if [ -f /var/swap ]
+then
+echo -e "\n\e[93mStopping Swap :\e[0m"
+sudo dphys-swapfile swapoff /var/swap
+sudo rm /var/swap
+swap_was="1"
+echo "Done."
+fi
+}
+
+function check_software_ {
+echo -e "\n\e[95mChecking Softwares :\e[0m"
+echo -e -n "Check PIXZ  installed  : "
+if ! [ -x "$(command -v pixz)" ]; then pixz_i="pixz" && echo -e "[\e[91m NO  \e[0m]"; else pixz_i="" && echo -e "[\e[92m YES \e[0m]"; fi
+echo -e -n "Check PIGZ  installed  : "
+if ! [ -x "$(command -v pigz)" ]; then pigz_i="pigz" && echo -e "[\e[91m NO  \e[0m]"; else pigz_i="" && echo -e "[\e[92m YES \e[0m]"; fi
+echo -e -n "Check PV    installed  : "
+if ! [ -x "$(command -v pv)" ]; then pv_i="pv" && echo -e "[\e[91m NO  \e[0m]"; else pv_i="" && echo -e "[\e[92m YES \e[0m]"; fi
+if ! [[ $pixz_i = "" || ! $pv_i = "" || ! $pigz_i = "" ]]
+then
+echo -e "\n\e[95mSoftwares update & install :\e[0m"
+sudo apt-get update
+sudo apt install $pixz_i $ftp_i $pv_i $lrzip_i $pigz_i $cifs_i -y
+check_software_
+fi
+echo -e "Done."
+}
+
+function freeze_on_ {
+NEW_FAN=5.0
+if [ -f /home/$USER/scripts/run-fan.py ]
+then
+echo -e "\n\e[95mEnable \e[38;5;196mF\e[38;5;202mr\e[38;5;208me\e[38;5;214me\e[38;5;220mz\e[38;5;226mi\e[38;5;227mn\e[38;5;229mg\e[0m \e[95m:\e[0m"
+sudo systemctl stop run-fan.service
+if ! [ -f /home/$USER/freeze.txt ]
+then
+if  grep "# Author: Andreas Spiess" /home/$USER/scripts/run-fan.py >/dev/null
+then
+grep -i "desiredTemp = " /home/$USER/scripts/run-fan.py |awk 'NR==1 {print$3;exit}' >/home/$USER/freeze.txt
+else
+grep -i "self.startTemperature = " /home/$USER/scripts/run-fan.py |awk 'NR==1 {print$3;exit}' >/home/$USER/freeze.txt
+fi
+fi
+OLD_FAN=`cat /home/$USER/freeze.txt| awk '{print $1}'`
+echo "Fan PWM value : $OLD_FAN => $NEW_FAN"
+if  grep "# Author: Andreas Spiess" ~/scripts/run-fan.py >/dev/null
+then
+sed -i -e "s/desiredTemp = "$OLD_FAN"/desiredTemp = "$NEW_FAN"/g" /home/$USER/scripts/run-fan.py
+else
+sed -i -e "s/self.startTemperature = "$OLD_FAN"/self.startTemperature = "$NEW_FAN"/g" /home/$USER/scripts/run-fan.py
+fi
+sudo systemctl restart run-fan.service
+echo -e "Done."
+sleep 1
+fi
+}
+
+function freeze_off_ {
+echo -e -n ""
+if [ -f /home/$USER/scripts/run-fan.py ]
+then
+echo -e "\n\e[95mDisable Freezing :\e[0m"
+OLD_FAN=`cat /home/$USER/freeze.txt| awk '{print $1}'`
+if  grep "# Author: Andreas Spiess" ~/scripts/run-fan.py >/dev/null
+then
+echo "Fan PWM value : $NEW_FAN => $OLD_FAN"
+else
+echo "Fan value: $NEW_FAN =>$OLD_FAN"
+fi
+sudo systemctl stop run-fan.service
+if  grep "# Author: Andreas Spiess" ~/scripts/run-fan.py >/dev/null
+then
+sed -i -e "s/desiredTemp = "$NEW_FAN"/desiredTemp = "$OLD_FAN"/g" /home/$USER/scripts/run-fan.py
+else
+sed -i -e "s/self.startTemperature = "$NEW_FAN"/self.startTemperature = "$OLD_FAN"/g" /home/$USER/scripts/run-fan.py
+fi
+sudo systemctl restart run-fan.service
+if [ -f /home/$USER/freeze.txt ];then rm /home/$USER/freeze.txt;fi
+echo -e "Done."
+fi
+}
+
+function end_restart {
+if [ -f /usr/local/bin/okcashd_old ]
+then
+sudo mv /usr/local/bin/okcashd_old /usr/local/bin/okcashd | true
+okcashd
+fi
+}
+
+function download_ {
+badsum=0
+sudo dphys-swapfile swapoff &> /dev/null
+if [ -f /var/swap ];then sudo rm /var/swap;fi
+echo -e "\n\e[95mDownload Bootstrap Files $bt_version => $bt_parts :\e[0m"
+folder="bootstrap_backup"
+cd /home/$USER/
+for i in `seq -w 01 $bt_parts`;
+do
+wget -c http://wareck.free.fr/crypto/okcash/$folder/bootstrap.part$i
+done
+for i in `seq -w 01 $bt_parts`;
+do
+wget -c http://wareck.free.fr/crypto/okcash/$folder/bootstrap$i.md5
+done
+
+echo -e "\n\e[95mBootstrap checksum test:\e[0m"
+for i in `seq -w 01 $bt_parts`;
+do
+echo -e -n "Bootstrap.part$i md5sum Test: " && if md5sum --status -c bootstrap$i.md5; then echo -e "[\e[92m OK \e[0m]"; else echo -e "[\e[91m NO \e[0m]" && badsum=1 ;fi
+if [ $badsum = "1" ]
+then
+echo -e "\e[38;5;166mBootstrap.tar.xz error !\e[0m"
+echo -e "\e[38;5;166mMaybe file damaged or not fully download\e[0m"
+echo -e "\e[38;5;166mRestart build_node to try again !\e[0m"
+exit
+fi
+done
+
+echo -e "\n\e[95mJoin bootstrap.tar.xz:\e[0m"
+if [ -f bootstrap.tar.xz ] ; then rm bootstrap.tar.xz ;fi
+mv bootstrap.part01 bootstrap.tar.xz
+echo "bootstrap.part01"
+list=$(ls bootstrap.part*)
+for i in ${list[@]}
+do
+cat "$i" >> bootstrap.tar.xz
+echo "$i"
+rm "$i"
+done
+rm bootstrap*.md5
+echo -e "Done."
+
+if [ -f ~/.okcash/blk0001.dat ]
+then
+echo -e "\n\e[95mClean old data before extract:\e[0m"
+rm -r -f ~/.okcash/blk0001.dat
+rm -r -f ~/.okcash/database
+rm -r -f ~/.okcash/txleveldb
+rm -r -f ~/.okcash/peers.dat
+rm -r -f ~/.okcash/smsg*
+rm -r -f okcashd.pid
+echo "Done."
+fi
+
+echo -e "\n\e[95mExtract bootstrap.tar.xz:\e[0m"
+tar xvfJ bootstrap.tar.xz
+rm bootstrap.tar.xz
+echo -e "Done."
+sudo dphys-swapfile setup &> /dev/null
+sudo dphys-swapfile swapon &> /dev/null
+}
+
+if  ps -ef | grep -v grep | grep okcashd >/dev/null
+then
+echo -e "\n\e[38;5;166mOKcash daemon is working => shutdown and restart during this process !...\e[0m"
+while true; do
+read -p "Do you want to start processing (y/n) ? " yn
+    case $yn in
+        [Yy]* ) init ; check_software_; freeze_on ; retry ; packit ; upload ; end_restart ; break;;
+        [Nn]* ) exit;;
+        * ) echo "Please answer yes or no.";;
+    esac
+done
+else
+init
+check_software_
+freeze_on_
+download_
+end_restart
+fi
+
+if [ swap_was = 1 ]
+then
+echo -e "\n\e[95mRestart Swap:\e[0m"
+sudo dphys-swapfile setup
+sudo dphys-swapfile swapon
+echo "Done."
+fi
+if [ -f /home/$USER/bootstrap_uploadpass ]; then rm /home/$USER/bootstrap_uploadpass;fi
+if [ $daemon_on = 1 ]
+then
+echo -e "\n\e[38;5;166mOKcash daemon is restarting ...\e[0m"
+if [ -f /usr/local/bin/okcashd_old ]
+then
+sudo mv /usr/local/bin/okcashd_old /usr/local/bin/okcashd | true
+fi
+fi
+echo ""
+

+ 1 - 1
upload_bootstrap.sh → backup/upload_bootstrap.sh

@@ -10,7 +10,7 @@ pv_i=0
 retry_flag=0
 daemon_on=0
 dfolder="bootstrap_backup"
-split_size=500
+split_size=250
 
 echo -e "\n\e[97mOkcash Blockchain Uploader v$version ($date)\e[0m"
 echo -e "FTP version (backup)"

+ 1 - 1
upload_mega.sh

@@ -130,7 +130,7 @@ echo -e "\n\e[95mPacking & Compressing Files :\e[0m"
 cd /home/$USER
 SIZE1=`du -sk /home/$USER/.okcash/blk0001.dat | cut -f 1`
 SIZE2=`du -sk /home/$USER/.okcash/txleveldb/ | cut -f 1`
-SIZE=$(($SIZE2+$SIZE1+1))
+SIZE=$(($SIZE2+$SIZE1-1024))
 echo -e "\e[97mTar & PiXz :\e[0m"
 tar cf - .okcash/txleveldb/* .okcash/blk0001.dat | pv -s ${SIZE}k | pixz  > bootstrap.tar.xz
 sleep 1