Friday, December 25, 2015

Backup Full Database 12c Script

Task 1: Preparing to Use the Oracle Suggested Backup Strategy

To use the Oracle suggested backup strategy, ensure that:

  The database is ARCHIVELOG mode
 The fast recovery area size is configured, or a default device for storing backups is configured.
 You have added a database host user to the OSBACKUPUPDBA operating system group, for operating system authentication.

Task 2: Create the Backup full Script-UNIX and Linux

[oracle@SERVER_DATABASE rman]$ pwd
/u01/app/oracle/rman_backup
[oracle@SERVER_DATABASE rman]$ more backup_script_full.sh
#!/bin/bash
ORACLE_HOME=/u01/app/oracle/product/12.1.0.2/db_1;export ORACLE_HOME
ORACLE_SID=orcl; export ORACLE_SID
PATH=$PATH:$ORACLE_HOME/bin; export PATH

chk_date=`date +%d`
chk_parity=`expr $chk_date % 2`

export bkdir=/backup11
BACKUP_DIR=$bkdir; export BACKUP_DIR
export DATA_DIR=$BACKUP_DIR/backup_full
export ARC_DIR=$BACKUP_DIR/backup_full
export BACKUP_DATA=$DATA_DIR/$ORACLE_SID"_data_f%t_s%s_s%p"
export BACKUP_ARC=$ARC_DIR/$ORACLE_SID"_arc_f%t_s%s_s%p"
export ORACLE_OWNER=oracle
export DATE=`date +%Y%m%d`
export IP=168_133

########### SCRIPT CHECK BACKUP FAILED############
backup_log_err='/u01/app/monitoring/log/backup_log.err';
backup_log_finish='/u01/app/monitoring/log/backup_log.finish';

/usr/bin/ls -lt /u01/app/rman_backup/log_full > $list_file;
i=1
while read line
do
 let i=$i+1;
 if [ $i -gt 2 ]
 then
  backup_log='/u01/app/rman_backup/log_full/'`echo $line | awk '{print $9}'`;
   break;
  fi
done < "$list_file"

  grep -i error $backup_log > $backup_log_err

  grep "Recovery Manager complete" $backup_log > $backup_log_finish
       
  if [ `cat $backup_log_err|wc -l` -gt 0 ]
    then
        echo 'Backup have error';
        exit;
  fi

  if [ !`cat $backup_log_finish|wc -l` -gt 0 ]
    then
        echo 'Backup have not finished yet';
        exit;
  fi
#######################################

cd $BACKUP_DIR
rm -rf backup_full_*
mv backup_full backup_full_$DATE
mkdir -p $DATA_DIR
mkdir -p $ARC_DIR


$ORACLE_HOME/bin/rman target / log /u01/app/rman_backup/log_full/rman_backup_full_$IP"_"$DATE.log <<EOF
RUN {
CROSSCHECK BACKUP OF DATABASE;
CROSSCHECK ARCHIVELOG ALL;
BACKUP AS COMPRESSED BACKUPSET FORMAT '$BACKUP_ARC' ARCHIVELOG ALL DELETE INPUT;
BACKUP AS COMPRESSED BACKUPSET FORMAT '$BACKUP_DATA' DATABASE SKIP READONLY;
SQL 'ALTER SYSTEM ARCHIVE LOG CURRENT';
BACKUP AS COMPRESSED BACKUPSET FORMAT '$BACKUP_ARC' ARCHIVELOG ALL DELETE INPUT;
BACKUP CURRENT CONTROLFILE;
}

exit;
EOF

Task 3: Testing the Backup Script

[oracle@SERVER_DATABASE rman]$ chmod 775 backup_script_full.sh
[oracle@SERVER_DATABASE rman]$ nohup ./ backup_script_full.sh &
[oracle@SERVER_DATABASE rman]$ tailf nohup.log
RMAN-00557: could not open MSGLOG "/u01/app/rman_backup/log_full/rman_backup_full_165_145_20151225.log"

Recovery Manager: Release 11.2.0.4.0 - Production on Fri Dec 25 17:05:50 2015

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database:ORCL (DBID=1723703927)

