DB2: Comandos Backup e Restore

From Wiki
Revision as of 18:03, 1 July 2024 by Ebasso (talk | contribs) (Created page with " == Comando Backup == db2 "BACKUP DATABASE << db2_dbname >>" This will generate a file like B2BI.0.db2inst1.DBPART000.20240605211641.001 == Comando Restore == db2 "CREATE DATABASE << db2_dbname >> AUTOMATIC STORAGE YES USING CODESET UTF-8 TERRITORY US COLLATE USING IDENTITY PAGESIZE 4096 DFT_EXTENT_SZ 32" db2 "RESTORE DATABASE << db2_dbname >> from /tmp into << db2_dbname >> without prompting" == Check backup file == db2ckbkp -H /tmp/ ===============...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Comando Backup

db2 "BACKUP DATABASE << db2_dbname >>"

This will generate a file like B2BI.0.db2inst1.DBPART000.20240605211641.001

Comando Restore

db2 "CREATE DATABASE << db2_dbname >> AUTOMATIC STORAGE YES USING CODESET UTF-8 TERRITORY US 
    COLLATE USING IDENTITY PAGESIZE 4096 DFT_EXTENT_SZ 32"
db2 "RESTORE DATABASE << db2_dbname >> from /tmp into << db2_dbname >> without prompting"

Check backup file

 db2ckbkp -H /tmp/
=====================
MEDIA HEADER REACHED:
=====================
Server Database Name           -- B2BI
Server Database Alias          -- B2BI
Client Database Alias          -- B2BI
Timestamp                      -- 20240605211641
Database Partition Number      -- 0
Instance                       -- db2inst1
Database Configuration Type    -- 0 (Non-shared data)
Sequence Number                -- 1
Database Member ID             -- 0
Release ID                     -- 0x1500 (DB2 v11.5.9.0)
AL version                     -- V:11 R:5 M:9 F:0 I:0 SB:0
...
The proper image file name would be:
B2BI.0.db2inst1.DBPART000.20240605211641.001
 

Restore using redirect file

You can use the "redirected" restore option by generating a file, using command:

db2 restore database mydb redirect generate script restore.sql

Once the script is generated, you can change the names, file locations, etc.

And finally, execute the script

db2 -tvf restore.sql


Ver também