01 April, 2015

Quick Unix / Linux commands reference

1. To zip the file using gunzip :
tar cvf - export_from_agprd_schema.dmp | gzip > export_from_agprd_schema.dmp.04012015.tar.gz

2. To find the delpoy* files with the age of more than 3 days and move it to a directory 

example : 
find /usr/sap/NPQ/J00/work/deploy* -mtime +3 -type f -exec mv "{}" /usr/sap/NPQ/J00/work/neel_test/ \; 

3. top CPU, memory consuming process on RHEL:  
ps aux --sort -rss  --> user friendly ; the below shows the process in detail . 
ps -eo pmem,pcpu,vsize,pid,cmd | sort -k 1 -nr | head -20

4. top disk space consuming directories and files 
du - xak <path> | sort -rn | head -20

5. copy the files with a modified time stamp to a different directory:

find . -mtime 8 -type f -exec cp {} /dd890/orabackup/Dev-Test/Donot_Remove/DSNPR/ \;

6. Uncompress the tgz file:

tar -xzvf <filename>.tgz
tar -xzvf <filename>.TGZ

7. killing the processing with a pattern

kill -9 `ps -ef | grep /usr/sap/hostctrl/exe/sapdbctrl | grep -v grep | cut -c10-15`

8. Find if the Linux server is a VM or physical ? 

dmesg |grep -i hypervisor  --> shows if it is a VM and is built with hypervisor. 

dmidecode -t system|grep 'Manufacturer\|Product' --> shows the Manufacturer and Product Name details :

eg:
1. root@hq-agtest1 ~]# dmidecode -t system|grep 'Manufacturer\|Product'
        Manufacturer: Dell Inc.
        Product Name: PowerEdge R720     ===> physical 


2. [root@hq-agsbx ~]# dmidecode -t system|grep 'Manufacturer\|Product'
        Manufacturer: Red Hat
        Product Name: RHEV Hypervisor    ===> virtual 


9. Find the files created after a date in unix / linux system 

find ./BIParch1* -type f -newermt 'Dec 16 13:14';

10. recursive search of a string within the files across the system from root path. 

grep -Ril "9001" /u01/home/oracle/Agile | more

11. understanding the CUP stats - 
https://www.tecmint.com/understand-linux-load-averages-and-monitor-performance/

12. delete older than number of days files 

find /almdata/almlogs/sa/SaServerLog* -mtime +90 -exec rm -rf {} \;
 
 

13. port in use on linux server to find - 
sudo netstat -tunlp | grep <port number>

How to export the dump file for the Oracle database


How to export the dump file for the Oracle database:


Here is the easy and simple instructions and steps in exporting the dump file:
Command is : expdp parfile=export.par
where as my script file contents for export.par as below:

userid=agile/<PASSWORD>
schemas=<schema name>
logfile=EXP_DIR_AGILE:export_from_<SID>_schema.log
dumpfile=EXP_DIR_AGILE:export_from_<SID>_schema.dmp
FLASHBACK_TIME=systimestamp
EXCLUDE=STATISTICS

SQL query to list the DB directories: The database directories for the export can be found from SQL command at ORACLE database as below:

SELECT owner, directory_name, directory_path FROM all_directories; 


If we need to create one , create with the below syntax:
  create directory <DIR> as '<PATH';


make sure to give the grants to the schema user that is going to run to export the schema with sys dba. 

   grant read,write on directory DIR to DSXN_CMS;

More information about uploading the dump file to the Oracle support is available at 
https://support.oracle.com/epmos/faces/DocContentDisplay?_afrLoop=315317654246873&id=1547088.2&_afrWindowMode=0&_adf.ctrl-state=1299xos1m1_388

++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
Alternative method:
export_table.sh script is below: run it like:

csh exp.WEBP_table.csh WEBP traintrack /u01/home/oracle/product/11.2.0/dbhome_1 SKILLS_ASSESSMENT_SUBMISSION

 #!/bin/csh