RMAN> 2> 3> 4> 5> 6> 7> 8> 9>
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=4018 instance=ptud11 device type=DISK
specification does not match any backup in the repository

released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=4018 instance=ptud11 device type=DISK
validation succeeded for archived log
archived log file name=+ARC/ptud1/archivelog/2015_12_17/thread_1_seq_3.256.898708303 RECID=4 STAMP=898708305
validation succeeded for archived log
archived log file name=+ARC/ptud1/archivelog/2015_12_18/thread_1_seq_4.261.898767075 RECID=9 STAMP=898767075
validation succeeded for archived log
archived log file name=+ARC/ptud1/archivelog/2015_12_21/thread_1_seq_5.262.899028659 RECID=10 STAMP=899028662
validation succeeded for archived log
archived log file name=+ARC/ptud1/archivelog/2015_12_17/thread_2_seq_2.258.898708305 RECID=5 STAMP=898708307
validation succeeded for archived log
archived log file name=+ARC/ptud1/archivelog/2015_12_18/thread_2_seq_3.257.898767069 RECID=6 STAMP=898767069
validation succeeded for archived log
archived log file name=+ARC/ptud1/archivelog/2015_12_18/thread_2_seq_4.259.898767073 RECID=7 STAMP=898767072
validation succeeded for archived log
archived log file name=+ARC/ptud1/archivelog/2015_12_18/thread_2_seq_5.260.898767073 RECID=8 STAMP=898767072
validation succeeded for archived log
archived log file name=+ARC/ptud1/archivelog/2015_12_25/thread_2_seq_6.263.899384879 RECID=11 STAMP=899384883
Crosschecked 8 objects
Starting backup at 25-DEC-15
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=2 sequence=2 RECID=5 STAMP=898708307
input archived log thread=1 sequence=3 RECID=4 STAMP=898708305
input archived log thread=2 sequence=3 RECID=6 STAMP=898767069
input archived log thread=1 sequence=4 RECID=9 STAMP=898767075
input archived log thread=2 sequence=4 RECID=7 STAMP=898767072
input archived log thread=2 sequence=5 RECID=8 STAMP=898767072
input archived log thread=1 sequence=5 RECID=10 STAMP=899028662
input archived log thread=2 sequence=6 RECID=11 STAMP=899384883
input archived log thread=1 sequence=6 RECID=13 STAMP=899399158
input archived log thread=2 sequence=7 RECID=12 STAMP=899399156
channel ORA_DISK_1: starting piece 1 at 25-DEC-15
channel ORA_DISK_1: finished piece 1 at 25-DEC-15
piece handle=/backup11/backup_full/ptud11_arc_f899399162_s1_s1 tag=TAG20151225T170602 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:25
channel ORA_DISK_1: deleting archived log(s)
archived log file name=+ARC/ptud1/archivelog/2015_12_17/thread_2_seq_2.258.898708305 RECID=5 STAMP=898708307
archived log file name=+ARC/ptud1/archivelog/2015_12_17/thread_1_seq_3.256.898708303 RECID=4 STAMP=898708305
archived log file name=+ARC/ptud1/archivelog/2015_12_18/thread_2_seq_3.257.898767069 RECID=6 STAMP=898767069
archived log file name=+ARC/ptud1/archivelog/2015_12_18/thread_1_seq_4.261.898767075 RECID=9 STAMP=898767075
archived log file name=+ARC/ptud1/archivelog/2015_12_18/thread_2_seq_4.259.898767073 RECID=7 STAMP=898767072
archived log file name=+ARC/ptud1/archivelog/2015_12_18/thread_2_seq_5.260.898767073 RECID=8 STAMP=898767072
archived log file name=+ARC/ptud1/archivelog/2015_12_21/thread_1_seq_5.262.899028659 RECID=10 STAMP=899028662
archived log file name=+ARC/ptud1/archivelog/2015_12_25/thread_2_seq_6.263.899384879 RECID=11 STAMP=899384883
archived log file name=+ARC/ptud1/archivelog/2015_12_25/thread_1_seq_6.264.899399153 RECID=13 STAMP=899399158
archived log file name=+ARC/ptud1/archivelog/2015_12_25/thread_2_seq_7.265.899399155 RECID=12 STAMP=899399156
Finished backup at 25-DEC-15

