Index: programs/programs.pro
===================================================================
--- programs/programs.pro (revision 16199)
+++ programs/programs.pro (working copy)
@@ -11,7 +11,7 @@
}
using_backend {
- SUBDIRS += mythbackend mythfilldatabase mythtv-setup
+ SUBDIRS += mythbackend mythfilldatabase mythtv-setup scripts
}
using_frontend:using_backend {
Index: programs/scripts/backup/database_mythconverg_backup.sh
===================================================================
--- programs/scripts/backup/database_mythconverg_backup.sh (revision 0)
+++ programs/scripts/backup/database_mythconverg_backup.sh (revision 0)
@@ -0,0 +1,409 @@
+#!/bin/sh
+#
+# database_mythconverg_backup.sh
+#
+# Creates a backup of the MythTV database.
+#
+# Usage:
+# database_mythconverg_backup.sh database_information_file
+#
+# This script will be called by mythbackend to create a backup of the MythTV
+# database. It will be passed a single command-line argument that provides the
+# name of a file that contains database configuration information. The
+# database_information_file will contain name=value pairs specifying the
+# following information:
+#
+# DBHostName - The hostname on which the MySQL server is running
+# DBPort - The TCP/IP port number to use for the connection. This may have a
+# value of 0, i.e. if the hostname is localhost or if the server is
+# using the default MySQL port.
+# DBUserName - The database username to use when connecting to the server.
+# DBPassword - The password to use when connecting to the server.
+# DBName - The name of the database that contains the MythTV data.
+# DBSchemaVer - The MythTV schema version of the database
+# DBBackupDirectory - The directory in which the backup file should be
+# created. This directory may have been specially
+# configured by the user as the "DB Backups" storage
+# group. It is recommended that this directory be
+# used--especially in "common-use" scripts such as those
+# provided by distributions.
+# DBBackupFilename - The name of the file in which the backup should be
+# created. Additional extensions may be added as desired
+# (i.e. adding ".gz" to the file if it's compressed). If
+# this file is used, it will be displayed in the GUI
+# messages provided for the user. If the file is not
+# used, the user will not be told where to find the backup
+# file.
+#
+# This script relies on the program mysqldump to create the database backup,
+# awk to parse the database information file, sed to create a "defaults extra
+# file" to provide the password to the database, and mktemp to securely create
+# temporary files used to provide a password for mysqldump. If sed is not
+# available, the database password will be echo'ed to create the password file.
+# Since echo is probably a shell builtin, it probably won't appear in process
+# lists, but even if it does, it is not a long-running process. If mktemp is
+# not found, the password file will not be created, but the backup will be
+# attempted anyway. In this situation, adding a line "password=DBPassword" to
+# the "[client]" and/or "[mysqldump]" section of the MySQL options file will
+# allow the backup to succeed. If available, gzip will be used to compress the
+# database backup.
+#
+# The script may also be called without arguments, i.e. manually or from a cron
+# job, to create a backup. It will attempt to parse the MySQL configuration
+# files to determine the database information. If this is unsuccessful, simply
+# providing a database information file in the format described above will
+# allow the script to function properly.
+#
+# When customizing this script, you should ensure that the script's exit status
+# reflects the results of the backup. If the backup was successful, the script
+# should return 0. Any non-zero value is considered an error.
+#
+
+# Specify the location of required programs
+AWK='awk'
+GZIP='gzip'
+MKTEMP='mktemp'
+MYSQLDUMP='mysqldump'
+SED='sed'
+
+# Clean up temporary files, if they were created.
+do_exit()
+{
+ if [ "x${DEFAULTS_EXTRA_FILE}" != "x" ]; then
+ if [ -f ${DEFAULTS_EXTRA_FILE} ]; then
+ rm -f ${DEFAULTS_EXTRA_FILE}
+ fi
+ fi
+ if [ "x${TEMPORARY_DB_INFO_FILE}" != "x" ]; then
+ if [ -f ${TEMPORARY_DB_INFO_FILE} ]; then
+ rm -f ${TEMPORARY_DB_INFO_FILE}
+ fi
+ fi
+}
+
+# Initialize the database information variables
+# Allows the user to pass in data using environment variables for those values
+# not specified in the database information file/configuration file (which will
+# be used in preference to the values in the environment).
+init_database_information ()
+{
+ if [ "x${DBHostName}" = "x" ]; then
+ DBHostName="UNDEF"
+ fi
+ if [ "x${DBPort}" = "x" ]; then
+ DBPort=-1
+ fi
+ if [ "x${DBUserName}" = "x" ]; then
+ DBUserName="UNDEF"
+ fi
+ if [ "x${DBPassword}" = "x" ]; then
+ DBPassword="UNDEF"
+ fi
+ if [ "x${DBName}" = "x" ]; then
+ DBName="UNDEF"
+ fi
+ if [ "x${DBSchemaVer}" = "x" ]; then
+ DBSchemaVer="UNDEF"
+ fi
+ if [ "x${DBBackupDirectory}" = "x" ]; then
+ DBBackupDirectory="UNDEF"
+ fi
+ if [ "x${DBBackupFilename}" = "x" ]; then
+ DBBackupFilename="UNDEF"
+ fi
+}
+
+# Read the database information file.
+# Rather than just source the file, parse it and look for the expected database
+# configuration information so we don't execute any commands in the file.
+read_database_information_file()
+{
+ if [ ${#} -lt 1 ]; then
+ echo "Usage: read_database_information_file database_information_file"
+ return 2
+ fi
+ DB_INFO_FILE=${1}
+ if [ "x${DB_INFO_FILE}" = "x" ]; then
+ return 2
+ fi
+ if [ ${#} -eq 2 ]; then
+ QUIET=${2}
+ fi
+ if [ ! -r ${DB_INFO_FILE} ]; then
+ if [ "x${QUIET}" = "x" ]; then
+ echo "${DB_INFO_FILE} does not exist or is not readable."
+ fi
+ return 4
+ fi
+ OLD_IFS=${IFS}
+ IFS=$'\n'
+ VALUES=(`${AWK} 'BEGIN {FS="="; DBHostName=DBPort=DBUserName=DBPassword=\
+ DBName=DBSchemaVer=DBBackupDirectory=\
+ DBBackupFilename="UNDEF"} \
+ /DBHostName/ {DBHostName=$2}; /DBPort/ {DBPort=$2}; \
+ /DBUserName/ {DBUserName=$2}; \
+ /DBPassword/ {DBPassword=$2}; \
+ /DBName/ {DBName=$2}; /DBSchemaVer/ {DBSchemaVer=$2}; \
+ /DBBackupDirectory/ {DBBackupDirectory=$2}; \
+ /DBBackupFilename/ {DBBackupFilename=$2}; \
+ END {printf "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n", \
+ DBHostName, DBPort, DBUserName, DBPassword, \
+ DBName, DBSchemaVer, \
+ DBBackupDirectory, DBBackupFilename}' \
+ "${DB_INFO_FILE}"`)
+ if [ "x${VALUES[0]}" != "xUNDEF" ]; then
+ DBHostName=${VALUES[0]}
+ fi
+ if [ "x${VALUES[1]}" != "xUNDEF" ]; then
+ DBPort=${VALUES[1]}
+ fi
+ if [ "x${VALUES[2]}" != "xUNDEF" ]; then
+ DBUserName=${VALUES[2]}
+ fi
+ if [ "x${VALUES[3]}" != "xUNDEF" ]; then
+ DBPassword=${VALUES[3]}
+ fi
+ if [ "x${VALUES[4]}" != "xUNDEF" ]; then
+ DBName=${VALUES[4]}
+ fi
+ if [ "x${VALUES[5]}" != "xUNDEF" ]; then
+ DBSchemaVer=${VALUES[5]}
+ fi
+ if [ "x${VALUES[6]}" != "xUNDEF" ]; then
+ DBBackupDirectory=${VALUES[6]}
+ fi
+ if [ "x${VALUES[7]}" != "xUNDEF" ]; then
+ DBBackupFilename=${VALUES[7]}
+ fi
+ IFS=${OLD_IFS}
+ return 0
+}
+
+# Attempt to find database information in the MythTV config file(s)
+# This is only used for "manual" execution of the backup script. The backend
+# will always provide a database information file, which will be used in
+# preference to any other configuration files.
+#
+# Though we could use a hack to pull the database configuration info from the
+# MythTV Perl bindings, the bindings require the backend to be running, so that
+# approach would not be appropriate for a backup/restore script.
+read_myth_config_file()
+{
+ if [ "x${MYTHCONFDIR}" = "x" -a "x${HOME}" != "x" ]; then
+ MYTHCONFDIR=${HOME}/.mythtv
+ fi
+ if [ ! -d ${MYTHCONFDIR} ]; then
+ unset MYTHCONFDIR
+ fi
+ # Prefer the config.xml/UPnP configuration
+ DATABASE_INFORMATION_FILE=`${MKTEMP}`
+ status=${?}
+ TEMPORARY_DB_INFO_FILE="${DATABASE_INFORMATION_FILE}"
+ if [ ${status} -eq 0 ]; then
+ if [ -r "${MYTHCONFDIR}/config.xml" ]; then
+ # Parse the config.xml with a quick regexp hack. Since this is not
+ # a full-fledged (or even half-fledged) XML parser, the parsing
+ # could easily be broken by someone hacking their copy of the
+ # config.xml file (i.e. having start and end tags on different
+ # lines, etc.).
+ ${SED} -n \
+ -e 's|^.*\(.\+\).*$|DBHostName=\1| p;' \
+ -e 's|^.*\(.\+\).*$|DBUserName=\1| p;' \
+ -e 's|^.*\(.\+\).*$|DBPassword=\1| p;' \
+ -e 's|^.*\(.\+\).*$|DBName=\1| p;' \
+ -e 's|^.*\(.\+\).*$|DBPort=\1| p;' \
+ "${MYTHCONFDIR}/config.xml" \
+ > "${DATABASE_INFORMATION_FILE}" 2>/dev/null
+ status=${?}
+ if [ ${status} -eq 0 ]; then
+ read_database_information_file "${DATABASE_INFORMATION_FILE}" \
+ "quiet"
+ status=${?}
+ if [ ${status} -eq 0 ]; then
+ return 0
+ fi
+ fi
+ fi
+ fi
+ # Since the config.xml file didn't provide the information, try looking for
+ # a mysql.txt file.
+ unset MYSQL_TEXT_FILE
+ if [ "x{MYTHCONFDIR}" != "x" ]; then
+ MYSQL_TEXT_FILE="${MYTHCONFDIR}/mysql.txt"
+ fi
+ loopstatus=2
+ for file in /usr/{,local/}{share,etc}/mythtv/mysql.txt \
+ "${MYSQL_TEXT_FILE}" ; do
+ read_database_information_file "${file}" "quiet"
+ status=${?}
+ if [ ${status} -eq 0 ]; then
+ loopstatus=0
+ DATABASE_INFORMATION_FILE="${file}"
+ fi
+ done
+ if [ ${loopstatus} -ne 0 ]; then
+ echo "Unable to parse database information file."
+ return ${loopstatus}
+ fi
+ return 0
+}
+
+# Check DBUserName, DBPassword, and DBName and use defaults, if undefined.
+check_database_information()
+{
+ if [ "x${DBUserName}" != "xUNDEF" ]; then
+ DBUserName=mythtv
+ fi
+ if [ "x${DBPassword}" != "xUNDEF" ]; then
+ DBPassword=mythtv
+ fi
+ if [ "x${DBName}" = "xUNDEF" ]; then
+ DBName=mythconverg
+ fi
+}
+
+check_backup_location()
+{
+ if [ "x${DBBackupDirectory}" = "xUNDEF" ]; then
+ if [ "x${MYTHCONFDIR}" != "x" ]; then
+ DBBackupDirectory="${MYTHCONFDIR}/backup"
+ if [ ! -d ${DBBackupDirectory} ]; then
+ if [ -e ${DBBackupDirectory} ]; then
+ DBBackupDirectory=/tmp
+ else
+ mkdir -p ${DBBackupDirectory}
+ fi
+ fi
+ fi
+ if [ ! -d ${DBBackupDirectory} -o ! -w ${DBBackupDirectory} ]; then
+ DBBackupDirectory=/tmp
+ fi
+ fi
+ if [ "x${DBBackupFilename}" = "xUNDEF" ]; then
+ if [ "x${DBSchemaVer}" != "xUNDEF" ]; then
+ SCHEMA_PART="-${DBSchemaVer}"
+ fi
+ DBBackupFilename="${DBName}${SCHEMA_PART}-`date +'%Y%m%d%H%M%S'`.sql"
+ fi
+
+ if [ ! -d ${DBBackupDirectory} ]; then
+ echo "${DBBackupDirectory} does not exist or is not a directory."
+ return 8
+ elif [ ! -w ${DBBackupDirectory} ]; then
+ echo "${DBBackupDirectory} is not writable."
+ return 16
+ fi
+ if [ -f "${DBBackupDirectory}/${DBBackupFilename}" ]; then
+ # Exit if the file exists rather than overwrite the file.
+ echo "${DBBackupDirectory}/${DBBackupFilename} already exists."
+ # To allow overwriting a file, uncomment the following lines of code.
+ # Note that doing so could be a serious security issue, especially if
+ # running mythbackend as root.
+# if [ ! -w "${DBBackupDirectory}/${DBBackupFilename}" ]; then
+# echo "${DBBackupDirectory}/${DBBackupFilename} already exists"\
+# "and is not writable."
+ return 32
+# fi
+ fi
+
+}
+
+# Create a temporary file to provide a password for mysqldump
+create_defaults_extra_file()
+{
+ DEFAULTS_EXTRA_FILE=`${MKTEMP}` || return 1
+ if [ "x${DATABASE_INFORMATION_FILE}" != "x" -a \
+ "x${DEFAULTS_EXTRA_FILE}" != "x" ]; then
+ # Rather than call echo with a command-line argument containing the
+ # password, use sed to read/transform the ${DATABASE_INFORMATION_FILE}
+ # contents to a ${DEFAULTS_EXTRA_FILE}
+ ${SED} -n -e 's/^DBPassword=\(.\+\)/[client]\npassword=\1\n[mysqldump]\npassword=\1/ p' "${DATABASE_INFORMATION_FILE}" > "${DEFAULTS_EXTRA_FILE}" 2>/dev/null
+ status=${?}
+ if [ ${status} -eq 0 ]; then
+ return 0
+ fi
+ fi
+ # Give up on a "secure" approach and just echo the info. Chances are echo
+ # will be a shell builtin, so it won't make it to the process list, anyway.
+ > ${DEFAULTS_EXTRA_FILE}
+ echo "[client]" >> ${DEFAULTS_EXTRA_FILE}
+ echo "password=${DBPassword}" >> ${DEFAULTS_EXTRA_FILE}
+ echo "[mysqldump]" >> ${DEFAULTS_EXTRA_FILE}
+ echo "password=${DBPassword}" >> ${DEFAULTS_EXTRA_FILE}
+ return 0
+}
+
+# Print a usage message
+usage()
+{
+ echo "Usage: ${0} [database_information_file]"
+}
+
+unset DEFAULTS_EXTRA_FILE
+unset TEMPORARY_DB_INFO_FILE
+
+init_database_information
+
+if [ ${#} -gt 1 ]; then
+ usage
+ do_exit 1
+elif [ ${#} -eq 1 ]; then
+ if [ "x${1}" = "x--help" ]; then
+ usage
+ do_exit 0
+ else
+ DATABASE_INFORMATION_FILE="${1}"
+ read_database_information_file "${DATABASE_INFORMATION_FILE}"
+ status=${?}
+ if [ ${status} -ne 0 ]; then
+ echo "Unable to parse database information file."
+ do_exit ${status}
+ fi
+ fi
+else
+ read_myth_config_file
+ status=${?}
+ if [ ${status} -ne 0 ]; then
+ echo "Unable to parse MythTV configuration files."
+ do_exit ${status}
+ fi
+fi
+
+check_database_information
+
+check_backup_location
+status=${?}
+if [ ${status} -ne 0 ]; then
+ do_exit ${status}
+fi
+
+unset DEFAULTS_FILE_ARG
+create_defaults_extra_file
+if [ ${?} -eq 0 ]; then
+ DEFAULTS_FILE_ARG="--defaults-extra-file=${DEFAULTS_EXTRA_FILE} "
+fi
+
+unset HOST_ARG
+if [ "x${DBHostName}" != "xUNDEF" ]; then
+ HOST_ARG=" --host=${DBHostName}"
+fi
+unset PORT_ARG
+if [ ${DBPort} -gt 0 ]; then
+ PORT_ARG=" --port=${DBPort}"
+fi
+
+${MYSQLDUMP} ${DEFAULTS_FILE_ARG}${HOST_ARG}${PORT_ARG} \
+ --user="${DBUserName}" --add-drop-table --add-locks \
+ --allow-keywords --complete-insert --extended-insert \
+ --lock-tables --no-create-db --quick \
+ "${DBName}" > "${DBBackupDirectory}/${DBBackupFilename}" 2>/dev/null
+status=${?}
+
+if [ ${status} -eq 0 -a \
+ -e "${DBBackupDirectory}/${DBBackupFilename}" -a \
+ ! -e "${DBBackupDirectory}/${DBBackupFilename}.gz" ]
+then
+ ${GZIP} "${DBBackupDirectory}/${DBBackupFilename}"
+fi
+
+do_exit ${status}
Property changes on: programs/scripts/backup/database_mythconverg_backup.sh
___________________________________________________________________
Name: svn:executable
+ *
Index: programs/scripts/scripts.pro
===================================================================
--- programs/scripts/scripts.pro (revision 0)
+++ programs/scripts/scripts.pro (revision 0)
@@ -0,0 +1,14 @@
+include ( ../../config.mak )
+include ( ../../settings.pro )
+
+QMAKE_STRIP = echo
+
+TEMPLATE = app
+CONFIG -= moc qt
+
+installscripts.path = $${PREFIX}/share/mythtv
+installscripts.files = backup/*
+
+INSTALLS += installscripts
+
+SOURCES += dummy.c
Index: programs/scripts/dummy.c
===================================================================
--- programs/scripts/dummy.c (revision 0)
+++ programs/scripts/dummy.c (revision 0)
@@ -0,0 +1,4 @@
+int main(void)
+{
+ return 0;
+}