+ All Categories
Home > Documents > Backup Restore

Backup Restore

Date post: 11-Jul-2016
Category:
Upload: hai-huy
View: 253 times
Download: 5 times
Share this document with a friend
Description:
Backup Restore Sybase IQ 16
45
Copyright 2009 Sybase, Inc. All rights reserved. No part of this publication may be reproduced, transmitted, or translated in any form or by any means, electronic, mechanical, manual, optical or otherwise, without prior written permission from Sybase, Inc. Sybase IQ Administration Backup and Restore
Transcript
Page 1: Backup Restore

Copyright 2009 Sybase, Inc. All rights reserved.

No part of this publication may be reproduced, transmitted, or translated in any form or by any means, electronic, mechanical, manual, optical or otherwise, without prior written permission from Sybase, Inc.

Sybase IQ Administration

Backup and Restore

Page 2: Backup Restore

10 - 2

MOD

ULE

TOP

ICS

Diagnostic Stored Procedures

Utilities: dblog and db_backupheader

Restore

Backup

Page 3: Backup Restore

10 - 3

Two Ways To Backup Sybase IQ Data Database backup

Full backup – makes a complete copy of the database incremental backup – copies all transactions since the last

backup of any type – copies all transactions since the last full Incremental-since-full backup

Virtual Backup – copies all of the database except for the table data from the IQ Store

Uses multiple devices for backups, allowing for parallel backups

Can run concurrently with other database operations, except metadata changes

The process backs up committed data

Page 4: Backup Restore

10 - 4

Database Backup Methods Full

Full backup of Catalog Store Full backup of IQ Store Default action

Incremental Full backup of Catalog Store Backs up changes to IQ Store since last backup of any type

Incremental-since-full Full backup of Catalog Store Backs up changes to IQ Store since last full backup

Page 5: Backup Restore

10 - 5

Backup Process Steps First, the Catalog Store (dbname.db) is backed up for a database, then

the transaction log file (dbname.log – only when the database is SA), and then all the dbspace files for the IQ Store

Backs up ONLY committed data!

Page 6: Backup Restore

10 - 6

Archive Devices Archive devices can be either disk or magnetic tape drives Disk backups must go to file systems, not raw devices Supported tape devices:

Digital linear tape (DLT) on UNIX 4mm DDS 8mm

Stacker drives with multiple tapes

Page 7: Backup Restore

10 - 7

BACKUP DATABASE SyntaxBACKUP DATABASE... { READWRITE FILES ONLY | READONLY dbspace-or-file [, …]}

... [CRC ON | OFF]

... [ATTENDED ON | OFF]

... [BLOCK FACTOR integer]

... [{FULL|INCREMENTAL|INCREMENTAL SINCE FULL}]

... [ { VIRTUAL DECOUPLED | VIRTUAL ENCAPSULATED 'shell_command' } ]