Starting backup at 25-DEC-15
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00004 name=+DATA/ptud1/datafile/users.259.898072689
input datafile file number=00002 name=+DATA/ptud1/datafile/sysaux.257.898072689
input datafile file number=00001 name=+DATA/ptud1/datafile/system.256.898072689
input datafile file number=00003 name=+DATA/ptud1/datafile/undotbs1.258.898072689
input datafile file number=00006 name=+DATA/ptud1/datafile/data.dbf
input datafile file number=00008 name=+DATA/ptud1/datafile/vsa.dbf
input datafile file number=00007 name=+DATA/ptud1/datafile/mdata.dbf
input datafile file number=00005 name=+DATA/ptud1/datafile/undotbs2.261.898072819
channel ORA_DISK_1: starting piece 1 at 25-DEC-15
channel ORA_DISK_1: finished piece 1 at 25-DEC-15
piece handle=/backup11/backup_full/ptud11_data_f899399248_s2_s1 tag=TAG20151225T170727 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:35
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 25-DEC-15
channel ORA_DISK_1: finished piece 1 at 25-DEC-15
piece handle=/backup11/backup_full/ptud11_data_f899399343_s3_s1 tag=TAG20151225T170727 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 25-DEC-15

sql statement: ALTER SYSTEM ARCHIVE LOG CURRENT

Starting backup at 25-DEC-15
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=7 RECID=14 STAMP=899399351
input archived log thread=2 sequence=8 RECID=15 STAMP=899399353
input archived log thread=1 sequence=8 RECID=17 STAMP=899399363
input archived log thread=2 sequence=9 RECID=16 STAMP=899399362
channel ORA_DISK_1: starting piece 1 at 25-DEC-15
channel ORA_DISK_1: finished piece 1 at 25-DEC-15
piece handle=/backup11/backup_full/ptud11_arc_f899399363_s4_s1 tag=TAG20151225T170923 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=+ARC/ptud1/archivelog/2015_12_25/thread_1_seq_7.265.899399351 RECID=14 STAMP=899399351
archived log file name=+ARC/ptud1/archivelog/2015_12_25/thread_2_seq_8.264.899399353 RECID=15 STAMP=899399353
archived log file name=+ARC/ptud1/archivelog/2015_12_25/thread_1_seq_8.262.899399363 RECID=17 STAMP=899399363
archived log file name=+ARC/ptud1/archivelog/2015_12_25/thread_2_seq_9.263.899399363 RECID=16 STAMP=899399362
Finished backup at 25-DEC-15

Starting backup at 25-DEC-15
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
channel ORA_DISK_1: starting piece 1 at 25-DEC-15
channel ORA_DISK_1: finished piece 1 at 25-DEC-15
piece handle=/u01/app/oracle/product/12.1.0.2/db_1/dbs/05qpnfm4_1_1 tag=TAG20151225T170924 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 25-DEC-15

Task 4: Scheduling the Daily Backup –UNIX and Linux

Firstly, configure oracle allow use crontab
[root@SERVER_DATABASE ~]# more /etc/cron.allow
root
oracle
Creating a crontab file for oracle user from the contents of .crontab.
[oracle@SERVER_DATABASE rman]$ crontab -e
MAILTO=thonh53@gmail.com
# MI HH DD MM DAY CMD
  00 19 * * * /u01/app/rman_backup/rman_backup_full.sh  > /dev/null 2>&1

Checking the contents of the crontab file for oracle user
[oracle@SERVER_DATABASE rman]$ crontab -l
MAILTO=thonh53@gmail.com
# MI HH DD MM DAY CMD
  00 19 * * * /u01/app/rman_backup/rman_backup_full.sh  > /dev/null 2>&1
