GBASE数据库 | Detailed Guide to Using the ontape Tool for Backup and Recovery in GBase 8s Database

GBASE数据库 | Detailed Guide to Using the ontape Tool for Backup and Recovery in GBase 8s Database


GBase Database (GBase 数据库) Backup and Recovery Guide with ontape Tool

In today’s data-driven world, the security and reliability of databases are critical for any organization. Database backup and recovery are essential for ensuring data safety and preventing data loss. This article discusses how to use the ontape tool for database backup and recovery, including incremental backup, logical log backup, and full database recovery. Whether you’re a database administrator or an IT professional, this guide aims to provide helpful insights.



Overview of the ontape Tool

The ontape tool is a database backup and recovery utility supporting various backup types, including full backup, incremental backup, and logical log backup. It also allows recovery of the entire database system or specific dbspaces from backups. In addition to backups, ontape supports standard I/O operations such as file and pipe read/write. Some configuration file modifications are required before using ontape.



Configuration File Modifications

When using ontape for backup, you must specify the storage device, block size, and maximum capacity. The configuration is shown below. Here, TAPEDEV defines the storage device for system backup, while LTAPEDEV specifies the storage device for logical log backup.

[root@node1 hdr]# onstat -c | grep TAPE
Your evaluation license will expire on 2024-10-18 00:00:00
# TAPEDEV      - The tape device path for backups. To use standard
# TAPEBLK      - The tape block size, in KB, for backups
# TAPESIZE     - The maximum amount of data to put on one backup
#                positive integral multiple of TAPEBLK.
TAPEDEV /dev/null
TAPEBLK 32
TAPESIZE 0
# LTAPEDEV     - The tape device path for logical logs
# LTAPEBLK     - The tape block size, in KB, for backing up logical
# LTAPESIZE    - The maximum amount of data to put on one logical
#                positive integral multiple of LTAPEBLK.
LTAPEDEV         /home/hdr/backups
LTAPEBLK 32
LTAPESIZE 0
Enter fullscreen mode

Exit fullscreen mode

Explanation of Parameters:

Parameter Description
TAPEDEV Specifies the backup device path
TAPEBLK Sets the backup block size (KB)
TAPESIZE Sets the backup device size (KB)
LTAPEDEV Sets the logical log backup path
LTAPEBLK Sets the logical log block size
LTAPESIZE Sets the logical log device size

Modify parameters by editing the configuration file or using the onmode -wf command, as shown below:

[root@node1 hdr]# cd $GBASEDBTDIR
[root@node1 hdr]# mkdir backups
[root@node1 hdr]# chown gbasedbt:gbasedbt backups
[root@node1 hdr]# chmod 777 backups
[root@node1 hdr]# onmode -wf "TAPEDEV=$GBASEDBTDIR/backups"
Your evaluation license will expire on 2024-10-18 00:00:00
Value of TAPEDEV has been changed to /home/hdr/backups.
[root@node1 hdr]# onmode -wf "LTAPEDEV=$GBASEDBTDIR/backups"
Your evaluation license will expire on 2024-10-18 00:00:00
Current value for LTAPEDEV (/home/hdr/backups) was saved in config file.

[root@node1 hdr]#  onstat -c | grep TAPEDEV
Your evaluation license will expire on 2024-10-18 00:00:00
# TAPEDEV      - The tape device path for backups. To use standard
TAPEDEV          /home/hdr/backups
# LTAPEDEV     - The tape device path for logical logs
LTAPEDEV         /home/hdr/backups
Enter fullscreen mode

Exit fullscreen mode

When TAPEDEV is set to STDIO, database backups will use standard I/O output to the specified device.



Detailed ontape Backup Commands

The ontape command syntax provides multiple options for various backup and restore operations:

{ -a [-d]  |
  -c  |
  -l [-C | -X] [-d]  |
  -p [-e] [-rename {-f <filename> |
               -p <old path> -o <old offset> -n <new path> -o <new offset>...}]
     [-t tape_device_path [-v]] [-d]  |
  -S [-d]  |
  -r [-rename {-f <filename> |
               -p <old path> -o <old offset> -n <new path> -o <new offset>...}]
     [-D DBspace_list] [-t tape_device_path [-v]] [-d]  |
  -s [[-L archive_level][-F]] [-A database_list] [-B database_list]
     [-N database_list] [-U database_list] [-t tape_device_path [-v]] [-d]  }
