Backup Media with Database – 7Zip

The following was written in 2011 and RM Inc did rise to the challenge and produced a Backup option that includes media. However, it does two things that some people do not like if they are forced to restore from that backup:

  1. Their carefully developed folder structure for media is collapsed into one media folder underneath the restored database.
  2. Their carefully named media items are renamed in the backup file to a hexadecimal string which must be a hash of the original name. While a successful RM Restore will both extract and unhash the name, using an independent unzip utility will not thus breaking all links between the database and the restored media items.

The procedure described below avoids those two outcomes by preserving paths and filenames in the backup file.

2011 Text

Not everyone wants to pay for an archive utility as much or more than the price of RootsMagic alone, especially when RootsMagic already includes an archiving engine that, with a few tweaks, could do the job. So here is a full database + media procedure that uses a free backup program, 7-Zip AND produces a .rmgb archive/backup file containing both a RootsMagic database and the media files it uses. And the really good news is that the RootsMagic Restore function will unpack the archive to a folder where the media will be in the same relative folders as they were in at the time of archiving. If this target folder path is different from the path of the original database folder, all that’s needed to correct the now erroneous media links in the database is to use RM’s Search & Replace on Multimedia filenames. So c’mon RM! It should be a trivial task to add a full backup feature to the File menu…

The Zip encoder RM4-7 uses for Backup may not be able to handle a large database with many media files – another reason to use outboard procedures until its limitations are lifted. See this article in Wikipedia on the early Zip limits.

If you have not done so, read the original page Backup Media with Database – RAR to find out about setting up the shortcut and placement of files.

This is the batch procedure to be called by the shortcut:
RMfullbackup7zip.bat.bak (.bak extension added because of some systems’ security that blocks .bat)

Here is the script:

REM RMfullbackup7zip.bat
REM RMfullbackup.bat by Tom Holden 2011-02-02
REM Rev 2011-03-20: uses free 7-Zip utility to create a .rmgb backup compatible with RootsMagic Restore function
REM Backs up a RootsMagic database file and all the media files referenced by it to one, compressed ZIP type file.

REM Command syntax: RMfullbackup.bat <databasename>
REM This batch file should be in the same folder as the database and expects a Backups folder immediately below it.
REM All media files must be in subsidiary folders below the database folder or in the same folder. If not, then
REM the SET variables must be revised so that the contentPath is common to the database and media paths. 
REM Close the database file from RootsMagic before running.

REM The first backup can take considerable time, depending on the total of the file sizes.
REM To save time on subsequent backups, RMfullbackup merely updates the backup file for those files added, changed or deleted.
REM Install the SQLite3 command line version in the same directory as the RMGC database file(s)
REM  OR set a system PATH to where sqlite3.exe is located
REM  OR prepend the path to sqlite3.exe in the command below.
REM Likewise for 7z.exe
REM Under the RM Data folder, create a folder Backups; if a different path is to be used, edit the command line below.

REM The backup file will be written to the Backups folder and will have the name <databasename>_fullbackup.rmgb
REM A log will also be written to the Backups folder with the name <databasename>_fullback.rmgb.log

REM ***set variables
SET archiver=C:\Program Files\7-Zip\7z.exe
SET contentPath=.\
SET list=.\Backups\backup.lst
SET archive=Backups\%1_fullbackup.rmgb

REM ***run sqlite query to get list of media files to be backed up 
sqlite3.exe %1.rmgc "SELECT DISTINCT trim(MediaFile) from MultiMediaTable;" > "%list%"

REM ***change directory to the root path common to both the database and media files.
cd /d "%contentPath%"

REM backup media files listed by query followed by the database file
"%archiver%" u -tzip "%archive%" @"%list%" %1.rmgc -r > "%archive%.log"


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.