Dumping data from DB2 database

Hello,

I need to check if a piece of data (a password) is present anywhere in a DB2 database. Seems like the easiest way to do that is to dump the database to plain text (similar to mysqldump) and then grep the resulting file. However I can't find any easy way to dump the whole database. Any suggestions?

I know how to dump individual tables with export command, however, since there are quite a lot of tables, it will take a while.

Alternatively if there is a way to a full text search on the whole database (all tables), this will solve my problem too.

Thanks.
LVL 3
gremwellAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kent OlsenData Warehouse Architect / DBACommented:
Hi Grem,

If you're on a *nix system you can run grep on the full backup.  The results won't be particularly meaningful, except for a pass/fail (yes/no) on the string occurring.  Using a regular expression will reveal if the exact string exists.  Otherwise, you'll get a "yes" if the string is a substring.

How many tables and about how much data do you have?  A bit of meta-sql go generate a query for all tables is pretty easy, but if could take quite a while to search the entire database!


Kent
0
Kent OlsenData Warehouse Architect / DBACommented:
If you're running LUW, the following code will generate the SQL to test the entire database.  If you have a lot of columns/data, this is probably not a good idea.

SELECT 
  'SELECT ''' || table_name || '.' || column_name || ''', count(*) FROM ' || rtrim (table_schema) || '.' ||
  table_name || ' WHERE ' || column_name || ' = ''{insert string here}'';'
FROM sysibm.columns
WHERE table_schema not like 'SYS%'
  AND data_type like 'CHAR%'
  AND character_maximum_length > 8
FETCH FIRST 10 rows only;

Open in new window


Replace {insert string here} with the string that you want to find.  In the next to last line, replace 8 with the length of the search string.  That will cause the search to skip columns too narrow to hold the target string.


Kent
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gremwellAuthor Commented:
Hello Kent,

Thanks for your comment. I have came up with a solution in a meantime. First I made a list of tables and dumped them to a file:
export to /tmp/tables.txt of del select tabname from syscat.tables where type='T' and owner='MYUSER';

Then I used the list to generate an SQL script that did
export to /tmp/dbdump/<tablename> of del select * from <tablename>
for each table

Then I ran the script with clpplus and grepped the resulting files.
0
Kent OlsenData Warehouse Architect / DBACommented:
Cool.  That should work fine.  

Remember to use the correct regex to search for the password or you could get a lot of false positives.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
DB2

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.