... TO 'archive_device' [SIZE #_of_KB integer ] [ STACKER #_of_tapes_in_stack integer ] ...... [WITH COMMENT ’string’]

Sybase IQ 15 Additions

Page 8: Backup Restore

10 - 9

Which Files and Where DBSPACES | FILES

Sybase IQ 15.0 introduces the concept and implementation of one or more dbfiles within a dbspace

Accommodates the architectural enhancement Dbfiles are not present in Sybase IQ 12.7

TO Specifies the name of the archive_device to be used for

backup, delimited with single quotation marks Archive_device is a file name or tape drive device name for

the archive file Must use separate TO clauses if using multiple archive

devices

Page 9: Backup Restore

10 - 10

Attended/Unattended Attended

Operator must be present Prompts to mount archive media Default action

Unattended No prompts are issued Must make appropriate size estimates and set up devices in

advance

Page 10: Backup Restore

10 - 11

Backup Options FULL

Specifies a full backup and is the default action All blocks in use in the database are saved to the archive

device(s) INCREMENTAL

Specifies an incremental backup All blocks changed since the last backup of any kind are

saved to the archive device(s) INCREMENTAL SINCE FULL

Specifies an incremental backup All blocks changed since the last FULL backup are saved to

the archive device(s)

Continued …

Page 11: Backup Restore

10 - 12

Backup Options VIRTUAL DECOUPLED

Specifies a decoupled virtual backup For the backup to be complete:

Copy the IQ dbspaces after the decoupled virtual backup finishes

And then perform a non-virtual incremental backup VIRTUAL ENCAPSULATED

Specifies an encapsulated virtual backup ‘shell-command’ argument can be a string or variable

containing a string executed as part of the encapsulated virtual backup

Shell commands execute a system-level backup of the IQ Store as part of the backup operation

Page 12: Backup Restore

10 - 13

Archive Options SIZE (KB)

Maximum size of the backed up data on that stripe Should specify for unattended tape backups on platforms that

do not reliably detect the end-of-tape marker Should also specify whether backup to disk is not the default

of 2GB STACKER

Indicates that Sybase IQ is being backed up to an automatically loaded multitape stacker device

Specify the number of tapes in that device

Page 13: Backup Restore

10 - 14

Simple Backup Examples Example:

BACKUP DATABASEINCREMENTALTO '/dev/rmt/0n' SIZE 15000WITH COMMENT 'March 17 incremental backup of mydb database'

Makes a full backup of the database to one tape device Catalog Store is backed up first, then the IQ Store

Example using new syntax introduced in Sybase IQ 15 that shows a backup of dbspace and dbfiles:

BACKUP DATABASE READONLY DBSPACES dsp2, dsp3READONLY FILES dsp4_f1, dsp5_f2 TO ‘bkp.RO’

Take note that the keyword INCREMENTAL is not allowed with READONLY FILES

Page 14: Backup Restore

10 - 15

Validating the Database Should run sp_iqcheckdb before a backup to make sure the

database is in a usable state Syntax:sp_iqcheckdb 'mode target[ …][resources resource-percent]'

Do not run sp_iqcheckdb while another user is doing inserts and deletes

Results may be misleading. sp_iqcheckdb can falsely report leaked blocks if there are multiple versions of any given table

You can pipe the output of sp_iqcheckdb to a file using #> in your SQL statement

Page 15: Backup Restore

10 - 25

MOD

ULE

TOP

ICS

Diagnostic Stored Procedures

Utilities: dblog and db_backupheader

Restore

Backup

Page 16: Backup Restore

10 - 26

Restore Features Allows parallel restore using multiple tape drives Can restore full database Can restore from incremental database backup Can restore to a new location

Useful for a lost device

Page 17: Backup Restore

10 - 27

Before a Restore... Must have Database Administrator privileges

Must have exclusive access Set using the switch: -gd DBA

Must be connected to the utility_db database as DBA No user can be connected to the database being restored

For a full restore, the Catalog Store and the Transaction Log (.db and .log files) must not exist

For an incremental restore, the Catalog Store and the Transaction Log must exist

For restoring a multiplex database, the server must be started with the multiplex override switch, -iqmpx_ov 1

Page 18: Backup Restore

10 - 28

RESTORE DATABASE Syntax:

RESTORE DATABASE 'database-name'[ restore-option ... ]FROM 'archive_device' ...restore-option:READONLY dbspace-or-file [, …]KEY key_specRENAME file-name TO new-file-path ...

database_name - relative or absolute path key_spec

Quoted string representing the database encryption key Includes mixed cases, numbers, letters, and special

charactersContinued …

Version 15.0 only

Page 19: Backup Restore

10 - 29

RESTORE DATABASE RENAME option

Specifies a dbspace (in 12.7) or a dbfile (in 15.0) to be created on a different path

Cannot rename the transaction log using this option To move or rename the log file use the DBLOG utility

Page 20: Backup Restore

10 - 30

Examples BACKUP statement and two possible RESTORE statements:

BACKUP DATABASE READONLY DBSPACES iq_main TO '/system1/IQ15/IQ-15_0/demo/backup/iqmain'

RESTORE statement 1:

RESTORE DATABASE 'iqdemo' READONLY DBSPACES iq_main FROM '/system1/IQ15/IQ-15_0/demo/backup/iqmain'

RESTORE statement 2:

RESTORE DATABASE 'iqdemo' FROM '/system1/IQ15/IQ-15_0/demo/backup/iqmain'

Page 21: Backup Restore

10 - 31

Moving Database FilesTwo Methods: To move the database file that holds the Catalog Store (by

default, the DB file), specify the new name as database_name

Example:

RESTORE DATABASE 'c:\\newdir\\mydbnew.db'FROM 'C:\\iq\\backup1'FROM 'C:\\iq\\backup2’

For any other database file, use the RENAME option See example on next slide

Continued …

Page 22: Backup Restore

10 - 32

Moving Database Files To move any database file other than the catalog store

Identify the files using sysfile Back up the database Restore the database using the rename option

select * from sysfilefile_id file_name dbspace_name store_type----------------------------------------------------0 /sybase/salesdb/salesdb.db SYSTEM SA16384 /dev/iqdisk/salesdb.iq IQ_SYSTEM_MAIN IQ16385 /dev/iqdisk/salesdb.iqtmp IQ_SYSTEM_TEMP IQ16386 salesdb.iqmsg IQ_SYSTEM_MSG IQ

Continued …

Page 23: Backup Restore

10 - 33

Moving Database Files Back up the databasebackup databaseto '/dev/rmt/0n' size 15000

Restore the databaserestore database ‘/sybase/salesdb/salesdb.db'from '/dev/rmt/0n'rename IQ_SYSTEM_MAIN to '/dev/newiqdisk/salesdb.iq‘rename IQ_SYSTEM_TEMP to'/dev/newiqdisk/salesdb.iqtmp'

Page 24: Backup Restore

10 - 34

Selective Backup Backs up either all READWRITE dbspaces or specific

READONLY dbspaces or dbfiles Can take a READONLY selective backup and restore all

objects from this backup Can take an all-inclusive backup and restore read-only files

and dbspaces selectively Can take a READONLY selective backup of multiple read-only

files and dbspaces and restore a sub-set of real-only files and dbspaces selectively

Restore of a read-only backup can happen only if that dbspace or dbfile has not changed since the backup

Page 25: Backup Restore

10 - 35

Dealing with Restore Failures Key point! Restore operation is not transactional If restore fails mid-way, the files restored until that point may not

be in consistent state If the files restored are inconsistent, the operation must be

repeated until it succeeds When running backup operation, may specify option CRC ON to

enable restore time verification After the backup operation finishes, as a practice, remove the

write permission on the backup archive to avoid accidental overwrite

Before starting restore with Sybase IQ 15.0, may also run command-line utility db_backupheader to verify backup archive header information

Page 26: Backup Restore

10 - 36

Notes and Restrictions Must restore full and incremental backups in the correct order Sybase IQ does not rewind tapes before using them

On rewinding tape devices, each tape must be positioned To ensure the database has been restored correctly, run

sp_iqcheckdb 'check database' after Restore

Page 27: Backup Restore

10 - 37

IQ Backup and Restore Performance Multiple tape drives provide the best performance Set CRC OFF in the BACKUP command to improve the

speed of backup and restore Increase memory during backup

Adjust BLOCK FACTOR Keep the size of the Catalog Store small

Creating non-IQ tables in it will increase backup and restore time

Page 28: Backup Restore

10 - 38

Estimating Dump Size Sybase IQ backs up

compressed data (no zeros)

sp_iqstatus Main IQ Blocks

Used output gives size of compressed data

Use 19089 * 4096 + catalog store = Total Bytes

Page 29: Backup Restore

10 - 39

MOD

ULE

TOP

ICS

Diagnostic Stored Procedures

Utilities: dblog and db_backupheader

Restore

Backup

Page 30: Backup Restore

10 - 40

sp_iqbackupsummary Summarizes backup operations performed DBA authority required Syntax:

sp_iqbackupsummary [timestamp] timestamp specifies the interval for which to report backup

operations If a timestamp is specified, the procedure returns only those

records with bu_time greater than or equal to that time If no timestamp is specified, the procedure returns all the

backup records in ISYSIQBACKUP

Page 31: Backup Restore

10 - 41

Summary Information Detail Column descriptions:

Column name Descriptionbackup_id Identifier for the backup transaction

backup_time Time of the backup

backup_type Type of backup: “Full,” “Incremental since incremental,” or “Incremental since full”

selective_type Subtype of backup: “All,” “All RW files,” or “RO file”virtual_type Type of virtual backup: “Non-virtual,” “Decoupled,” or

“Encapsulated”depends_on_id Identifier for transaction that the backup depends oncreator Creator of the backupbackup_size Size of the backup file in MBuser_comment User commentbackup_command The backup statement issued (minus the comment)

Page 32: Backup Restore

10 - 42

sp_iqbackupdetails Shows all the dbfiles backed up in a particular backup

specified by its transaction identifier DBA authority required Syntax:

sp_iqbackupdetails [backup_id] backup_id specifies the backup operation transaction identifier

Page 33: Backup Restore

10 - 43

Detail Information Retrieved Column descriptions:

Column name Descriptionbackup_id Identifier for the backup transaction.backup_time Time of the backup.backup_type Type of backup: “Full,” “Incremental since incremental,” or “Incremental since full.”selective_type Subtype of backup: “All,” “All RW files,” or “RO file.”dbspace_name Name of the dbspace from ISYSIQBACKUPHISTORYDETAIL. If it matches the

dbspace name in ISYSDBSPACE for a given dbspace_id. Otherwise “null.”dbspace_rwstatus “ReadWrite” or “Read Only.”dbspace_size Size of dbspace at time of backup in MB.dbspace_backup_size Size of data backed up in the dbspace.dbfile_id Identifier for the dbfiledbfile_name The logical file name if it was not renamed after the backup operation. If renamed,

“null.”dbfile size in MB Size of the dbfile, in MBdbfile_backup_size Size of the dbfile backup, in MBdbfile_path The dbfile path from ISYSBACKUPDETAIL, if it matches the physical file path

(‘file_name’) in ISYSDBFILE for a given dbspace_id and the dbfile_id. Otherwise “null.”

Page 34: Backup Restore

10 - 44

sp_iqrestoreaction Shows what restore actions are needed to bring database to

a consistent state with a given past date Syntax:

sp_iqrestoreaction [ timestamp ] Result Information:

When successful, suggests restore actions that will return the database to a consistent state

Returns an error if database cannot be brought to a consistent state for the timestamp

Try again after consulting sp_iqbackupsummary with a different timestamp

Page 35: Backup Restore

10 - 45

MOD

ULE

TOP

ICS

Diagnostic Stored Procedures

Utilities: dblog and db_backupheader

Restore

Backup

Page 36: Backup Restore

10 - 46

dblog Utility Utility program to manipulate the transaction log for your

database file (.log file) The executable will be in the path

Syntax:dblog [options] database-file

Use dblog to: Create a new transaction log

Recommended after a successful restore as a matter of routine Start or Stop a mirror for the transaction log

The database must run with a transaction log

Continued …

Page 37: Backup Restore

10 - 47

dblog Utility dblog Switches Options

-t log-name (Set the transaction log name) -m mirror-name (Set transaction log mirror name) -r (stop mirror for transaction log) -o (log output messages to a file) -q (Quiet mode – do not print messages)

Example: Start a new database transaction log for iqdemo

dblog –t demolog.log iqdemo

Page 38: Backup Restore

10 - 48

db_backupheader Utility used to read the backup archive file

It does not connect to the database Syntax:

db_backupheader <first backup file> The backup archive information includes:

Backup information Database information at the time of the backup dbspace information for each dbspace in the database dbfile information for each dbfile in the dbspaces

Useful utility in the case you need to know every dbspace in the database when using the RENAME option of RESTORE

Continued …

Page 39: Backup Restore

10 - 49

db_backupheader Partial sample:

IQ Backup Header Display of File: "iqdemo.bu.1"

Volumn Header: "VOL10000014"Header 1: "HDR1000000000000000000000000000000000"Header 2: "HDR2D000000000000"

Backup Data Record: DB Name: "iqdemo.db"DB Type: "ASIQ"Current Backup ID: "28683"Depends On ID: "0"Last Full ID: "0"Creation Date: "2009-06-16 00:59:00.000"

Continued …

Page 40: Backup Restore

10 - 50

db_backupheader Partial sample:

Creator: "DBA"Total Tapes: "1"Backup Type: "Full"Media: "Othr"Backup Version: "6"Backup Method: "Arch"Backup Location: "/home/sybase/iqdemo.bu"Filler: 0x0

Backup Data Record Extended: ...

Page 41: Backup Restore

10 - 51

dbbackup Utility Makes a copy of the IQ Transaction Log Syntax:

dbbackup [options] target-directory Can truncate the transaction log, freeing disk space and

improving recovery speed without having to stop and restart your server

However, to back up an entire Sybase IQ database, always use the BACKUP statement NOT dbbackup

Why? BACKUP backs up all database files, and is the only way to back up the catalog store

Page 42: Backup Restore

10 - 52

dbbackup Options

Option Description@data Read options from the specified environment variable or

configuration file

-c "keyword=value; ... " Supply database connection parameters

-l (lowercase L) file Live backup of the transaction log to a file

-q Quiet mode — do not print messages

-r Copy the old transaction log to a new name and start a new empty log

-xo filename Truncate (delete and restart) the transaction log

Page 43: Backup Restore

10 - 53

Live Backup of Transaction Log Must use option –l (lowercase L) Install and configure Sybase IQ on the secondary machine Periodically, make a full backup to the secondary machine Run a live backup of the transaction log to the secondary machine

using:

dbbackup -l path\filename.log –c "connection_string“

Run the dbbackup utility from the secondary machine If the primary machine becomes unusable, you can restart your database

using the secondary machine Database file and the transaction log hold the information needed to

restart

Page 44: Backup Restore

10 - 54

Module Summary During the course of this module, you have learned:

How to do develop a data backup and restore strategy How to schedule routine backups

Mixing full and incremental backups Restores should be tested on a periodic basis How to use sp_iqcheckdb to validate the database before a

backup and after a restore How to use Sybase IQ 15 Diagnostics stored procedures How to use the new Sybase IQ 15 SYSIQBACKUPHISTORY

and SYSIQBACKUPHISTORYDETAIL to investigate backup history

How to use dbbackup and the new Sybase IQ 15 Utility db_backupheader

Continued …

Page 45: Backup Restore

10 - 55

Module Summary Methodology for using technology provided by some SAN

manufacturers to "mirror" a Sybase IQ database which can be used in lieu of a full database backup

The shadow devices and files can be used to start an instance of IQ to perform maintenance tasks such as sp_iqcheckdb


Recommended