(Optional) Checking crontab log.
[root@SERVER_DATABASE ~]# tailf /var/log/cron
Oct 30 18:01:01 localhost run-parts(/etc/cron.hourly)[7601]: finished 0anacron
Oct 30 18:01:01 localhost run-parts(/etc/cron.hourly)[7592]: starting mcelog.cron
Oct 30 18:01:01 localhost run-parts(/etc/cron.hourly)[7616]: finished mcelog.cron
Oct 30 18:01:44 localhost crontab[7744]: (oracle) BEGIN EDIT (oracle)
Oct 30 18:01:55 localhost crontab[7744]: (oracle) REPLACE (oracle)
Oct 30 18:01:55 localhost crontab[7744]: (oracle) END EDIT (oracle)
Oct 30 18:02:01 localhost crond[2526]: (oracle) RELOAD (/var/spool/cron/oracle)
Oct 30 18:02:12 localhost crontab[7783]: (root) BEGIN EDIT (root)
Oct 30 18:02:14 localhost crontab[7783]: (root) END EDIT (root)
Oct 30 18:02:28 localhost crontab[7805]: (root) LIST (oracle)
Oct 30 19:00:00 localhost CROND[7842]: (oracle) CMD (/u01/app/oracle/rman/backup_script_full.sh)

Friday, December 4, 2015

How to drop or truncade all partitions Oracle Database

[oracle@PTUD-VM02-2 oradata]$ more drop_partition_table.sql 

SET LINESIZE 32000;
SET PAGESIZE 40000;
SET LONG 50000;

select 'ALTER TABLE '||TABLE_OWNER||'.'||table_name||' DROP PARTITION '||partition_name||';' from dba_tab_partitions;

[oracle@PTUD-VM02-2 oradata]$ sqlplus / as sysdba @drop_partition_table.sql >> a.sql &

[oracle@PTUD-VM02-2 oradata]$ cat a.sql | grep 'DROP PARTITION' >> b.sql
[oracle@PTUD-VM02-2 oradata]$ sqlplus / as sysdba @b.sql

Thursday, December 3, 2015

Running OLAP Builds to Load Data into Analytical Workspace

Read the document firstly
https://docs.oracle.com/cd/E64694_01/CDMIG/E64550-04.pdf

