Restore/Synchronize Database
Version 3.1.8
- MediaMonkey Add-on -

by Zvezdan Dimitrijević
This add-on works with MediaMonkey v3.0-4.x. It could restore or synchronize (merge) the following data from/to some external (backup) database file:
- playing history (the Played table and Playcount + LastTimePlayed fields in the Songs table),
- playlists (auto-playlists and/or static ones in Playlists and PlaylistSongs tables),
- filters [MM3 db] / collections [MM4 db] and views (Filters, Views and NodeViews tables), and/or
- specified fields from the Songs table (e.g. Artist, Title or DateAdded field, however for some fields some another tables would be updated as well, e.g. Genres and GenresSongs if you specify Genre for restore).

This add-on could restore/synchronize data for all tracks in the current database or just filtered or selected ones. It could import/export data even from/to the backup file which is not a copy of the current database, i.e. the current database could be created from the ground after the last backup, as soon as they contain matched tracks.

If you have an adequate backup file, this add-on could be used as Undo tool as well. Let say that you have edited some tag/field in bunch of tracks and after that you have changed your mind. Nothing to worry: just select files that are affected, specify which tags you want to restore and the add-on will import that data from the specified backup file into the current database. Also, this add-on could transfer data from corrupted databases into the new, fresh ones in most cases.

If you want to discus about this add-on, you could visit its related MediaMonkey forum thread.

You could also take a look on my other add-ons for MediaMonkey.

What is new

v3.1.8 - 2019-11-22

v3.1.7 - 2017-07-16

v3.1.6 - 2016-12-22

v3.1.3 - 2015-06-22

v3.1.2 - 2013-08-31

v3.1.1 - 2012-05-31

v3.1 - 2012-04-04

v3.0.2 - 2012-01-25

v3.0.1 - 2012-01-12

v3.0 - 2012-01-09

v2.1.3 - 2011-12-09

v2.1.2 - 2011-11-15

v2.1.1 - 2011-08-04

v2.1 - 2011-07-19

v2.0 - 2011-07-17

v1.4.2 - 2010-09-03

v1.4.1 - 2009-11-16

v1.4 - 2009-08-28

v1.3 - 2009-08-26

v1.2 - 2009-08-23

v1.1.2 - 2009-08-21

v1.1.1 - 2009-08-21

v1.1 - 2009-08-21

v1.0 - 2009-08-19

Installation

Just double-click on the RestorePlayHistory-xx.mmip file; if you are on Vista or newer Windows and you got "Product installation error", make sure you have MM set to "Run as Administrator"; if you downloaded the installation package with IE and it changed its extension to a .zip, you should first change it back to a .mmip.

Usage

First of all, it is highly recommended that you periodically make a backup of the database file. You could use this add-on to make the backup or you could copy the database file by yourself - here you could find its location depending of the version of MediaMonkey and Windows.

The next important thing with this add-on is that it could restore data only from/to the backup (external) database file, but it cannot restore the current (active) database with itself. Which means that you need to have the backup file before you get some problem with the current database and nothing can be done if you don't have it.

This version of the add-on could import/export data only if there are tracks in the backup file that are matched with the tracks in the current database, i.e. if they have the same:
1. full path (folders\filename.extension) OR
2. checksum (made after click on Files To Edit / Duplicate Content) OR
3. filename with extension AND FileLength AND Album AND Year AND TrackNumber OR
4. path without drive letter, first folder & extension AND SongLength OR
5. filename without extension AND SongLength AND AlbumArtist AND Album AND Year AND TrackNumber.

The ExtraMatchTests key in the MediaMonkey.ini file determines which criteria will be used to match files between the backup and current databases (you can find more info about that key in the Additional INI keys section). These criteria are cumulative, e.g. if you choose the 4-th one, all previous testing will be executed before that one.

The 2-5. criteria cover situations with modified file locations after backup. The 4-5. criteria further cover situations with different media formats in the backup and current databases, e.g. if the backup database contains .flac tracks and the current one contains .mp3 tracks instead, but with the same filename, song length and other mentioned tags. The 2-5. criteria have the true condition only if there are exactly two matched tracks - if there are three or more tracks matched with those criteria, they would return the false condition and such tracks should have the same full paths to be considered as matched.

The data for tracks that are not matched between current and backup database files will not be restored. This version of the add-on allows matching only one-to-one file, so if you have duplicates in the database (records with the same paths), only the first one will be restored (well, you should avoid having duplicates in the database anyway).

RestorePlayHistory-3.1

The Restore/Synchronize Database dialog box can be opened using its corresponding item in the Tools / Scripts menu. The backup (external) database file should be specified first in the Backup database file text box. The data will be transferred (restored) from that file to the current database if you choose Import or they will be transferred from the current database to the specified backup file if you choose Export. The backup database file should be different than the current database file, i.e. you cannot specify the current database file in this text box.

Immediately after you specify the backup file, the add-on will start comparing the backup with the current database and that process could be very slow, especially with the higher values of the ExtraMatchTests key . So, if you have a large database with too many records, it is recommended that you have specified the lower ExtraMatchTests value before you start the program. The remaining options in the dialog box determine which data will be restored and for which files.

File restrictions
You could choose which files should be restored using two Restore playhistory/metadata only for options. These options are mutually exclusive, i.e. you could use one of them, but not both. With the option Restore playhistory/metadata only for files in collection [MM4] (Restore playhistory/metadata only for filtered tracks [MM3]) you could choose to restore data only for matched files in the specified collection.

