Professional Web Applications Themes

udb backup script - IBM DB2

HTH Sathyaram #!/bin/ksh db2owner=<instance-owner> # DB2 instance owner cd ~${db2owner} ./sqllib/db2profile for instances in `db2ilist` do . /export/home/${instances}/sqllib/db2profile db2 list database directory \ | nawk 'BEGIN { } { if ($1" "$2 == "Database name") { dbname=$NF } if ($1" "$2 == "Database alias") { dbalias=$NF } if ($1" "$2 == "Directory entry") { entrytype=$NF } if (entrytype == "Indirect") { if (dbname == dbalias) { print dbname } } } END { }' \ | sort -u \ | while read database do echo ${database} done # while read database.... done # for instances.... exit -- DB2 discussion also ...

  1. #1

    Default Re: udb backup script


    HTH

    Sathyaram

    #!/bin/ksh

    db2owner=<instance-owner> # DB2 instance owner

    cd ~${db2owner}
    ./sqllib/db2profile

    for instances in `db2ilist`
    do
    . /export/home/${instances}/sqllib/db2profile
    db2 list database directory \
    | nawk 'BEGIN {
    }
    {
    if ($1" "$2 == "Database name") {
    dbname=$NF
    }
    if ($1" "$2 == "Database alias") {
    dbalias=$NF
    }
    if ($1" "$2 == "Directory entry") {
    entrytype=$NF
    }
    if (entrytype == "Indirect") {
    if (dbname == dbalias) {
    print dbname
    }
    }
    }
    END {
    }' \
    | sort -u \
    | while read database
    do
    echo ${database}
    done # while read database....
    done # for instances....
    exit

    --
    DB2 discussion also at [url]http://www.dbforums.com/f8[/url]


    Posted via [url]http://dbforums.com[/url]
    sathyaram_s Guest

  2. #2

    Default Re: udb backup script

    How about

    db2 list active databases and grep for the database name

    HTH,
    Eric

    [email]uninfmx[/email] (dbtoo_dbtoo) wrote in message news:<90d22926.0307141054.4d281159posting.google. com>...
    > I am trying to write a standard backup script since we have many udb
    > instances on different servers (AIX). I do this right now:
    >
    > Db2 ?list db directory' | grep ?i alias to get the database name. Then
    > I use backup command in a loop to back up all the databases to TSM ?
    > works fine. I now have a different situation: how do I get the names
    > of databases that are local (i.e. Directory entry type = Indirect),
    > without using some heavy awk/sed programming.
    >
    > The ?list db directory' lists everything ? local and remote. I want
    > to be able to get only local databases. I don't think databases are
    > stored on any system tables/views ? are they?
    >
    > For instance, if I create a db called abc and catalog it with a
    > different name (say xyz) on the same server (don't know why anyone
    > wants to do this!) thru TCP/IP, the ?list db directory' command lists
    > both:
    > ABC = Indirect and XYZ = Remote (since XYZ database points to ABC).
    >
    > I want to back up just ABC (and get an error for XYZ even if I try to
    > and don't want to back up same database twice even if I can).
    >
    > (AIX5.1 UDB 7.2 FP9)
    >
    > Thanks.
    Eric Guest

  3. #3

    Default Re: udb backup script

    Hi,

    fyi

    I tried to use this code with awk (as opposed to nawk) and it gets the
    following database directory wrong as it prints the DBA Database which
    is remote? maybe just a awk/nawk difference or is this a bug in the
    code?

    ################################################## #####################
    db2jbsi3:(hardy) /home/db2jbsi3/dba_scripts/bin->db2 list db directory

    System Database Directory

    Number of entries in the directory = 4

    Database 1 entry:

    Database alias = JABSREP4
    Database name = REP4REST
    Local database directory = /home/db2jbsi3
    Database release level = a.00
    Comment =
    Directory entry type = Indirect
    Catalog database partition number = 0

    Database 2 entry:

    Database alias = DBA
    Database name = DBA
    Node name = HARDY1
    Database release level = a.00
    Comment =
    Directory entry type = Remote
    Catalog database partition number = -1

    Database 3 entry:

    Database alias = JBSREP5D
    Database name = JBSREP5D
    Local database directory = /home/db2jbsi3
    Database release level = a.00
    Comment =
    Directory entry type = Indirect
    Catalog database partition number = 0

    Database 4 entry:

    Database alias = REP4REST
    Database name = REP4REST
    Local database directory = /home/db2jbsi3
    Database release level = a.00
    Comment =
    Directory entry type = Indirect
    Catalog database partition number = 0
    ################################################## ####################

    Paul.
    Paul Reddin Guest

  4. #4

    Default Re: udb backup script

    You could use this syntax:

    for xx in `db2 list database directory | grep -p Indirect | grep
    alias | awk '{ print $4 }'`
    do
    db2 backup database $xx...."
    done

    HTH,
    Leo


    [email]paulabacus.co.uk[/email] (Paul Reddin) wrote in message news:<1fd2a603.0307160612.54b90aeaposting.google. com>...
    > Hi,
    >
    > fyi
    >
    > I tried to use this code with awk (as opposed to nawk) and it gets the
    > following database directory wrong as it prints the DBA Database which
    > is remote? maybe just a awk/nawk difference or is this a bug in the
    > code?
    >
    > ################################################## #####################
    > db2jbsi3:(hardy) /home/db2jbsi3/dba_scripts/bin->db2 list db directory
    >
    > System Database Directory
    >
    > Number of entries in the directory = 4
    >
    > Database 1 entry:
    >
    > Database alias = JABSREP4
    > Database name = REP4REST
    > Local database directory = /home/db2jbsi3
    > Database release level = a.00
    > Comment =
    > Directory entry type = Indirect
    > Catalog database partition number = 0
    >
    > Database 2 entry:
    >
    > Database alias = DBA
    > Database name = DBA
    > Node name = HARDY1
    > Database release level = a.00
    > Comment =
    > Directory entry type = Remote
    > Catalog database partition number = -1
    >
    > Database 3 entry:
    >
    > Database alias = JBSREP5D
    > Database name = JBSREP5D
    > Local database directory = /home/db2jbsi3
    > Database release level = a.00
    > Comment =
    > Directory entry type = Indirect
    > Catalog database partition number = 0
    >
    > Database 4 entry:
    >
    > Database alias = REP4REST
    > Database name = REP4REST
    > Local database directory = /home/db2jbsi3
    > Database release level = a.00
    > Comment =
    > Directory entry type = Indirect
    > Catalog database partition number = 0
    > ################################################## ####################
    >
    > Paul.
    Leo Guest

  5. #5

    Default Re: udb backup script


    On AIX, to get a list of all local databases in an instance:

    db2 list db directory | \
    grep -p 'Indirect' | \
    grep 'Database name' | \
    awk '{print $4}'


    This will work on AIX only (the '-p' option for grep is available on AIX,
    but nothing else that I have seen).








    -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
    [url]http://www.newsfeeds.com[/url] - The #1 Newsgroup Service in the World!
    -----== Over 80,000 Newsgroups - 16 Different Servers! =-----
    Ian D. Bjorhovde Guest

Similar Threads

  1. Help with backup script on DW site panel.
    By stevenlmas in forum Macromedia Exchange Dreamweaver Extensions
    Replies: 1
    Last Post: February 24th, 04:03 AM
  2. script to take backup
    By suhailh@yahoo.com in forum AIX
    Replies: 9
    Last Post: August 23rd, 09:50 AM
  3. HELP: SQL script to backup all databases
    By NoSpam in forum Microsoft SQL / MS SQL Server
    Replies: 1
    Last Post: July 9th, 07:26 PM
  4. Execute shell script from a perl script
    By kderaedt in forum Perl / CGI
    Replies: 3
    Last Post: June 26th, 08:26 PM
  5. loop - begin backup, end backup Oracle 8.1.7
    By Matthias Arth in forum Oracle Server
    Replies: 1
    Last Post: December 27th, 08:53 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139