Difference between revisions of "Backup your database"

From MythTV Official Wiki
Jump to: navigation, search
m (mark outdated)
(Turned outdated page into redirect)
 
Line 1: Line 1:
{{Outdated2|MythTV 0.22 and later are released with official backup scripts to use rather than this guide. See [[Database Backup and Restore]].}}
+
#REDIRECT [[Database Backup and Restore]].
 
 
Before making any changes that may cause problems (such as upgrades), you should always back up your MythTV database.
 
 
 
__TOC__
 
 
 
== The <tt>mysqldump</tt> command ==
 
 
 
<pre>$ mysqldump -u <myth_user> -p --extended-insert --databases <myth_db_name> > mythdatabase.sql
 
Password: <myth_password></pre>
 
 
 
Be sure to replace <myth_user>, <myth_db_name>, and <myth_password> with the appropriate values.
 
 
 
The <tt>mysqldump</tt> command produces a text file that contains all of the MySQL commands necessary to recreate your database.  The syntax used here assumes you will delete the database and recreate it from scratch if you need to restore it.  In this case you probably will need to use the root MySQL user to do the restore because your <tt><myth_user></tt> userid may not have the necessary privileges in MySQL to create a new database.
 
 
 
The <tt>--extended-insert</tt> option causes <tt>mysqldump</tt> to generate multi-value INSERT commands inside the backup text file which results in the file being smaller and the restore running faster.
 
 
 
The command to restore the database using the backup file generated by <tt>mysqldump</tt> would be:
 
<pre>$ mysql -u <root_user> -p <mythdatabase.sql
 
Password: <root_password></pre>
 
 
 
If you get errors with this try using..
 
<pre>$mysql -u root -p mythconverg < mythdatabase.sql
 
Password: <password></pre>
 
 
 
Remember, the backup file is a text file and therefore can be compressed into a much smaller file.  If you plan to keep it around consider using something like gzip or bzip2 to save some major space.
 
 
 
Also, move the file some place safe if you are doing major surgery on your MythTV server.
 
 
 
== Utilities ==
 
You might also like to automate this activity on a daily Crontab schedule , otherwise you can use script utilities like : [http://sourceforge.net/projects/automysqlbackup/ automysqlbackup] to manage process. This particular script generates daily and monthly snapshots of your database.
 
 
 
== Issues ==
 
 
 
{|border=1 cellspacing=0
 
|'''Simon Kenyon <simon@koala.ie> posted the following to the mythtv-dev mailing list:'''
 
|-
 
|i thought i'd pass this on - because it took me a long time to diagnose what was going on.
 
 
 
some time ago i was having problems with my database, so i decided to dump in and then recreate it. all went fine and thing seemed to work. i kept having strange problems. i finally tracked it down to this:
 
 
 
for some versions of mysql, the mysqldump command would not save either the fact that a column was auto_increment, or the current value of the auto_increment variable.
 
 
 
so i had a database with no auto_increment attribute on some of the columns.
 
 
 
well i fixed it by dumping the database and then restoring it after editing the dump with the help of mythtv/libs/libmythtv/dbcheck.cpp
 
 
 
perhaps not the most elegant solution, but functional.
 
 
 
hope this helps somebody else in the future
 
<br />--
 
<br />simon
 
|}
 
 
 
[[Category:HOWTO]]
 
[[Category:MySQL]]
 

Latest revision as of 04:40, 9 April 2010

.