Link to home
Start Free TrialLog in
Avatar of Raf
Raf

asked on

Shell Script on AIX

Hi,
I'm trying to make a bash script (oslevel = AIX 7100-04-02-1614) that's going to restore my DB2 database from an existing backup into a different database (DB2PRD3 - DB2PRD4)

below are the steps that I perform manually:

cd /backup/

ls
DB2PRD3.0.2016111815.001

db2 list applications | grep DB2PRD4

DB2_DB21 xxxxxxxxxxx.ex 16723      172.16.105.999.18428.1612021058                                DB2PRD4     1
DB2_DB21 yyyyyyyyyyyyyy 583        172.16.105.999.63207.1612011334                                DB2PRD4     1

db2 "force application (16723,583)"

db2 deactivate database DB2PRD4

db2 restore database DB2PRD3 from /db2_tbsp/backup taken at 2016111815 to /db2_tbsp into DB2PRD4  

SQL2528W  Warning!  Restoring to an existing database that is the same as the
backup image database, but the alias name "DB2PRD4" of the existing database does
not match the alias "DB2PRD3" of backup image, and the database name "DB2PRD4" of
the existing database does not match the database name "DB2PRD3" of the backup
image.  The target database will be overwritten by the backup version.
Do you want to continue ? (y/n) y
SQL2563W  The restore process has completed successfully, but one or more
table spaces from the backup were not restored.

db2 connect to DB2PRD4

drop tablespace TEMPSPACE32K
db2 "CREATE SYSTEM TEMPORARY TABLESPACE TEMPSPACE32K PAGESIZE 32 K MANAGED BY SYSTEM USING ('/db2/DB2PRD4/T0000999/C0000000.TMP') EXTENTSIZE 32 BUFFERPOOL DB2_32K_BP FILE SYSTEM CACHING"
db2 connect reset
db2 activate database DB2PRD4


Have you any idea how I can automate these commands with a bash script on AIX 7100-04-02-1614?

Thanks in advance!
Avatar of gheist
gheist
Flag of Belgium image

You did not post bash version. What technical reasons keeps you away from default korn shell?
Avatar of Raf
Raf

ASKER

bash-4.3$ echo $BASH_VERSION
4.3.30(1)-release
Just put command sequence you posted row by row in a file?
I do not see any need for any sort of logic in script yet.
Avatar of Raf

ASKER

Gheist,
I believe that the logic in the script is required, for example I've the backup: DB2PRD3.0.2016111815.001:

DB_DIR="/db2_tbsp/backup"
MYDB="DB2PRD3"
DBTIMESTAMP="$(ls -rt $DB_DIR/$MYDB* | tail -1 | rev | cut -d "." -f2 | rev)"

db2 restore database $MYDB from $DB_DIR taken at $DBTIMESTAMP to /db2_tbsp into DB2PRD4 without prompting
RESTORE DATABASE WHATEVER INTO OTHER WITHOUT PROMPTING;
It will rewrite target if exists.
ASKER CERTIFIED SOLUTION
Avatar of Tomas Helgi Johannsson
Tomas Helgi Johannsson
Flag of Iceland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
the problem is prompt in DB2 CLI.... It is just DB2 syntax diagram missing.