From 5d5f53c8d8e3e0a9ab2ea02c7b1caa131964507a Mon Sep 17 00:00:00 2001 From: Roy Lee Date: Thu, 26 May 2022 21:16:30 -0700 Subject: [PATCH] [lbry] contrib: add a helper script for generating snapshots --- contrib/snapshot.sh | 63 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100755 contrib/snapshot.sh diff --git a/contrib/snapshot.sh b/contrib/snapshot.sh new file mode 100755 index 00000000..9b885514 --- /dev/null +++ b/contrib/snapshot.sh @@ -0,0 +1,63 @@ +#!/bin/sh + +read -r -d '' help << EOM +snapshot.sh - helper script for generating snapshot from lbcd's app dir. + +The default output name "lbcd_snapshot___.tar.zst" + +To extract the snapshot (data/mainter/): + + zstd -d lbcd_snapshot___.tar.zst | tar xf - -C + +Default appdir of lbcd on different OSes: + + Darwin) "\${HOME}/Library/Application Support/Lbcd" + Linux) "\${HOME}/.lbcd" + Windows) "%%LOCALAPPDATA%%/lbcd" + +Options: + + -h Display this message. + -d Specify APPDIR to copy the snapshot from. + + -o Specify the output filename of snapshot. + -b Specify the best block height of the snapshot. (ignored if -o is specified) + -l Specify git tag of the running lbcd. (ignored if -o is specified) + -t Specify the date when the snapshot is generated. (ignored if -o is specified) +EOM + +while getopts o:d:b:l:t:h flag +do + case "${flag}" in + h) printf "${help}\n\n"; exit 0;; + d) appdir=${OPTARG};; + + o) snapshot=${OPTARG};; + b) height=${OPTARG};; + l) lbcd_ver=${OPTARG};; + t) date=${OPTARG};; + esac +done + +if [ -z "$appdir" ]; then + case $(uname) in + Darwin) appdir="${HOME}/Library/Application Support/Lbcd" ;; + Linux) appdir="${HOME}/.lbcd" ;; + Windows) appdir="%LOCALAPPDATA%/lbcd" ;; + esac +fi + + +if [ -z ${snapshot} ]; then + git_repo=$(git rev-parse --show-toplevel) + [ -z "${height}" ] && height=$(go run ${git_repo}/claimtrie/cmd block best --showhash=false) + [ -z "${lbcd_ver}" ] && lbcd_ver=$(git describe --tags) + [ -z "${date}" ] && date=$(date +"%Y-%m-%d") + snapshot="lbcd_snapshot_${height}_${lbcd_ver}_${date}.tar.zst" +fi + + +echo "Generating $snapshot ..." + +tar c -C "${appdir}" data/mainnet | zstd -9 --no-progress -o "${snapshot}" +