Enter fullscreen mode

Exit fullscreen mode

Key Options:

  • -a Automatically back up logical logs
  • -c Continuously back up logical logs
  • -d Non-interactive mode for backing up or restoring from a directory
  • -l Logical restore
  • -p Physical restore (-e for external physical restore)
  • -r Complete recovery of listed DBspaces/BLOBspaces
  • -s Archive the entire system
  • -A Set the following databases to ANSI logging mode
  • -B Set the following databases to buffered logging mode
  • -C Continuous logical log recovery
  • -F Backup without updating archive information (useful for HDR, cloning, etc.)
  • -N Set the following databases to no-logging mode
  • -S Logical log recovery only (salvage mode)
  • -U Set the following databases to unbuffered logging mode
  • -X Complete continuous logical log recovery and place the server in quiescent mode
  • -rename Rename dbspaces during cold recovery
    with -rename options:

    • -f <filename> Pathname of the file containing the list of mapped dbspace paths and offsets
    • -p Old pathname of the dbspace
    • -o Old offset of the dbspace
    • -n New pathname of the dbspace
    • -o New offset of the dbspace
  • -t Set the tape device path for the current backup or restore. Use STDIO for backup to standard output or restore from standard input.
  • -v Write informational messages to standard error output



Example: ontape Backup Operation

When running the ontape -s command for a backup, the server prompts the user to specify the backup level and device. If the server cannot access the specified device, it will prompt for an available device.

[root@node1 hdr]# ontape -s
Your evaluation license will expire on 2024-10-18 00:00:00
Please enter the level of archive to be performed (0, 1, or 2) 0
100 percent done.
File created: /home/hdr/backups/node1_199_L0

Please label this tape as number 1 in the arc tape sequence.
This tape contains the following logical logs:

4

Program over.
Enter fullscreen mode

Exit fullscreen mode



Modifying Database Log Recording Mode

Use ontape options -A, -B, -N, and -U to modify database log modes:

$> ontape -s -B # Buffered log mode
$> ontape -s -U # Unbuffered log mode
$> ontape -s -N # No log mode
$> ontape -s -A # ANSI logging mode (irreversible, use with caution)



ontape Logical Log Backup

  • The -a option backs up all unarchived logical logs.
  • The -c option performs automatic backup when logical logs are full, requiring ontape to be running continuously with a dedicated device for storage.
[root@node1 hdr]# ontape -a
Your evaluation license will expire on 2024-10-18 00:00:00

Performing automatic backup of logical logs.

File created: /home/hdr/backups/node1_199_Log0000000001
File created: /home/hdr/backups/node1_199_Log0000000002
File created: /home/hdr/backups/node1_199_Log0000000003
Do you want to back up the current logical log? (y/n) y
File created: /home/hdr/backups/node1_199_Log0000000004

Program over.
Enter fullscreen mode

Exit fullscreen mode



Hot Recovery with ontape

Hot restore can be performed when the server is in online mode, and the rootdbs or dbspace containing logical logs does not need to be restored. For instance, if the disk containing dbs2 fails, and dbs2 does not contain logs or is not rootdbs, hot restore can be used to recover dbs2. Begin by restoring the level 0, 1, and 2 backups of dbs2 through physical recovery, followed by a logical log replay up to the failure point.

Create dbs2:

[root@node1 tmp]# cd $GBASEDBTDIR/tmp
[root@node1 tmp]# touch dbs2
[root@node1 tmp]# chown gbasedbt:gbasedbt dbs2
[root@node1 tmp]# chmod 660 dbs2
[root@node1 tmp]# onspaces -c -d dbs2 -p $GBASEDBTDIR/tmp/dbs2 -o 0 -s 20000
Your evaluation license will expire on 2024-10-18 00:00:00
Verifying physical disk space, please wait ...
Space successfully added.

** WARNING **  A level 0 archive of Root DBSpace will need to be done.
Enter fullscreen mode

Exit fullscreen mode

Perform Level 0 Backup:

[root@node1 tmp]# ontape -s
Your evaluation license will expire on 2024-10-18 00:00:00
Please enter the level of archive to be performed (0, 1, or 2) 0
100 percent done.
File created: /home/hdr/backups/node1_199_L0

