SQL Anywhere allows transactions to span multiple transaction log files. If a database is backed up part way through a transaction, the transaction may span two transaction log files. When this occurs, the first part of the transaction is contained in the offline transaction log, while the second part of the transaction is contained in the online transaction log.
If you need to recover your database and you have multiple transaction logs, you must apply the transaction log files to the backup copy of your database in the correct order in case there are transactions that span multiple transaction logs. If the transaction logs are not applied in the correct order, then portions of transactions that span multiple transaction logs are rolled back.
You can use any of the following methods to apply transaction logs in the correct order:
See -a database option.
See -ad database option.
See -ar database option.
The -ad server option is used to recover a database by applying all the transaction logs from a specified directory to the backup copy of a database. When this option is specified, the database server applies the log and then shuts down the database.
To recover from multiple transaction logs using the -ad server option
Start the database server using -ad to apply the transaction logs to the backup copy of your database. See -ad database option.
The following example applies the offline (backup) and current transaction logs to the backup copy of the sample database using the -ad database server option. The database server uses the log offsets in the transaction logs to determine the correct order in which to apply the log files.
dbeng11 backupdemo.db -ad c:\backuplogs |
The database server applies the transaction logs to the backup copy of the database and then shuts down.
The -a server option is used recover a database by applying a single transaction log file to the backup copy of a database. When this option is specified, the database server applies the log and then shuts down—it will not continue to run. If you have multiple transaction logs, you must apply them one at a time in the correct order, from oldest to most recent.
To recover from multiple transaction logs using the -a server option
Start the database server using -a to apply the backup transaction log to the offline (backup) copy of your database.
See -a database option.
Start the database server and apply the current transaction log to the backup copy of your database.
The following example applies the offline (backup) and current transaction logs to the backup copy of the sample database using the -a database server option.
dbeng11 backupdemo.db -a backupdemo.log |
The database server applies the backup transaction log to the backup copy of the database and then shuts down.
dbeng11 backupdemo.db -a demo.log |
The database server applies the current transaction log to the backup copy of the database and then shuts down.
To maintain the integrity of your data when you use dbtran to translate multiple transaction logs, you must specify both the -m and -n options. The -m option instructs the Log Translation utility to generate a file (named by -n) containing all the transactions from the logs in the specified directory.
You need to use -m because if you translate each log individually using dbtran, any transactions that span transaction log files could be rolled back. This is because when dbtran translates a log, it adds a ROLLBACK statement to the end of the log to undo any uncommitted transactions. In cases where a transaction spans two logs, the COMMIT for the transaction occurs in the second log file. Operations at the end of the first log file would be rolled back by dbtran because the file does not contain a COMMIT for the transaction. Translating all the transaction log files in a directory using -m ensures that all your transactions are translated. See Transaction Log utility (dblog).
To recover from multiple transaction logs using the dbtran utility
Run the Log Translation utility (dbtran) against the directory containing the transaction log files and output the resulting SQL statements into a .sql file.
Start the backup copy of your database.
Apply the .sql file generated by dbtran in step 1 to the backup copy of your database from Interactive SQL.
The following example uses the dbtran utility to apply the backup and current transaction logs to the backup copy of the database.
dbtran -m "c:\backup" -n recoverylog.sql |
dbeng11 backupdemo.db |
dbisql "UID=DBA;PWD=sql;END=backupdemo" READ recoverylog.sql |
Send feedback about this page via email or DocCommentXchange | Copyright © 2008, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.0 |