LoginSignup
20
15

More than 1 year has passed since last update.

symbol-bootstrap(暫定fast-sync)

Last updated at Posted at 2021-01-25

はじめに

symbol-bootstrapでtestnetのノードを最初から構築すると非常に時間がかかります。
(1日中やっても終わらない場合があります)

以下は、アーカイブしているデータからノードを構築するスクリプトです。
(いまのところtime4vpsのlinux8プランで大体1時間強くらいで完了します)

内容は、単純にtarget/databasesとtarget/nodes/node/dataの差し替えです。

そのうち本体側で実装されると思うので、あくまでもそれまでの暫定です。
https://github.com/nemtech/symbol-bootstrap/pull/115

本体側に実装されたら本記事は消します。

データについて

アーカイブは毎日4:00(JST)に作成しています。
ここから直接持って行って差し替えしても大丈夫と思います。

前提条件

スクリプト実行の前提は以下のとおり。

  • symbol-bootstrapでcomposeまで終わっていること

手順

手順は以下のとおり。

# targetがあるフォルダに移動
cd symbol-bootstrap
# fast-sync.shを保存、実行権付与
chmod +x fast-sync.sh
# 実行
./fast-sync.sh

以下はスクリプト(fast-sync.sh)

#!/bin/bash
#
# [USAGE]
#  fast-sync.sh [OPTION]... [TARGET]
#  -f     remove target/databases, target/nodes/node/data
#  -p     download data in parallel
#  -h     show usage
#
#  current directory is used for the target when no target argument specified.
#  
# [DESCRIPTION]
#  symbol-bootstrap fast sync tool(unofficial).
#  this tool run the following steps:ggVG
# 
# 1) symbol-bootstrap stop
#
# 2) recovery databases/data
#  https://symbol-archives.s3-ap-northeast-1.amazonaws.com/archives/mainnet.databases.tar.gz
#   -> $HOME/target/databases
#  https://symbol-archives.s3-ap-northeast-1.amazonaws.com/archives/mainnet.data.tar.gz
#   -> $HOME/target/nodes/node/data
#
# 3) symbol-bootstrap start -d
#
#
# [PREREQUISITES]
#  - before running this script, 
#   you need to setup symbol-bootstrap by symbol-bootstrap config & compose.
#
# [NOTE]
#  - tested in only linux as follows, it might not work in other environment.
#   CPU: 4 x 2.60 GHz
#   RAM: 16384 MB
#   Storage: 160 GB
#   Bandwidth: 16 TB
#   Port speed: 100 Mbps
#   Backups: Optional
#   Virtualization: KVM
#
# - this script removes the following directories,  
#   it might not work in your environment. if so,
#   please comment out rm statements.
#   target/databases
#   target/nodes/node/data
#
usage_exit() {
    cat <<EOF
Usage:  fast-sync.sh [OPTION]... [TARGET]
 -f, --force-clean     remove target/databases, target/nodes/node/data
 -p, --parallel        download data in parallel
 -h, --help            show usage

 current directory is used for the target when no target argument specified.
EOF
    exit 1
}

FORCE_CLEAN=0
PARALLEL_DL=0
while getopts fph OPT
do
    case $OPT in
    f)  FORCE_CLEAN=1
        ;;
    p)  PARALLEL_DL=1
        ;;
    h) usage_exit
        ;;
    \?) usage_exit
        ;;
    esac
done

shift $(($OPTIND - 1))
if [ $# -gt 0 ]; then
    BOOTSTRAP_HOME=$(cd $1 && pwd)
elif [ -z "$BOOTSTRAP_HOME" ]; then
    BOOTSTRAP_HOME=$(pwd)
fi
if [ ! -d "$BOOTSTRAP_HOME/target" ]; then
    echo "$BOOTSTRAP_HOME/target not found!"
    exit 1
fi
S3_URL=https://symbol-archives.s3-ap-northeast-1.amazonaws.com/archives
recover_data()
{
    echo "start recover data"
    cd $BOOTSTRAP_HOME/target/nodes/node/
    wget -O -  $S3_URL/mainnet.data.tar.gz | tar zxf -
    echo "end recover data"
}
recover_databases()
{
    echo "start recover database"
    cd $BOOTSTRAP_HOME/target
    wget -O -  $S3_URL/mainnet.databases.tar.gz | tar zxf -
    echo "end recover database"
}
date
cd $BOOTSTRAP_HOME
symbol-bootstrap stop
symbol-bootstrap stop

if [ "$FORCE_CLEAN" = 1 ]; then
    rm -rf $BOOTSTRAP_HOME/target/nodes/node/data
    rm -rf $BOOTSTRAP_HOME/target/databases
fi
if [ "$PARALLEL_DL" = 1 ]; then
    recover_data &
    recover_databases &
    wait
else
    recover_data
    recover_databases
fi 
cd $BOOTSTRAP_HOME
symbol-bootstrap run -d
date
20
15
11

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
15