Translate

Saturday, 22 September 2012

Batch job for copying latest file and delete older file on network path

Hello everyone,
Today I am posting a scenario where user have to be copy and delete the files from local server to remote server on windows. And delete the older files (due to space issue) from remote server via manually.
Initially (when someone join the new organization) it is a most Favorited time pass job (the person who have nothing to do on his office) for him ;). But after a time it will become more boring and time consuming task (coz u have to login via mstc on main server and copy the file from mouse intelligent people may use CTRL+C and then open the share location and paste it).
So I am giving you a small script which will do this task for you either on single click or automatic ( by scheduling it in scheduler job).
So here are the steps for same...


Step 1. First you will create the network drive for the shared folder where you are moving or copying your   file. Because you are copying and moving so I am assuming that you have the write privs on it.

Crete the network drive for shared folder...
on command prompt type.

net use N: "<shared_location>"

Here N could be any alphabet which is represent the share location as a drive in my computer.

(In my case it like this - net use N: "\\192.168.1.1\Oracle\reports\cache")

Step 2: Now you can see the N: in my computer, through which you can directly go to the shared location.
            
            Now find the most recent file to copy from local server to remote location.

FOR /F "delims=" %%i IN ('DIR "<You_directory_path_for_copy>\*.*" /B /O:D') DO (SET NewestFile=%%i)

this command will find the most recent file either for current date or time.

Step 3: Now copy that file to remote server...

xcopy "<You_directory_path_for_copy>\%NewestFile%" "N:\"

here the path is same from which we need to copy the file to remote server and N: is the location for remote shared server.

Step 4: after copying this if you need to delete the old file from any location use this script. In my case i am deleting the file from remote location i.e. N: which is older then 7 days.

forfiles -p "N:" -s -m *.* -d -7 -c "cmd /c del @path"

Tadaaa... your new file is copied and oldest file has been deleted.Now you can put all these script in just one notepad file and save it as .bat extension. 


Thanks... :)









Friday, 21 September 2012

Database Upgrade from 9i to 10gR2


Database upgrade from 9i to 10g Release 2

This procedure describes the steps necessary to manually upgrade a database from 9.2.x to 10.2.x. It assumes that you have already installed 10g onto the server.Take a backup of your database before attempting any upgrade.

  • 1. Compile any invalid objects
@?/rdbms/admin/utlrp.sql
  • 2. Create a sysaux tablespace
Having a sysaux tablespace is a requirement in 10g. 
create tablespace sysaux
datafile '<file_name>' size 512M
extent management local
segment space management auto
/
  • 3. Run utlu102i.sql
This utility script checks that the database is ready to be upgraded to 10g. It also identifies any actions that need to be taken. The script is located in the 10g oracle home, so you will need to specify the full path to it.
@/u01/app/oracle/product/10.2.0/db_1/rdbms/admin/utlu102i.sql
Review the output and make any necessary alterations. Make a note of how many invalid objects there are.

  • 4. Shut the database down with either normal or immediate
shutdown immediate
  • 5. Copy the spfile (or pfile) and the password file from the existing home to the 10g one.
cp ${ORACLE_HOME}/dbs/*${ORACLE_SID}* <new_home>/dbs/
  • 6. Edit oratab
Alter /etc/oratab (or /var/opt/oracle/oratab) to point to the10g home. Once done, rerun oraenv to bring the alteration into effect.

  • 7. Upgrade the database
sqlplus "/ as sysdba"

startup upgrade
This next bit is the upgrade itself. It takes roughly half an hour to complete. Spool the output to a file so that you can review it afterward.
@?/rdbms/admin/catupgrd.sql
  • 8. Recompile any invalid objects
@?/rdbms/admin/utlrp.sql
Compare the number of invalid objects with the number noted in step 3. It should hopefully be the same or less.

  • 9. Then check the status of the upgrade
@?/rdbms/admin/utlu102s.sql
  • 10. Alter or remove initialisation parameters
Temporarily creating a pfile is the easiest way.
create pfile from spfile;

shutdown immediate

vi ${ORACLE_HOME}/dbs/init${ORACLE_SID}.ora
Alter/remove parameters identified in step 9. Set compatible to 10.2.0.0.0
startup

create spfile from pfile;

shutdown immediate

startup



Reference:  http://www.shutdownabort.com/quickguides/upgrade_9_to_10.php
(All the require steps are given in the above link. I did not make any changes in my blog)
               
Thanks...

Purging the log in Oracle application Server

Hi,

One of  a client site I have saw a scenario where App dba is purging the log file of oracle application report server by stopping the service and renaming the file on daily basis because of performance issue.

he did the same by early morning before the client start working.

If a day he'll be on leave or could not reach on time, then there will be a issue.

So I have make a batch file (because the app is running on windows environment) and schedule the same at the time when he wants to do the purging...


Here the steps for creating the batch file:


Step 1: In my case the oracle apps home was in E:\OracleAS\Oracle_Mid\. So I start the batch file by entering into E Drive.
open the notepad or any editor and type...

e: 

Step 2: Going to the opmn\bin directory in batch file...

cd OracleAS\Oracle_Mid\opmn\bin 


Step 3: Stop the process to which you want to perform the purging.

opmnctl stopproc ias-component=<Process_name> process-type=<Process_type>

(In my case it is  ias-component=OC4J process-type=FIN1 )

Step 4: now move to the Log directory which is actually contain the logfile that you want to purge..

cd ..\logs 

Step 5: Rename the file by adding the current date at the end of the file...
(There is a small script in MSDOS which will return you the current date in (DDMMYY) format)

rename OC4J~FIN1~1 OC4J~FIN1_%Date:~-7,2%%Date:~-10,2%%Date:~-2,4% 

Step 6: Now the move the file to some other backup folder (This step can b neglect). I made a directory named bkp in the logs folder and move the renamed file to that one. so that i can easily removed or find the appropriate file whenever require.

move  OC4J~FIN1_%Date:~-7,2%%Date:~-10,2%%Date:~-2,4%   bkp\ 

Step 7: Now start the process by going either bin directory or simply specified the full path in command prompt. (I used the first method )

cd ..\bin 

opmnctl startproc ias-component=<Process_name> process-type=<Process_type>


Stpe 8: save it as <name>.bat

Step 9: Schedule it on window scheduler at whatever time you want to perform the purging.