Database backup and restore

From Dragon Age Toolset Wiki
Revision as of 18:59, 3 February 2010 by Eshme (Talk | contribs) (Restoring the Database if it failed after Installation)

Jump to: navigation, search

The following commands can be used to backup and restore your database, assuming you're using the default database name (bw_dragonage_content):

Restoring the Database if it failed after Installation

If you installed the Toolset, and receive an Error message "Unable to connect to Database", and have never made a Backup, this Solution helps. Although it is a batch file, and requires the users maintenance.

Note: Be aware that it will overwrite the old Database if it existed.


1. Create a file called "MyRestore.bat" anywhere in your system and edit it with a program like "Notepad"

2. Copy and paste the complete following lines into it:

SET SOURCE=C:\Program Files\Dragon Age\tools\dbbak
SET TARGET=C:\Program Files\Dragon Age\tools\toolssql\Data
 
@Echo off
if not exist "%SOURCE%\bw_dragonage_content.bak" goto Sourcemiss
if not exist "%TARGET%" goto Targetmiss
:returnme
if not exist "%PROGRAMFILES(X86)%\Microsoft SQL Server\90\Tools\Binn\" goto SQLmiss64
SET varprogs=%PROGRAMFILES(X86)%
goto apply
 
:SQLmiss64
if not exist "%ProgramFiles%\Microsoft SQL Server\90\Tools\Binn\" goto SQLmiss32
SET varprogs=%ProgramFiles%
goto apply
 
:apply
Echo Running SQLcmd...
"%varprogs%\Microsoft SQL Server\90\Tools\Binn\"sqlcmd -S .\BWDATOOLSET -E -Q "RESTORE DATABASE bw_dragonage_content FROM DISK = '%SOURCE%\bw_dragonage_content.bak' WITH MOVE 'bw_dragonage_content' TO '%TARGET%\bw_dragonage_content.mdf', MOVE 'bw_dragonage_content_log' TO '%TARGET%\bw_dragonage_content.ldf'"
goto End
 
:Sourcemiss
Echo SOURCE not found. (bw_dragonage_content.bak) Please check.
Echo Edit this File with Notepad and reapply correct location.
goto End
 
:Targetmiss
Echo TARGET directory does not exist and will be created: %Target%
PAUSE
mkdir "%TARGET%"
if not exist "%TARGET%" goto Stillmiss
goto returnme
 
:Stillmiss
Echo TARGET Directory creation failed. Please check.
goto End
 
:SQLmiss32
Echo SQL is missing. Please check location (Windows 32bit): %PROGRAMFILES%\Microsoft SQL Server\90\Tools\Binn\
Echo SQL is missing. Please check location (Windows 64bit): %PROGRAMFILES(X86)%\Microsoft SQL Server\90\Tools\Binn\
Echo Edit this file with Notepad and apply correct location.
goto end
 
:End
PAUSE

3. Change SET SOURCE and SET TARGET to the path of your Dragon Age installation folder as appropriate. Look it up if you dont know. The above example is default for english WindowsXP 32bit.

3.1 Common other default paths are C:\Program Files(x86)\Dragon Age\... for 64Bit Windows XP /Vista
3.2 C:\Programme\Dragon Age\... for 32bit Windows XP/Vista (german)
3.3 Archivos de Programa(x86)\Dragon Age\... for 64bit Windows XP/Vista (spanish)

4. Save and run the new "MyRestore.bat" file by doubleclicking. Make sure you are logged in as "Administrator".

5. If you get a load of Error messages saying among others "The operating system returned the error (Access denied) while attempting..":

5.1. SQL being picky about write access here. Workaround: Change the second line into SET TARGET=C:\DB , and rerun it. You may experiment with this.

6. Once finished with a short success message ,you can start the Toolset.

Using the Backup and Restore batch files

A pair of batch files have been included with the toolset install to ease the process of making backups. They can be found at:

C:\Program Files\Dragon Age\tools\DatabaseUtilities\Backup_Restore

Both the "Backup" and "Restore" scripts are controlled by settings stored in the config.ini file. If you're using the default database location the only settings you'll need to change are the filenames that backups will be stored to or read from.

Use caution when restoring your database, as this will overwrite everything in your existing database.

Also note that SQL Server is very picky about directory access permissions, and may not be able to write to the directory of your choosing. Check to make sure that your backup file was actually created after doing a backup. A common way of ensuring that SQL Server will be able to write to the backup directory is to create the backup directory directly off of the root of your drive, such as C:\Backups\.

Backup

sqlcmd -S .\BWDATOOLSET -E -Q "BACKUP DATABASE <Database Name> TO DISK = '<Backup Directory><Backup Filename>'"

Where:

<Database Name> is the name of your database, typically bw_dragonage_content
<Backup Directory> is the name of the directory where you want to save the backup file (directory must exist, this process will not create it)
<Backup Filename> is what you are naming the backup file

an example:

sqlcmd -S .\BWDATOOLSET -E -Q "BACKUP DATABASE bw_dragonage_content TO DISK = 'C:\Backup\bw_dragonage_content.bak'"


Restore

sqlcmd -S .\BWDATOOLSET -E -Q "RESTORE DATABASE <Database Name> FROM DISK = '<Backup Directory><Backup Filename>' WITH REPLACE"

where:

<Database Name> is the name of your database, typically bw_dragonage_content
<Backup Directory> is the name of the directory where the backup file resides
<Backup Filename> is the name of backup file you wish to restore

an example:

sqlcmd -S .\BWDATOOLSET -E -Q "RESTORE DATABASE bw_dragonage_content FROM DISK = 'C:\Backup\bw_dragonage_content.bak' WITH REPLACE"


If you're restoring to a data store that's in a location other than the store you made the backup from (for example if you're moving your data from one computer to another and the toolset is installed in a different location on the destination machine) you can add the following to the restore command to restore to the new location. If you're restoring to the same place you made the backup from you can omit this.

WITH MOVE 'bw_da_content_euts_Data' TO 'C:\Program Files\Dragon Age\toolssql\Data\bw_dragonage_content.mdf', MOVE 'bw_da_content_euts_Log' TO 'C:\Program Files\Dragon Age\toolssql\Data\bw_dragonage_content.ldf'

Troubles with sqlcmd

You may experience a strange occurrence where sqlcmd is not recognized as a dos command. You can try to download Microsoft SQL Server 2005 Command Line Query Utility at

http://www.microsoft.com/downloads/details.aspx?FamilyID=D09C1D60-A13C-4479-9B91-9E8B9D835CDC&displaylang=en (scroll down a bit)

Reboot your computer and try it again, it should work.