SoFunction
Updated on 2025-04-14

Backup and recovery of DB2 databases

The db2 tutorial I am watching is: backup and recovery of DB2 database. Recently, I restored a database. The hard work in it is unexplained. I want to write some of the sentences I used to encourage each other with xdjm who encounter the same problems.
First, let’s talk about the backup of db2 database. I use the backup command.
db2 backup database database name (my library is jsdb)
I forgot to say that before backup, I need to stop the database you want to backup, I used db2stop force (the reason I used the force parameter is because it is easy to stop lazy and save trouble :) and db2start. This ensures that you can successfully backup.
After the backup is completed, db2 will tell you a timestamp, for example: 20040831 (there are several digits later). This will generate a folder name in the current directory with the same database name as your database name, for example: jsdb. This folder directory level is very important. If it is wrong, it will prompt that the file cannot be found during recovery.
After the backup is completed, it is restored. I used the restore command.
db2 restore database Database Name (jsdb)taken at timestamp (20040831)
There are two points to note when executing this statement: 1. You must take the backup folder to the current directory (I used a cd c:\ command to set the current directory as C drive, and take the jsdb folder to the root directory of the c drive); 2. The timestamp should be consistent with the jsdb directory.
In this way, the database recovery is completed.