You are on page 1of 3

DB2 Baking up or restoring a database DB2 manager Db2 manager must be running before running the following code

and you must be the db2 admin. Note: In the following lines, you may have to replace "sample" and "/home/ sample" with whatever makes sense for your database and environment Open command prompt. C:\>db2cmd Enter DB2 command window opens And type db2 and enter in the DB2 command window And you will see something like this: C:\>db2 (c) Copyright IBM Corporation 1993,2007 Command Line Processor for DB2 Client 9.7.2 You can issue database manager commands and SQL statements from the command prompt. For example: db2 => connect to sample db2 => bind sample.bnd For general help, type: ?. For command help, type: ? command, where command can be the first few keywords of a database manager command. For example: ? CATALOG DATABASE for help on the CATALOG DATABASE command ? CATALOG for help on all of the CATALOG commands. To exit db2 interactive mode, type QUIT at the command prompt. Outside interactive mode, all commands must be prefixed with 'db2'. To list the current command option settings, type LIST COMMAND OPTIONS. For more detailed help, refer to the Online Reference Manual. db2 =>
Database Backup: Backup types: 1. Backup offline 2. Backup online. Backup is basically like taking a picture of your system and storing it into a file.

Now you may say why do I need to make sure that the database has no connections? Why did I need to force all connections? Well, there are two types of ways in which you can execute commands in DB2 for backup, for reorg, runstats etc. You can do a backup offline or a backup To backup the database, run all following commands preceded by db2:
Step1: db2 => CONNECT Step2: db2 => QUIESCE Step3: db2 => CONNECT Step4: db2 => RESTORE 20110503113107 TO SAMPLE

DATABASE IMMEDIATE FORCE CONNECTIONS RESET DATABASE SAMPLE FROM "/backups/sample" TAKEN AT

SQL2539W Warning! Restoring to an existing database that is the same as the backup image database. The database files will be deleted. Do you want to continue ? (y/n) y DB20000I The RESTORE DATABASE command completed successfully.

Step5: db2 => CONNECT TO sample Step6: db2 => UNQUIESCE DATABASE Step7:

db2 => CONNECT RESET To restore the database, run all following commands preceded by db2 (Replace 20091202115556 with the date and time the backup was made):
Step1:

db2 => CONNECT TO SAMPLE


Step2:

db2 => QUIESCE DATABASE IMMEDIATE FORCE CONNECTIONS


Step3: Step4:

db2 => CONNECT RESET db2 => RESTORE DATABASE SAMPLE FROM "/backups/sample" TAKEN AT 20110503113107 WITH 2 BUFFERS BUFFER 1024 PARALLELISM 1 WITHOUT PROMPTING

SQL2540W Restore is successful, however a warning "2539" was encountered during Database Restore while processing in No Interrupt mode. This is nothing - just means an SQL2539W which is just warning you are overwriting an existing db, if you hadn't specified WITHOUT PROMPTING you'd have seen this on the screen and would have had to answer YES to continue. (Refer for example Step4 of the backup) Step5:

db2 => CONNECT TO sample


Step6:

db2 => UNQUIESCE DATABASE


Step7:

db2 => CONNECT RESET

You might also like