Please label this tape as number 1 in the arc tape sequence.
This tape contains the following logical logs:

 5

Program over.
Enter fullscreen mode

Exit fullscreen mode

Manually delete the dbs2 file to simulate failure. Prepare for recovery by recreating the dbs2 file and setting permissions:

[root@node1 tmp]# rm -rf dbs2
[root@node1 tmp]# touch dbs2
[root@node1 tmp]# chown gbasedbt:gbasedbt dbs2
[root@node1 tmp]# chmod 660 dbs2
[root@node1 tmp]# ll dbs2
-rw-rw---- 1 gbasedbt gbasedbt 0 Sep 15 13:13 dbs2
Enter fullscreen mode

Exit fullscreen mode

Using ontape to restore dbs2. If the dbs to be restored is in online mode, ontape will first switch it to offline mode, then display the backup file information for user confirmation before proceeding with the restore. After completing level 0, 1, and 2 backups, ontape will continue with a logical backup. When the entire restore process is finished, ontape will bring the dbs back to online mode.

[root@node1 tmp]# ontape -r -D dbs2
Your evaluation license will expire on 2024-10-18 00:00:00
DBspace 'dbs2' is online; restoring 'dbs2' will bring all chunks
comprising the DBspace OFFLINE and will terminate all active
transactions and queries accessing the DBspace.

OK to continue?y
Restore will use level 0 archive file /home/hdr/backups/node1_199_L0. Press Return to continue ...


Archive Tape Information

Tape type:      Archive Backup Tape
Online version: GBase Database Server Version 12.10.FC4G1TL
Archive date:   Sun Sep 15 13:10:12 2024
User id:        root
Terminal id:    /dev/pts/1
Archive level:  0
Tape device:    /home/hdr/backups/
Tape blocksize (in k): 32
Tape size (in k): system defined for directory
Tape number in series: 1
Continue restore? (y/n)y

Spaces to restore:1 [dbs2]
Restore a level 1 archive (y/n) y
Ready for level 1 tape
Restore will use level 1 archive file /home/hdr/backups/node1_199_L1. Press Return to continue ...


Archive Tape Information

Tape type:      Archive Backup Tape
Online version: GBase Database Server Version 12.10.FC4G1TL
Archive date:   Sun Sep 15 13:10:20 2024
User id:        root
Terminal id:    /dev/pts/1
Archive level:  1
Tape device:    /home/hdr/backups/
Tape blocksize (in k): 32
Tape size (in k): system defined for directory
Tape number in series: 1
Restore a level 2 archive (y/n) n
Do you want to restore log tapes? (y/n)y

Roll forward should start with log number 5
Restore will use log backup file /home/hdr/backups/node1_199_Log0000000005. Press Return to continue ...

File /home/hdr/backups/node1_199_Log0000000005 not found, continuing ...
Recommendation: continue the warm restore until  log 5 is replayed.
The last log that has been restored is: 0. If you want to stop the
restore at this log, choose commit, otherwise, choose suspend.
If you have not performed a backup that includes the log 5,
perform a backup using the ontape -a command. Continue the suspended
log restore using the ontape -l command.
Do you want to suspend (y), commit (n) or abort (CTRL/C) logical restore?
y

Program over.
Enter fullscreen mode

Exit fullscreen mode

At this point, dbs2 has been successfully restored. Once restoration is complete, the database will enter Quiescent mode, and you can switch it to online mode using onmode -m.



Cold Recovery with ontape

When the server cannot start, or when restoring rootdbs or a dbs containing logical logs, a cold restore is required.

To perform a cold restore, first shut down the database, then execute the ontape -r command.

[root@node1 tmp]# ontape -r
Your evaluation license will expire on 2024-10-18 00:00:00
Restore will use level 0 archive file /home/hdr/backups/node1_199_L0. Press Return to continue ...


Archive Tape Information

Tape type:      Archive Backup Tape
Online version: GBase Database Server Version 12.10.FC4G1TL
Archive date:   Sun Sep 15 13:10:12 2024
User id:        root
Terminal id:    /dev/pts/1
Archive level:  0
Tape device:    /home/hdr/backups/
Tape blocksize (in k): 32
Tape size (in k): system defined for directory
Tape number in series: 1

