The following articles mainly describe the commonly used backups, recovery commands, and correct use of DB2move in DB2 databases. The following are commonly used backups in DB2 databases, A detailed description of the recovery command and the correct use of DB2move. We hope you will have a better understanding of it after browsing.
DB2 commands
DB2 offline and online full backup, Incremental backup and recovery operations
1. Full offline backup
1) first, make sure that no user uses DB2:
- $DB2 list applications for db sample
2) Stop the database and restart it to disconnect all connections:
- DB2stop force
- DB2start
3) execute the BACKUP command: Use TSM as the backup media)
- DB2 backup db sample use tsm
If the backup is successful, a timestamp is returned.
4) check that the backup is successful:
DB2 list history backup all for sample. You can see that this backup record is missing.
The return value can also be seen in the DB2adutl query command.
5) Remarks:
First, execute the BACKUP command on the nodes where the catalog tablespace is located on the master node, and then perform this operation on other nodes.
2. Online backup:
1) First, open the database configuration parameters that support online backup:
DB2 update db cfg for sample using userexit on Enable User exit
DB2 update db cfg for sample using logretain on enable archiving logs
DB2 update db cfg for sample using trackmod on enable Incremental Backup
(Each Node must be set separately)
After these parameters are enabled, the database is in the backup pending state and requires offline full backup of the database. Perform full offline backup. Refer to the above command.
2) The online backup command is as follows:
- DB2 backup db sample online use tsm
If the backup is successful, a timestamp is returned.
3) You can also use the DB2 database adutl and DB2 list history to view the backup records.
4) Remarks:
Similarly, this operation is performed on each node.
3. Online Incremental Backup
1) when three required parameters are enabled, perform Incremental Backup:
- DB2 backup db sample online incremental use tsm
If the backup is successful, a timestamp is returned.
2) You can also use DB2adutl and DB2 list history to view backup records.
3) There is also a delta backup:
- DB2 backup db sample online incremental delta use tsm
The difference between the two backups is similar to the Incremental and Cumulative modes of Oracle Exports. The incremental method of DB2 corresponds to the cumulative mode of oracle, while the delta mode of DB2 corresponds to the incremental mode of oracle.
4) Remarks:
Similarly, this operation is performed on each node.
4. Restore the database
1) manually drop the database to simulate disaster recovery. perform the following operations:
- DB2 drop db sample
2) restore the backup history every time, regardless of the type, the history file will be backed up ). The timestamp here should be the latest:
- DB2 restore db sample history file use tsm taken at 20030102223107 buffer 100
3) use the DB2 recovery help tool:
- DB2ckrst -d sample -t 20030101224424 -r database
Command to return the recommended required recovery operation command.
4) follow the prompts of the help tool to restore the version first. The recovery command is as follows:
- DB2 restore db sample incremental use tsm taken at 20030101224424 buffer 100
Recover the master node and other nodes.
5) when the database is in the rollforward-pending state, you need to perform the roll forward operation:
- DB2 rollforward db sample to 2003-01-12-13.27.25.000000 on all nodes and stop
Roll to the same time point. This operation must be performed on the master node.
5. Instructions:
1) recovery operations also have online and offline operations, just like backup operations.
2) Add the TABLESPACE (tablespace-name) clause to perform similar backup and recovery based on the TABLESPACE. Tablespace-level backup/recovery operations require that the database be in the archive log and Incremental backup mode.
3) In the recovery example, only version recovery is performed. If there is an updated full backup and Incremental backup image, you can perform the recovery in sequence. Note that the recommended recovery sequence and number of times are used for the DB2 database ckrst.
- DB2 force applications all
- DB2 backup db ldapDB2 to directory_or_device
DB2 restore db ldapDB2 from directory_or_device replace existing where directory_or_device is the name of the directory or device that stores the backup.
- Migrate windows to linux:
- DB2move tfms export;
- Create db tfms;
- DB2move tfms-u-p import> a.txt;
- DB2move tfmsw179 import-u DB2admin-p DB2admin> a.txt
Confirm execution: TERMINATE
6. Restore the database
(1) first create an empty Database: DB2 create db NewdbName
(2) DB2 restore olddbName (database name to be restored) taken at Times (Time Point) into NewdbName (new database name)
Note: The name of the recovered database is the same as that of the newly created database.
My own applications:
Export data:
1: Run DB2CMD in DOS
2: Create a New CMS folder on disk D and CD it to the CMS directory in DOS of DB2CMD.
3: Run DB2move to back up the database name export-u username-p Password
4: Successful
Export data:
1: Build an empty database default buffer pool and tablespace size in the DB2 database console set up to 32 K big point, code set UTF-8)
2. Select a folder such as cms on disk D.
3: Run DB2move test import-u username-p Password