Customizing the SQL Anywhere backup procedure

<< Click to Display Table of Contents >>

Navigation:  Supported database systems > SAP SQL Anywhere > Tools >

Customizing the SQL Anywhere backup procedure

Backup is performed by executing the SQL BACKUP command contained in the files backup_database.sql and schedule_backup.sql. You can customize the backup procedure by modifying the commands contained in those files.

 

The contents of the backup_database.sql file that ships with Dispatch is as follows:

 

--

-- make a backup copy of a running database

--

-- this will rename the existing transaction log using the following format: YYMMDD[A-Z][A-Z].LOG

--

-- if multiple backups are performed on the same day - July 13, 2017 for example - the log files

-- will be named 170713AA.LOG, 170713AB.LOG, 170713AC.LOG and so on

--

MESSAGE 'Backup database file to ', '&1';

BACKUP DATABASE DIRECTORY '&1'

TRANSACTION LOG RENAME;

 

The '&1' refers to Folder property in the Manual backup settings.

 

The full syntax of the BACKUP command is as follows:

Syntax 1

BACKUP DATABASE

DIRECTORY backup-directory

[ WAIT BEFORE START ]

[ WAIT AFTER END ]

[ DBFILE ONLY ]

[ TRANSACTION LOG ONLY ]

[ TRANSACTION LOG RENAME [ MATCH ] ]

[ TRANSACTION LOG TRUNCATE ]

Syntax 2

BACKUP DATABASE TO archive-root

[ ATTENDED { ON | OFF } ]

[ WITH COMMENT comment string ]

 

 

Parameter

Description

backup-directory

The target location on disk for the backup files, relative to the server's current directory at startup. If the directory does not already exist, it is created. Specifying an empty string as a directory allows you to rename or truncate the log without making a copy of it first.

 

The backslash ( \ ) is an escape character in SQL strings, so each backslash must be doubled (e.g. 'C:\\My\\Backup').

 

You can use '&1' in place of a fixed directory location. See the examples below.

WAIT BEFORE START

This clause ensures that the backup copy of the database does not contain any information required for recovery. In particular, it ensures that the rollback log for each connection is empty.

 

If a backup is carried out using this clause, you can start the backup copy of the database in read-only mode and validate it. By enabling validation of the backup database, the customer can avoid making an additional copy of the database.

WAIT AFTER END

This clause may be used if the transaction log is being renamed or truncated. It ensures that all transactions are completed before the log is renamed or truncated. If this clause is used, the backup must wait for other connections to commit or rollback any open transactions before finishing.

MATCH keyword

If you supply the MATCH keyword, the backup copy of the transaction log is given a name of the form YYMMDDnn.log. This enables the same statement to be executed several times without writing over old data.

archive-root

The file name or tape drive device name for the archive file.

 

To back up to tape, you must specify the device name of the tape drive. For example, on Windows NT or NetWare, the first tape drive is \\.\tape0.

 

The backslash ( \ ) is an escape character in SQL strings, so each backslash must be doubled.

WITH COMMENT

Record a comment in the archive file and in the backup history file.

ATTENDED

The clause applies only when backing up to a tape device. ATTENDED ON (the default) indicates that someone is available to monitor the status of the tape drive and to place a new tape in the drive when needed. A message is sent to the application that issued the BACKUP statement if the tape drive requires intervention. The database server then waits for the drive to become ready. This may happen, for example, when a new tape is required.

 

If ATTENDED OFF is specified and a new tape is required or the drive is not ready, no message is sent, and an error is given.

 

Each BACKUP operation, whether image or archive, updates a history file called backup.syb. This file is stored in the same directory as the database server executable.

Examples

Back up the current database and the transaction log to a file, renaming the existing transaction log. An image backup is created.

 

BACKUP DATABASE

DIRECTORY 'd:\\temp\\backup'

TRANSACTION LOG RENAME

 

The option to rename the transaction log is useful especially in replication environments, where the old transaction log is still required.

 

Back up the current database and transaction log to tape device:

 

BACKUP DATABASE

TO '\\\\.\\tape0'