Files
purple-explorer/scripts/restore_backup.sh
T
joeuhren be1205d90a Add masternodes page/feature
-Added a new "Masternodes" page which displays the current list of masternodes on the network
-/api/getmasternodelist is no longer publicly accessible and has been replaced by /ext/getmasternodelist which returns the masternode list from local collection instead of directly from wallet
-Added new masternode sync options to sync.js and sync.sh
-Added new masternodes_last_updated field to the Stats collection
-Updated delete_database.sh and restore_backup.sh to include support for the new masternodes collection
-Network header menu icon changed to allow the new Masternodes menu item to use the old network icon
2020-12-30 18:22:02 -07:00

71 lines
2.0 KiB
Bash
Executable File

#!/bin/bash
ARCHIVE_SUFFIX=".tar.gz"
# Check if a backup file was specified
if [ -n "${1}" ]; then
BACKUP_PATH="${1}"
# Check if the backup file exists as a full path
if [ ! -f "${BACKUP_PATH}" ]; then
# Check if the backup is valid by adding the archive suffix
if [ -f "${BACKUP_PATH}${ARCHIVE_SUFFIX}" ]; then
# The backup file is valid after adding the archive suffix
BACKUP_PATH="${BACKUP_PATH}${ARCHIVE_SUFFIX}"
else
# Prepend the default backup path
BACKUP_PATH="$(dirname $(dirname $(readlink -f "$0")))/backups/${BACKUP_PATH}"
fi
fi
# Check for the backup file (again)
if [ ! -f "${BACKUP_PATH}" ]; then
# Append the default archive suffix
BACKUP_PATH="${BACKUP_PATH}${ARCHIVE_SUFFIX}"
fi
# Check for the backup file (last time)
if [ -f "${BACKUP_PATH}" ]; then
# Extract the backup archive
DIR_NAME=$(dirname "${BACKUP_PATH}")
tar -zxvf "${BACKUP_PATH}" -C "${DIR_NAME}"
# Check if this is a valid backup archive now that the files have been extracted
if [ -d ${BACKUP_PATH%"${ARCHIVE_SUFFIX}"}/explorerdb ]; then
BACKUP_DIR=${BACKUP_PATH%"${ARCHIVE_SUFFIX}"}
# Erase entire database
sudo mongo <<EOF
use explorerdb
db.addresses.remove({})
db.addresses.drop()
db.addresstxes.remove({})
db.addresstxes.drop()
db.coinstats.remove({})
db.coinstats.drop()
db.heavies.remove({})
db.heavies.drop()
db.markets.remove({})
db.markets.drop()
db.masternodes.remove({})
db.masternodes.drop()
db.peers.remove({})
db.peers.drop()
db.richlists.remove({})
db.richlists.drop()
db.txes.remove({})
db.txes.drop()
exit
EOF
# Restore mongo database from the backup directory
eval "mongorestore -d explorerdb ${BACKUP_DIR}/explorerdb"
# Remove the backup directory
rm -rf "${BACKUP_DIR}"
# Finished msg
echo "Backup restored from ${BACKUP_PATH} successfully."
else
# Backup file is not a valid mongo database backup
echo "${BACKUP_PATH} is not a valid backup file."
fi
else
# Backup does not exist
echo "${BACKUP_PATH} cannot be found."
fi
else
echo "no backup file specified."
fi