Spaces to restore:1 [rootdbs]
2 [dbs2]

Archive Information

GBase Database Server Copyright 2001, 2021  General Data Corporation
Initialization Time       09/15/2024 09:56:33
System Page Size          2048
Version                   32
Index Page Logging        OFF
Archive CheckPoint Time   09/15/2024 13:07:59

Dbspaces
number   flags     fchunk   nchunks  flags     owner                            name
1        60001    1         1        N  BA     gbasedbt                          rootdbs                                                                      
2        60001    2         1        N  BA     gbasedbt                          dbs2                                                                        


Chunks
chk/dbs offset   size     free      bpages   flags pathname
1   1    0        10240000 5059090           PO-B- /home/hdr/gbase001_dbs/rootdbs
2   2    0        10000    9947               PO-B- /home/hdr/tmp/dbs2

Continue restore? (y/n)y
Do you want to back up the logs? (y/n)y
File created: /home/hdr/backups/node1_199_Log0000000005
Log salvage is complete, continuing restore of archive.
Your evaluation license will expire on 2024-10-18 00:00:00
Restore a level 1 archive (y/n) n
Do you want to restore log tapes? (y/n)y

Roll forward should start with log number 5
Restore will use log backup file /home/hdr/backups/node1_199_Log0000000005. Press Return to continue ...

Rollforward log file /home/hdr/backups/node1_199_Log0000000005 ...

Program over.
Enter fullscreen mode

Exit fullscreen mode

The cold restore process is generally similar to hot restore. Upon completion of ontape -r in cold restore, the dbspace containing rootdbs and logical logs will also be restored.



Using STDIO Standard Input and Pipe Output

ontape also supports standard input and pipe output by configuring the TAPEDEV parameter to STDIO, or specifying -t STDIO in the command line to use a pipe. Since read or write actions will be directly forwarded to the UNIX pipe, any UNIX command can be used to process the data.

When using STDIO, there will be no interactive prompts, so you’ll need to specify the backup level directly in the command line for backup, and list each restoration level’s files for restore. Below are three examples using STDIO.

Sequential Level 0 and Level 1 Restorations:

[root@node1 tmp]# cat $GBASEDBTDIR/backups/backupFile 
> $GBASEDBTDIR/backups/backupFile0 | ontape -r
Enter fullscreen mode

Exit fullscreen mode

Backup:

[root@node1 backups]# ontape -s -L 0 | compress > node1_ontape_0
Your evaluation license will expire on 2024-10-18 00:00:00
[root@node1 backups]# chown gbasedbt:gbasedbt node1_ontape_0
[root@node1 backups]# chmod 660 node1_ontape_0           
[root@node1 backups]# ll node1_ontape_0
-rw-rw---- 1 gbasedbt gbasedbt 179 Sep 15 13:43 node1_ontape_0
Enter fullscreen mode

Exit fullscreen mode

Recovery:

[root@node1 backups]# zcat node1_ontape_0 | ontape -r
Your evaluation license will expire on 2024-10-18 00:00:00
Restore will use level 0 archive file /home/hdr/backups/node1_199_L0. Press Return to continue ...

Archive Tape Information

Tape type:      Archive Backup Tape
Online version: GBase Database Server Version 12.10.FC4G1TL
Archive date:   Sun Sep 15 13:43:04 2024
User id:        root
Terminal id:    /dev/pts/1
Archive level:  0
Tape device:    /home/hdr/backups/
Tape blocksize (in k): 32
Tape size (in k): system defined for directory
Tape number in series: 1
Continue restore? (y/n)
Enter fullscreen mode

Exit fullscreen mode

Backing up and restoring the database is essential to ensure data safety. This guide provides a comprehensive overview of using the ontape tool for database backup and restore. Whether you need regular backups or are dealing with emergency data recovery, ontape offers reliable support. Secure your data by mastering effective backup and recovery techniques.


The above covers some practical tips with GBase Database (GBase 数据库). If you’re interested in learning more about GBase Database, feel free to follow our related technical articles.



Source link
lol

By stp2y

Leave a Reply

Your email address will not be published. Required fields are marked *

No widgets found. Go to Widget page and add the widget in Offcanvas Sidebar Widget Area.