mirror of
https://github.com/EDCD/EDDN.git
synced 2025-04-12 07:00:04 +03:00
scripts/eddn-restore-db-data: Handles if file is .gz or not
This commit is contained in:
parent
78edcffa6b
commit
080136127e
59
scripts/eddn-restore-db-data
Executable file
59
scripts/eddn-restore-db-data
Executable file
@ -0,0 +1,59 @@
|
||||
#!/bin/bash
|
||||
# Add ' -x' above to debug
|
||||
#
|
||||
# Use a dump to replace data in the given environment's database
|
||||
|
||||
###########################################################################
|
||||
# Exit codes
|
||||
###########################################################################
|
||||
EXIT_CONFIG_MISSING=1
|
||||
EXIT_CL_ARGS=3
|
||||
###########################################################################
|
||||
|
||||
###########################################################################
|
||||
# Functions
|
||||
###########################################################################
|
||||
##################################################
|
||||
# Print usage information
|
||||
##################################################
|
||||
usage() {
|
||||
echo "Usage: $(basename $0) ( live | beta | dev ) <dump file name>" >&2
|
||||
}
|
||||
##################################################
|
||||
###########################################################################
|
||||
|
||||
if [ -z "${1}" ];
|
||||
then
|
||||
usage
|
||||
echo "No EDDN environment specified." >&2
|
||||
exit ${EXIT_CL_ARGS}
|
||||
fi
|
||||
EDDN_ENV="${1}"
|
||||
|
||||
if [ -z "${2}" ];
|
||||
then
|
||||
usage
|
||||
echo "No database dump file name specified." >&2
|
||||
exit ${EXIT_CL_ARGS}
|
||||
fi
|
||||
DBDUMP_FILE="${2}"
|
||||
|
||||
# Bring in some common configuration
|
||||
if [ ! -f "${HOME}/.local/bin/eddn_${EDDN_ENV}_config" ];
|
||||
then
|
||||
echo "eddn_${EDDN_ENV}_config is missing from $(pwd)" >&2
|
||||
exit ${EXIT_CONFIG_MISSING}
|
||||
fi
|
||||
. "${HOME}/.local/bin/eddn_${EDDN_ENV}_config"
|
||||
|
||||
|
||||
# This relies on ~/.my.cnf containing the password
|
||||
if [ "$(basename ${DBDUMP_FILE})" != "$(basename ${DBDUMP_FILE} .gz)" ];
|
||||
then
|
||||
gunzip -c - < "${DBDUMP_FILE}" | mysql -u eddn "eddn_${EDDN_ENV}"
|
||||
else
|
||||
mysql -u eddn "eddn_${EDDN_ENV}" < "${DBDUMP_FILE}"
|
||||
fi
|
||||
|
||||
# vim: tabstop=2 shiftwidth=2 textwidth=0 wrapmargin=0 expandtab
|
||||
|
Loading…
x
Reference in New Issue
Block a user