Compartilhar via


Backing Up and Restoring Your XP Embedded Database

How many of you have installed one of the updates to the XP Embedded Database (SP1 to SP2, or SP2 to FP2007 CTP) and encountered a message telling you that you should back up your database before proceeding?

Okay, now, how many of you are running MSDE or SQL Express and don't have any SQL administration tools installed?

Well, now there's a solution!

Windows XP Embedded Feature Pack 2007 comes with another small utility in the ValueAdd folder on the CD, called DBRestore. This little tool can back up and restore your database, provided you have any version of SQL Server (MSDE, SQL Express, SQL 2000, SQL 2005, etc) installed.

In fact, it can back up remote databases too, if you have administrator access to the machine where the database resides. To use DBRestore, open a CMD window and navigate to your FP2007 CD (or the folder where you expanded the CD image), then go to the ValueAdd folder. Now, just run DBRestore.vbs as follows (this is a direct copy of the usage text from the program):

 DBRestore.vbs v1.21
Backup and Restore Utility for Windows XP Embedded Databases.

Command-Line Usage:
  DBRESTORE ComputerName BackupPath [/CB|/CREATEBACKUP]

Parameters:
----------
ComputerName (required)
  Can be "local" (no quotes) or the name of a computer (local or remote).
  The named computer must be running an XP Embedded database, retail or eval.

BackupPath (required)
  Can be a local or UNC path.  Can be a path to a folder, or to a specific
  file - if a filename is specified, it must be a .MDF file (case is not
  important).  If a folder is specified, a file must exist in the folder
  matching the existing database file (unless you are creating a backup).

/CB or /CREATEBACKUP (optional)
  Specifies that you want to create a backup of the existing database.  In
  this case, BackupPath must point to a valid location to create the backup
  file.  If you do not specify a filename (with .MDF extension), DBRestore
  will create a backup filename with the same name as the existing database
  file.  (Note: DBrestore determines the correct filename to use by querying
  the database directly.)

For example, to create a backup of your existing SP2 database:

 dbrestore MyServer c:\MySP2Backup.mdf /cb

To later restore this database, you would just execute the same line without the /cb switch.

Note that this tool only backs up your database MDF file. It does not backup your repositories. However, it does manage your repositories by automatically checking to see which repository folders correspond to the repository definitions in your database.

It will remove any that don't belong after the backed-up database is restored - for example, if you restore your SP2 database after having installed FP07, the FP07-specific repositories will be removed. However, if your SP2 database includes some custom components and repositories for, say, custom drivers or applications, those will be preserved during the restore. We hope you enjoy the final release of Feature Pack 2007!

- Matt

Comments

  • Anonymous
    November 21, 2006
    The comment has been removed
  • Anonymous
    November 22, 2006
    Nicolas, Some basic questions:
  1. Are you sure the database is attached (and not been detached through some other method e.g. SQL Server Management tool) before trying to create the backup using dbrestore?
  2. Is the database still in use when you are trying to run dbrestore (e.g. a configuration is still open in Target Designer or something similar)?
  3. Do you have permission to write to the C:  (or the location where you are trying to save your mdf to)?
  4. Does this error also occur if you specify the actual server name (as opposed to "local")? Lynda
  • Anonymous
    November 23, 2006
    The comment has been removed

  • Anonymous
    November 23, 2006
    Well, it appears we probably could have done a better job in our uninstall process since we're seeing

  • Anonymous
    November 27, 2006
    Actually, this error occurs if you attempt to run the script using "WScript.exe" rather than "CScript.exe" (the difference is between the Windows GUI script-host and the Console script-host).  You can solve this problem by either running cscript explicitly: cscript dbrestore.vbs (params) ...or setting CScript as your default script host: cscript //H:cscript After running the latter command, cscript will be used by default.  This will solve this particular problem.