Saturday, November 11, 2017

Practical Tips I: Compressing Files

Quite often in a consulting scenario I'll find myself in a situation, particularly working for the government, where I'm dealing with tight constraints and need to find space. I remember when I was sitting on several gigabytes of archived logs going back 4 years. I think the oldest backup image datafile (yes, the client wasn't running RMAN) was maybe 6 months old (now, in practice, I've never gone past since my last usable backup, even for doing a clone or refresh of test or development), but the point is that even if the client wanted to clone the production database as of 7 months ago, I didn't have the necessary datafiles. But I couldn't get a client manager to give me the OK to purge 3.5 years of unusable archive logs.

In a recent situation, I needed to find enough space on my /u01 and /opt mountpoints to make the prerequisite storage requirements for running a major bundle patch. Here's one tip: look for audit files, something other DBA's don't realize until one day they find themselves facing a full file system. One source is to check your admin folders for adump, e.g., /u01/app/oracle/admin/[SID]/adump. If you're running on a grid (clusterware/RAC), also look for an audit directory off $GRID_HOME/rdbms.

So what do you do when you run into wildcard problems because you have too many files in your directory? (I'm assuming here that you are running on Linux or a Unix variant.)  I love to do DO LOOPs; there are a variety of things you can do (including moving files where you have more space), but if you delete files after zipping them, you should reclaim available space throughout the process. So, for example, assuming you are running in the audit file working directory

ls | while read fn
do
zip aud.zip $fn
rm $fn
done

Now there is a complication in Linux: what if you have say a file name preceded by a minus sign, e.g., like I've seen in grid audit files. A practical solution is to work "-- "" into the command syntax, e.g., ls -- *.aud

I'm a fan of using the job scheduler in OEM 12c. (I find the interface design somewhat quirky and non-intuitive to launch job creation off the bottom of the screen.)  Now one of the things I frequently like to is date-stamp a file (say, for instance I want to run a periodic [weekly] audit file sweep indicating the end of the audit file period), e.g.,

cd [audit file directory]
export zf=aud`date +%y%m%d`.zip
zip $zf    *.aud
rm *.aud


Now this script will not work (in my experience) through OEM job scheduler, and it has to do with the use of %. So what you want to do is to repeat the '%', e.g.,

export zf=aud`date +%%y%%m%%d`.zip