The core protocol of WoopChain
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
woop/scripts/package/woop-rclone.sh

65 lines
1.4 KiB

#!/bin/bash
ME=$(basename "$0")
function usage() {
local MSG=$1
cat<<-EOT
$MSG
This script will rclone the woop db to datadir/archive directory.
Usage: $ME [options] datadir shard
datadir: the root directory of the woop db (default: /home/woop)
shard: the shard number to sync (valid value: 0,1,2,3)
Options:
-h print this help message
-c clean up backup db after rclone
-a sync archival db, instead of regular db
EOT
exit 1
}
CLEAN=false
FOLDER=mainnet.min
CONFIG=/etc/woop/rclone.conf
while getopts ":hca" opt; do
case $opt in
c) CLEAN=true ;;
a) FOLDER=mainnet.archival ;;
*) usage ;;
esac
done
shift $((OPTIND - 1))
if [ $# != 2 ]; then
usage
fi
DATADIR="$1"
SHARD="$2"
if [ ! -d "$DATADIR" ]; then
usage "ERROR: no datadir directory: $DATADIR"
fi
case "$SHARD" in
0|1|2|3) ;;
*) usage "ERROR: invalid shard number: $SHARD" ;;
esac
mkdir -p "${DATADIR}/archive"
rclone --config "${CONFIG}" sync -vvv "wiki:pub.wikiwoop.com/${FOLDER}/woop_db_${SHARD}" "${DATADIR}/archive/woop_db_${SHARD}" > "${DATADIR}/archive/archive-${SHARD}.log" 2>&1
[ -d "${DATADIR}/woop_db_${SHARD}" ] && mv -f "${DATADIR}/woop_db_${SHARD}" "${DATADIR}/archive/woop_db_${SHARD}.bak"
mv -f "${DATADIR}/archive/woop_db_${SHARD}" "${DATADIR}/woop_db_${SHARD}"
if $CLEAN; then
rm -rf "${DATADIR}/archive/woop_db_${SHARD}.bak"
fi