id,summary,reporter,owner,description,type,status,priority,milestone,component,version,severity,resolution,keywords,cc,mlocked 4760,Use a script for the database backup,sphery ,Isaac Richards,"The attached patch, mythtv-database_backup_using_script.patch , modifies the new automatic database backup functionality to invoke a script (potentially a distro-specific script) to create the database backup. It's primary purpose is to allow packagers to customize the database backup procedure and to remove the code in myth calling the externally-provided binaries, mysqldump and gzip. It also has the additional advantage of allowing users to perform database backups whenever desired (i.e. in startup/shutdown scripts, in a cron job, ...) in such a way that the automatically-created database backups are no different from the manually-created backups. The script path can be specified with the ""undocumented"" setting ""DatabaseBackupScript"" (default value gContext->GetShareDir() + ""database_mythconverg_backup.sh""). A matching script (gContext->GetShareDir() + ""database_mythconverg_restore.sh"") can be used by the user to restore the database from a backup created by database_mythconverg_backup.sh. If either script is customized by the packager, the other script should be tested to verify it works with the other. This way, any distribution-specific backup/restore parameters/techniques can be hidden within the scripts, yet the MythTV HOWTO can provide generic guidance on backing up and restoring the database. To prevent the user from having to configure the database within MythTV and within the database backup script, a temporary database information file is created with name=value pairs specifying dbHostName, dbPort, dbUserName, dbPassword, dbName, dbSchemaVer, dbBackupDirectory, and dbBackupFilename. The information file is written with only read by owner filesystem permissions and is deleted immediately after execution of the backup script. The database information file provides the dbBackupDirectory to ensure that the script can place the backup in the appropriate directory, i.e. as specified in the DB Backups storage group. The dbBackupFilename ""suggested"" filename is also provided for use by the script. Since it is impossible to force the script to use these values, Myth will check for the existence of a file in the dbBackupDirectory whose name begins with dbBackupFilename, perhaps with additional extensions--such as "".gz"". If any files matching the pattern are found, the filename will be returned to be used for the GUI messages; if the script uses some other directory or filename, the returned filename will be """", thus preventing GUI messages specifying the name of the backup file. To ensure this works, the script must provide a proper exit code. The backup script is executed with a single command-line argument providing the name of the temporary database information file. The restore script will provide ""--help"" output to help the user determine the appropriate command-line arguments to pass the script. Example scripts will be provided in the new programs/scripts directory (an initial backup script is in the separate patch, mythtv-database_backup_scripts.patch ) and will be installed to the sharedir. Packagers who customize the scripts are encouraged to create restore scripts using similar command-line arguments to those specified in the programs/scripts/database_mythconverg_restore.sh script to make usage of scripts easier. If you would like the scripts placed in a different location within the source distribution or at install, please let me know. Currently, only the database_mythconverg_backup.sh script is provided. I began it as a shell script thinking it would be relatively quick and simple, but the script grew ever more complex as I tried to make a relatively-secure script that could also be used for ""manual"" backups. The script has already grown large enough that it may make sense to rewrite it in Perl. Please let me know whether a sh-based or Perl-based script would be preferable. I plan to add code to allow rotation of backups and to allow the user to specify default values/configuration in a separate configuration file (especially useful for manual execution). The database_mythconverg_restore.sh script will provide full getopts support as well as attempt to parse configuration files to determine database configuration information. However, not knowing whether the devs would prefer a sh-based approach or a complete rewrite to Perl, I decided to upload what I had for review rather than write a bunch more code only to have to reimplement it later in another language. Once the appropriate script language is decided, I can finish both scripts rather quickly (though I won't have a chance to do much work on them until next weekend--around Mar 1). Most all of the ideas in here came from Daniel K., Rob S., and Stuart M. on IRC. I'll take responsibility for all the errors, oversights, and bad ideas, though. ",patch,closed,minor,unknown,mythtv,head,medium,fixed,,Rob Smith,0