This load typically completes in 30-35 minutes.
[oracle@PTUD-S07 ~]$ sqlplus ocdm_sample/*********@orcl

SQL*Plus: Release 12.1.0.1.0 Production on Thu Dec 3 14:56:25 2015

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Last Successful login time: Thu Dec 03 2015 14:03:22 +07:00

Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SQL> begin
pkg_ocdm_olap_etl_aw_load.run;
end;
/

PL/SQL procedure successfully completed.

SQL> select cubename,load_status,error_dtl from dwc_olap_activity order by
cubename; 

ACM COMPLETED-SUCCESS
ADM COMPLETED-SUCCESS
AGRMNT COMPLETED-SUCCESS
APM COMPLETED-SUCCESS
CCM COMPLETED-SUCCESS
CHRN COMPLETED-SUCCESS
CMSN COMPLETED-SUCCESS
COM COMPLETED-SUCCESS
CSM COMPLETED-SUCCESS
IAM COMPLETED-SUCCESS
INV COMPLETED-SUCCESS
INVCM COMPLETED-SUCCESS
RVN COMPLETED-SUCCESS
SLS COMPLETED-SUCCESS

14 rows selected.



How to impdp OCDM_SAMPLE for Oracle Communications Data Model





Step 1: Create tablespace for OCDM_SAMPLE:


SQL>  create tablespace DW_OCDM_SAMPLE datafile '/u01/app/oracle/admin/orcl/datafile/DW_OCDM_SAMPLE.dbf' size 100M autoextend on next 10M;
Tablespace created.
SQL>  create temporary tablespace DW_OCDM_SAMPLE_TEMP tempfile '/u01/app/oracle/admin/orcl/datafile/DW_OCDM_SAMPLE_TEMP.dbf' size 100M autoextend on next 10M;
Tablespace created.

Step 2: Create user ocdm_sample and grant privilege for the user.


create user "OCDM_SAMPLE" identified by ********** profile "DEFAULT" account unlock default tablespace  "DW_OCDM_SAMPLE" temporary tablespace "DW_OCDM_SAMPLE_TEMP";
     
grant CREATE SESSION to "OCDM_SAMPLE";
grant CREATE TYPE to "OCDM_SAMPLE";
grant CREATE SYNONYM to "OCDM_SAMPLE";
grant CREATE MATERIALIZED VIEW to "OCDM_SAMPLE";
grant CREATE TABLE to "OCDM_SAMPLE";
grant CREATE DIMENSION to "OCDM_SAMPLE";
grant CREATE SEQUENCE to "OCDM_SAMPLE";
grant CREATE VIEW to "OCDM_SAMPLE";
grant CREATE JOB to "OCDM_SAMPLE";
grant "OLAP_USER" to "OCDM_SAMPLE";
grant CREATE PROCEDURE to "OCDM_SAMPLE";
grant CREATE TABLESPACE to "OCDM_SAMPLE";
grant CREATE MINING MODEL to "OCDM_SAMPLE";
grant UNLIMITED TABLESPACE to "OCDM_SAMPLE";

Step 3: Import ocdm_sample.dmp


impdp system/******* directory=dump_dir dumpfile=ocdm_sample.dmp logfile=ocdm_sample.log

Wednesday, December 2, 2015

Limiting User Privileges when you install sample reports

[oracle@PTUD-S07 ~]$ more a.sql 
SET LINESIZE 32000;
SET PAGESIZE 40000;
SET LONG 50000;

select 'CREATE OR REPLACE EDITIONABLE SYNONYM OCDM_REPORT.'||Table_Name||' for OCDM_SYS.'||Table_Name||';' from All_Tables where owner='OCDM_SYS';


[oracle@PTUD-S07 ~]$ sqlplus / as sysdba @a.sql >> b.sql &
[4] 141981
[oracle@PTUD-S07 ~]$ cat b.sql | grep 'CREATE OR REPLACE EDITIONABLE SYNONYM' >> c.sql

[4]+  Stopped                 sqlplus / as sysdba @a.sql >> b.sql
[oracle@PTUD-S07 ~]$ sqlplus / as sysdba @c.sql

Tuesday, December 1, 2015

Scripts start, stop BI Publisher 11G

Prerequisite:

[obiee@PTUD-S07 security]$ pwd
/u02/obiee/fmw/user_projects/domains/bifoundation_domain/servers/AdminServer/security
[obiee@PTUD-S07 security]$ more boot.properties 
#Tue Dec 01 18:38:07 ICT 2015
username=weblogic
password=********

[obiee@PTUD-S07 security]$ cd ../..
[obiee@PTUD-S07 servers]$ ls
AdminServer  AdminServerTag  bi_server1  domain_bak
[obiee@PTUD-S07 servers]$ cp AdminServer/security/boot.properties bi_server1/security/


Start BI Publisher Scripts

[obiee@PTUD-S07 bin]$ cat start.sh
export FM_HOME=/u02/obiee/fmw
export DOMAIN_HOME=$FM_HOME/user_projects/domains/bifoundation_domain
export INSTANCE_HOME=$FM_HOME/instances/instance1

cd $DOMAIN_HOME/bin
nohup ./startWebLogic.sh >> weblogic.log &
#tailf weblogic.log

nohup ./startManagedWebLogic.sh bi_server1 >> bi_server1.log &
#tailf bi_server1.log

cd $INSTANCE_HOME/bin
./opmnctl startall
./opmnctl status



Stop BI Publisher Scripts

[obiee@PTUD-S07 bin]$ cat stop.sh 

export FM_HOME=/u02/obiee/fmw
export DOMAIN_HOME=$FM_HOME/user_projects/domains/bifoundation_domain
export INSTANCE_HOME=$FM_HOME/instances/instance1
cd $DOMAIN_HOME/bin
./stopManagedWebLogic.sh bi_server1
./stopWebLogic.sh
cd $INSTANCE_HOME/bin
./opmnctl stopall
./opmnctl status

Post-step:

[obiee@PTUD-S07 bin]$ chmod 775 start.sh stop.sh 






Set JAVA_HOME for user!

[obiee@PTUD-VM01-2 ~]$ cat .bash_profile 
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH

#JAVA_HOME
export JAVA_HOME=/u01/obiee/setup/jdk
export PATH=$JAVA_HOME/bin:$PATH