setenv SID $1
setenv ORACLE_SID $1
setenv OWNERS $2
setenv DATA_PUMP_DIR /u02/exports/$SID
setenv ORACLE_HOME $3
setenv table $4
set now=`date +"%m-%d-%y"`
#export by list of schemas
$ORACLE_HOME/bin/expdp traintrack/h0tsp0t dumpfile=DATA_PUMP_DIR:exp_from_${SID}_${OWNERS}_$table logfile=DATA_PUMP_DIR:exp_from_{$SID}_{$OWNERS}_$table tables=$table

#remove the previous one
#rm $DATA_PUMP_DIR/exp_from_{$SID}_$OWNERS.dmp.gz

#compress it
###gzip $DATA_PUMP_DIR/exp_from_{$SID}_$OWNERS.dmp
###mv /u02/export/DSNPR/exp_from_{$SID}_$OWNER.log /dd890/orabackup/Dev-Test/DataPump/DSNPR/exp_from_{$SID}_{$OWNERS}_$now.log
###mv /u02/export/DSNPR/exp_from_{$SID}_$OWNERS.dmp.gz /dd890/orabackup/Dev-Test/DataPump/DSNPR/exp_from_{$SID}_{$OWNERS}_$now.dmp.gz

###find /dd890/orabackup/Dev-Test/DataPump/DSNPR/exp_from_* -mtime +10 -type f -exec rm "{}" \;



+++++++++++++++++++++++++++++++++++++++++++++++++++++++
 script import_table.sh is below : run it like
csh imp.WEBP_table.csh WEBP traintrack_sfdc /u01/home/oracle/product/11.2.0/dbhome_1 SKILLS_ASSESSMENT_SUBMISSION


#!/bin/csh
setenv SID $1
setenv ORACLE_SID $1
setenv OWNERS $2
setenv DATA_PUMP_DIR /u02/exports/$SID
setenv ORACLE_HOME $3
setenv table $4
set now=`date +"%m-%d-%y"`
#export by list of schemas
####$ORACLE_HOME/bin/impdp rman/cat dumpfile=DATA_PUMP_DIR:exp_from_${SID}_$OWNERS logfile=DATA_PUMP_DIR:imp_from_{$SID}_$OWNERS.log

#$ORACLE_HOME/bin/impdp \'/ AS SYSDBA\' tables=$table dumpfile=DATA_PUMP_DIR:exp_from_WEBP_traintrack_SKILLS_ASSESSMENT_SUBMISSION.dmp logfile=DATA_PUMP_DIR:imp_for_WEBP_traintrack_$table.log remap_schema=traintrack:traintrack_sfdc REMAP_TABLESPACE=traintrack:traintrack_sfdc

$ORACLE_HOME/bin/impdp \'/ AS SYSDBA\' tables="traintrack"."SKILLS_ASSESSMENT_SUBMISSION" dumpfile=DATA_PUMP_DIR:exp_from_WEBP_traintrack_SKILLS_ASSESSMENT_SUBMISSION.dmp logfile=DATA_PUMP_DIR:imp_for_WEBP_traintrack_$table.log remap_schema=traintrack:traintrack_sfdc REMAP_TABLESPACE=traintrack:traintrack_sfdc


+++++++++++++++++++++++++++++++++++++++++++++++++++++++++


for schema:
Export: 
$ORACLE_HOME/bin/expdp traintrack/h0tsp0t dumpfile=DATA_PUMP_DIR:exp_from_${SID}_$OWNERS logfile=DATA_PUMP_DIR:exp_from_{$SID}_$OWNERS flashback_time=\"TO_TIMESTAMP\(TO_CHAR\(SYSDATE,\'YYYY-MM-DD HH24:MI:SS\'\),\'YYYY-MM-DD HH24:MI:SS\'\)\" EXCLUDE=STATISTICS schemas=$OWNERS

Import:
$ORACLE_HOME/bin/impdp \'/ AS SYSDBA\' dumpfile=DATA_PUMP_DIR:exp_from_WEBP_traintrack.dmp logfile=DATA_PUMP_DIR:imp_for_WEBP_traintrack_sfdc.log remap_schema=traintrack:traintrack_sfdc REMAP_TABLESPACE=traintrack:traintrack_sfdc