diff --git a/scripts/backup-database.sh b/scripts/backup-database.sh new file mode 100755 index 0000000..22c3aa5 --- /dev/null +++ b/scripts/backup-database.sh @@ -0,0 +1,50 @@ +#!/bin/bash +# LMDB Database backup utility + +DATABASE_PATH="${HOME}/printer_data/database" +MOONRAKER_ENV="${HOME}/moonraker-env" +OUPUT_FILE="${HOME}/database.backup" + +print_help() +{ + echo "Moonraker Database Backup Utility" + echo + echo "usage: backup-database.sh [-h] [-e ] [-d ] [-o ]" + echo + echo "optional arguments:" + echo " -h show this message" + echo " -e Moonraker Python Environment" + echo " -d Moonraker LMDB database to backup" + echo " -o backup file to save to" + exit 0 +} + +# Parse command line arguments +while getopts "he:d:o:" arg; do + case $arg in + h) print_help;; + e) MOONRAKER_ENV=$OPTARG;; + d) DATABASE_PATH=$OPTARG;; + o) OUPUT_FILE=$OPTARG;; + esac +done + +PYTHON_BIN="${MOONRAKER_ENV}/bin/python" +DB_TOOL="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/dbtool.py" + +if [ ! -f $PYTHON_BIN ]; then + echo "No Python binary found at '${PYTHON_BIN}'" + exit -1 +fi + +if [ ! -f "$DATABASE_PATH/data.mdb" ]; then + echo "No Moonraker database found at '${DATABASE_PATH}'" + exit -1 +fi + +if [ ! -f $DB_TOOL ]; then + echo "Unable to locate dbtool.py at '${DB_TOOL}'" + exit -1 +fi + +${PYTHON_BIN} ${DB_TOOL} backup ${DATABASE_PATH} ${OUPUT_FILE} diff --git a/scripts/restore-database.sh b/scripts/restore-database.sh new file mode 100755 index 0000000..32987aa --- /dev/null +++ b/scripts/restore-database.sh @@ -0,0 +1,55 @@ +#!/bin/bash +# LMDB Database restore utility + +DATABASE_PATH="${HOME}/printer_data/database" +MOONRAKER_ENV="${HOME}/moonraker-env" +INPUT_FILE="${HOME}/database.backup" + +print_help() +{ + echo "Moonraker Database Restore Utility" + echo + echo "usage: restore-database.sh [-h] [-e ] [-d ] [-i ]" + echo + echo "optional arguments:" + echo " -h show this message" + echo " -e Moonraker Python Environment" + echo " -d Moonraker LMDB database path to restore to" + echo " -i backup file to restore from" + exit 0 +} + +# Parse command line arguments +while getopts "he:d:i:" arg; do + case $arg in + h) print_help;; + e) MOONRAKER_ENV=$OPTARG;; + d) DATABASE_PATH=$OPTARG;; + i) INPUT_FILE=$OPTARG;; + esac +done + +PYTHON_BIN="${MOONRAKER_ENV}/bin/python" +DB_TOOL="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/dbtool.py" + +if [ ! -f $PYTHON_BIN ]; then + echo "No Python binary found at '${PYTHON_BIN}'" + exit -1 +fi + +if [ ! -d $DATABASE_PATH ]; then + echo "No database folder found at '${DATABASE_PATH}'" + exit -1 +fi + +if [ ! -f $INPUT_FILE ]; then + echo "No Database Backup File found at '${INPUT_FILE}'" + exit -1 +fi + +if [ ! -f $DB_TOOL ]; then + echo "Unable to locate dbtool.py at '${DB_TOOL}'" + exit -1 +fi + +${PYTHON_BIN} ${DB_TOOL} restore ${DATABASE_PATH} ${INPUT_FILE}