If you turn on the option Restore playhistory/metadata only for x selected file(s) [MM4] (track(s) in MM3), data will be restored only for matched files that belong to the group of files that are selected in the main filelist.

Play history
The Restore playhistory option should be turned on if you want to restore the playing data in the Played table and the PlayCounter/LastPlayedDate fields in the Songs table for matched files. If you run this add-on twice with the same backup file, and if you choose this option again, it will not add the play history twice - the add-on will compare those data from the backup and current database files and if they are same it will skip them, i.e. it will add (merge) only the new playing data.

However, if you turn on the option Clear Played table & Playcount/LastTimePlayed fields first, the add-on will remove all playing data from the Played table for matched files from the target database before restoring them from the source database. Also, the PlayCounter/LastPlayedDate fields in the target Songs table will be based only on the data from the source database in that case. So, be careful when using this option.

Playlists
You could restore both Static playlists and/or AutoPlaylists using the corresponding Restore options. However, some type of playlists will be restored even if you do not select them if they are parents of the playlists of the chosen type. For example, if you have some auto-playlist that has the child static playlists, that auto-playlist will be restored if you select Static playlists even if the AutoPlaylists is turned off.

The option Clear Playlists & PlaylistSongs tables first is enabled only if you have turned on both Static playlists and AutoPlaylists check boxes. If you have that option turned on, the add-on will clear the Playlists and PlaylistSongs tables in the target database completely before restoring playlists from the source database. Please be very careful when using that option! If you turn it off, the add-on will merge the playlists from the source database with the existing ones in the target database, i.e. it will restore only playlists that don't exist in the target database. The content of playlists in the target database which have the same names as the playlists from the source database (within the same parent playlists, i.e. in the same hierarchy) will remain unmodified.

Collections/Views (Filters in MM3)
The option Restore collections/views should be turned on if you want to restore collections and views in MM4, or filters in MM3. If you turn on the option Clear Filter table first as well, the collections/views will be completely cleared in the target database before restoring the collections/views from the source database. Please be very careful when using that option! If you turn it off, the add-on will merge the collections/views from the source database with the existing ones in the target database, i.e. it will restore only collections/views that don't exist in the target database.

Metadata
You could restore the selected metadata for matched files if you turn on the option Restore metadata in Songs & other tables, in which case the add-on will update Songs table and other tables that are connected to it by related fields, e.g. Artists or Genres.

The option Update tags in files too (only on Import) allows updating of tags in media files for the corresponding metadata in database on Import. If you forget to turn on that option, but you want to have updated tags in files as well, after restoring of metadata in the database, you could choose the Synchronize Tags option of the program.

The remaining check boxes on the bottom of the dialog box allow you to choose which particular metadata you want to restore, e.g. Date Added, Artist...

Info line and commands
The information line on the bottom of the dialog box displays the total number of files in the backup (external) and current databases, as well as the number of matched files (the numbers inside parentheses are the number of matched files for each matching criterion).

You could click the Backup button if you want to make a copy of your current database file using the destination path specified in the Backup database file text box.

After you have adequately set all previously mentioned options, you could click the Export button if you want to transfer data from the current database to the specified backup file, or you could click the Import button if you want to transfer data from the specified backup file to the current database. Then just wait for the add-on to finish, it could be rather slow and maybe will need several minutes with larger databases.

Additional INI keys

The [RestorePlayHistory] section of the MediaMonkey.ini file contains some less used options that are not represented with GUI:
  • ExtraMatchTests - it could be used to speed up the comparison of databases and can take a value from 0 to 4, which represents the number of additional tests, beside of the base one which compares full paths. Its default value is 4, so all 5 tests mentioned in the Usage section are performed;

  • PlistAltMethod - determines the restoring method of static playlists in MM3: slower, but more reliable method = 0 (default), faster method = 1. The default method is very slow, but it is more reliable when the backup file contains corrupted database. The another method could cause the missing tracks from playlists, but it is a way faster. For example, with one test database the faster method lasted approx. 150 seconds instead of 1600 with the default method.

    The MediaMonkey.ini file is stored in the c:\Documents and Settings\User_Name\Application Data\MediaMonkey\ folder for MM4 and Win7. You could find the location of the .ini file depending of the version of MediaMonkey and Windows here. If you want to modify the mentioned keys in it using e.g. Notepad, you should do that with closed MediaMonkey application.

    Important

    This add-on is relatively dangerous and could cause some corrupted data in the current database, especially if you forcibly terminate the program during its execution! Please make one more backup of the current database before you apply this add-on. Well, maybe you should make a copy of the backup file itself, because this add-on could modify the backup file as well when you choose the Export command (which could be done mistakenly).

    If you have upgraded computer or changed hard disk and if you copied all media files to it keeping the same folder structure, then you could first try to transfer MM database to it and update it using the
    Update Location of Files in Database add-on instead since it is a way faster and simpler to use.

    If you choose any of the Clear ... options, the related tables in the target database will be deleted first after applying the Export/Import command, as it is mentioned in the Usage section! If you want to merge data, you should leave those options unchecked.

    Disclaimer

    This software is provided 'as-is', without any express or implied warranty. In no event will the author be held liable for any damages arising from the use of this software.

    Notice

    This add-on is a false positive reported as a worm by F-Secure. The author of F-Secure promised me that will update its database and put the add-on on white-list, but still didn't. If you go to the www.virustotal.com/en/ site, you will see that it is safe tested by 54 popular anti-virus engines; the only one reporting a worm in it is F-Secure.