Skip to content

Instantly share code, notes, and snippets.

@a1300
Last active September 16, 2021 10:54
Show Gist options
  • Save a1300/4ca85df387100651ca6041f8d9f14c31 to your computer and use it in GitHub Desktop.
Save a1300/4ca85df387100651ca6041f8d9f14c31 to your computer and use it in GitHub Desktop.
upgrade mainnet
#!/bin/bash
##################
# backup current database
##################
sudo docker stop node1
sudo docker rm node1
sleep 15s
LAST_HEIGHT=$(sudo docker exec -it db1 psql -U postgres -d postgres -c "select max(height) from block" | sed -n 3p | sed 's/ //g;s/\t//g;s/\r//g;s/$//g')
echo "$LAST_HEIGHT"
BACKUP_DATE=$(date +%d-%m-%Y"_"%H_%M_%S)
# backup
sudo docker exec -t db1 pg_dumpall -c -U postgres > v2_height_${LAST_HEIGHT}_v1.0.80.sql
zip v2_height_${LAST_HEIGHT}_v1.0.80.zip v2_height_${LAST_HEIGHT}_v1.0.80.sql
#####################
# restore
#####################
sudo apt-get install zip unzip
wget https://mainnet.snapshots.gny.io/v2_height_1831668_16-09-2021_09_29_39.zip
unzip v2_height_1831668_16-09-2021_09_29_39.zip
sudo docker-compose --file docker-compose.yml down
sudo docker volume prune --force
sudo docker-compose --file docker-compose.yml pull
sudo docker-compose --file docker-compose.yml up --no-start
sudo docker-compose --file docker-compose.yml start db1
sleep 10s
cat v2_height_1831668_16-09-2021_09_29_39.sql | sudo docker exec -i db1 psql -U postgres
sudo docker-compose --file docker-compose.yml up --detach
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment