github.com/lbryio/lbcd@v0.22.119/contrib/snapshot.sh (about)

     1  #!/bin/sh
     2  
     3  read -r -d '' help << EOM
     4  snapshot.sh - helper script for generating snapshot from lbcd's app dir.
     5  
     6  The default output name "lbcd_snapshot_<height>_<lbcd_ver>_<date>.tar.zst"
     7  
     8  To extract the snapshot (data/mainter/):
     9  
    10      zstd -d lbcd_snapshot_<height>_<lbcd_ver>_<date>.tar.zst | tar xf - -C <appdir>
    11  
    12  Default appdir of lbcd on different OSes:
    13  
    14          Darwin)  "\${HOME}/Library/Application Support/Lbcd"
    15          Linux)   "\${HOME}/.lbcd"
    16          Windows) "%%LOCALAPPDATA%%/lbcd"
    17  
    18  Options:
    19  
    20      -h Display this message.
    21      -d Specify APPDIR to copy the snapshot from.
    22  
    23      -o Specify the output filename of snapshot.
    24      -b Specify the best block height of the snapshot. (ignored if -o is specified)
    25      -l Specify git tag of the running lbcd. (ignored if -o is specified)
    26      -t Specify the date when the snapshot is generated. (ignored if -o is specified)
    27  EOM
    28  
    29  while getopts o:d:b:l:t:h flag
    30  do
    31      case "${flag}" in
    32  	h) printf "${help}\n\n"; exit 0;;
    33          d) appdir=${OPTARG};;
    34  
    35          o) snapshot=${OPTARG};;
    36          b) height=${OPTARG};;
    37          l) lbcd_ver=${OPTARG};;
    38          t) date=${OPTARG};;
    39      esac
    40  done
    41  
    42  if [ -z "$appdir" ]; then
    43      case $(uname) in
    44          Darwin)  appdir="${HOME}/Library/Application Support/Lbcd" ;;
    45          Linux)   appdir="${HOME}/.lbcd" ;;
    46          Windows) appdir="%LOCALAPPDATA%/lbcd" ;;
    47      esac
    48  fi
    49  
    50  
    51  if [ -z ${snapshot} ]; then
    52      git_repo=$(git rev-parse --show-toplevel)
    53      [ -z "${height}" ] && height=$(go run ${git_repo}/claimtrie/cmd block best --showhash=false)
    54      [ -z "${lbcd_ver}" ] && lbcd_ver=$(git describe --tags)
    55      [ -z "${date}" ] && date=$(date  +"%Y-%m-%d")
    56      snapshot="lbcd_snapshot_${height}_${lbcd_ver}_${date}.tar.zst"
    57  fi
    58  
    59  
    60  echo "Generating $snapshot ..."
    61  
    62  tar c -C "${appdir}" data/mainnet | zstd -9 --no-progress -o "${snapshot}"
    63