DB2: Comandos Backup e Restore: Difference between revisions

From Wiki
(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/ ===============...")
 
No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 2: Line 2:
== Comando Backup ==
== Comando Backup ==


  db2 "BACKUP DATABASE << db2_dbname >>"
  db2 "BACKUP DATABASE '''MYDB'''"


This will generate a file like B2BI.0.db2inst1.DBPART000.20240605211641.001
This will generate a file like MYDB.0.db2inst1.DBPART000.20240605211641.001
 
=== Error Msg: SQL1035N  The operation failed ...  SQLSTATE=57019 ===
 
1. Check Active Connections
 
db2 list applications for database BLUDB
 
2. Force Disconnect All Users
 
db2 force applications all
db2 terminate
 
3. Deactivate Database
 
db2 deactivate database BLUDB
 
4. Perform Backup
 
db2 "BACKUP DATABASE BLUDB ONLINE TO /mnt/backup COMPRESS"
 
for offline remove "ONLINE" parameter


== Comando Restore ==
== Comando Restore ==


  db2 "CREATE DATABASE << db2_dbname >> AUTOMATIC STORAGE YES USING CODESET UTF-8 TERRITORY US  
  db2 "CREATE DATABASE '''MYDB''' AUTOMATIC STORAGE YES USING CODESET UTF-8 TERRITORY US  
     COLLATE USING IDENTITY PAGESIZE 4096 DFT_EXTENT_SZ 32"
     COLLATE USING IDENTITY PAGESIZE 4096 DFT_EXTENT_SZ 32"


  db2 "RESTORE DATABASE << db2_dbname >> from /tmp into << db2_dbname >> without prompting"
  db2 "RESTORE DATABASE '''MYDB''' from /tmp into '''MYDB''' without prompting"


== Check backup file ==
== Check backup file ==
Line 20: Line 41:
  MEDIA HEADER REACHED:
  MEDIA HEADER REACHED:
  =====================
  =====================
  Server Database Name          -- B2BI
  Server Database Name          -- MYDB
  Server Database Alias          -- B2BI
  Server Database Alias          -- MYDB
  Client Database Alias          -- B2BI
  Client Database Alias          -- MYDB
  Timestamp                      -- 20240605211641
  Timestamp                      -- 20240605211641
  Database Partition Number      -- 0
  Database Partition Number      -- 0
Line 33: Line 54:
  ...
  ...
  The proper image file name would be:
  The proper image file name would be:
  B2BI.0.db2inst1.DBPART000.20240605211641.001
  MYDB.0.db2inst1.DBPART000.20240605211641.001
 


== Restore using redirect file ==
== Restore using redirect file ==
Line 40: Line 60:
You can use the "redirected" restore option by generating a file, using command:
You can use the "redirected" restore option by generating a file, using command:


  db2 restore database mydb redirect generate script restore.sql
  db2 restore database '''MYDB''' redirect generate script restore.sql


Once the script is generated, you can change the names, file locations, etc.
Once the script is generated, you can change the names, file locations, etc.
Line 47: Line 67:


  db2 -tvf restore.sql
  db2 -tvf restore.sql


== Ver também ==
== Ver também ==

Latest revision as of 20:28, 22 April 2026

Comando Backup

db2 "BACKUP DATABASE MYDB"

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

Error Msg: SQL1035N The operation failed ... SQLSTATE=57019

1. Check Active Connections

db2 list applications for database BLUDB

2. Force Disconnect All Users

db2 force applications all
db2 terminate

3. Deactivate Database

db2 deactivate database BLUDB

4. Perform Backup

db2 "BACKUP DATABASE BLUDB ONLINE TO /mnt/backup COMPRESS"

for offline remove "ONLINE" parameter

Comando Restore

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

Check backup file

 db2ckbkp -H /tmp/
=====================
MEDIA HEADER REACHED:
=====================
Server Database Name           -- MYDB
Server Database Alias          -- MYDB
Client Database Alias          -- MYDB
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:
MYDB.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