Friday, May 22, 2015

FULL DATABASE EXPORT BACKUP USING DATAPUMP (EXPDP)


Change path as per your requirment



bash-3.2$
bash-3.2$ cat full_export.sh

ORACLE_SID=TESTRE
ORACLE_HOME=/opt/oracle/product/10.2.0/db_1; export ORACLE_HOME
PATH=$ORACLE_HOME/bin; export PATH
expdp system/manager dumpfile=full_backup14012015.dmp logfile=full_backuplog.log directory=datapump_dir full=y
bash-3.2$
bash-3.2$


save with 

full_export_sh

and run with ./full_export.sh


You can also run in background

nohup ./full_export.sh &

press enter

bash-3.2$ tail -f nohup.out
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT



SCHEMA IMPORT FROM FULL DATAPUMP BACKUP.


Change path as per your requirement



bash-3.2$
bash-3.2$ cat import_schema.sh
#!/bin/sh

ORACLE_SID=TESTRE
ORACLE_HOME=/opt/oracle/product/10.2.0/db_1; export ORACLE_HOME
PATH=$ORACLE_HOME/bin; export PATH
impdp  system/manager dumpfile=sprt_schema_backup14012015.dmp logfile=sprt_importlog.log directory=datapump_dir schemas=SPRTSG4
bash-3.2$
bash-3.2$


save with 

import_schema.sh

and run with ./import_schema.sh


You can also run in background

nohup ./full_export.sh &

press enter

bash-3.2$ tail -f nohup.out
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT

Solution ORA-01940: cannot drop a user that is currently connected



SQL> drop user sprtsg4 cascade;
drop user sprtsg4 cascade
*
ERROR at line 1:
ORA-01940: cannot drop a user that is currently connected



///
Before the kill session lock the account for further connection establish.


SQL>
SQL> alter user sprtsg4 account lock;

User altered.

SQL>
SQL> SET LINESIZE 100
SQL> COLUMN spid FORMAT A10
SQL> COLUMN username FORMAT A10
SQL> COLUMN program FORMAT A45
SQL>
SQL> SELECT s.inst_id,
  2         s.sid,
  3         s.serial#,
  4         p.spid,
       s.username,
  5    6         s.program
  7  FROM   gv$session s
  8         JOIN gv$process p ON p.addr = s.paddr AND p.inst_id = s.inst_id
WHERE  s.type != 'BACKGROUND';  9

   INST_ID        SID    SERIAL# SPID       USERNAME   PROGRAM
---------- ---------- ---------- ---------- ---------- ---------------------------------------------
         1         49       7543 4360       SYS        sqlplus@acs7 (TNS V1-V3)
         1        100       4663 4153       SYS        sqlplus@acs7 (TNS V1-V3)
         1        141      15044 4626       SPRTSG4    JDBC Thin Client
         1         16      33035 4628       SPRTSG4    JDBC Thin Client
         1         71      16974 4630       SPRTSG4    JDBC Thin Client
         1         83      58119 4632       SPRTSG4    JDBC Thin Client
         1         90      61930 4634       SPRTSG4    JDBC Thin Client
         1        121      28526 3065       SYSMAN     OMS
         1         31      44985 3076       SYSMAN     OMS
         1        122      31487 3078       SYSMAN     OMS
         1        140      11579 3366       DBSNMP     emagent@acs7 (TNS V1-V3)

   INST_ID        SID    SERIAL# SPID       USERNAME   PROGRAM
---------- ---------- ---------- ---------- ---------- ---------------------------------------------
         1        129        121 25590      DBSNMP     emagent@acs7 (TNS V1-V3)
         1        152       3737 4636       SPRTSG4    JDBC Thin Client
         1         79        615 4615       SYSMAN     OMS
         1        119      22358 4638       SPRTSG4    JDBC Thin Client
         1          6       6899 4640       SPRTSG4    JDBC Thin Client
         1         46       7585 4644       SPRTSG4    JDBC Thin Client
         1        151      38346 4648       SPRTSG4    JDBC Thin Client

18 rows selected.

SQL> alter system kill session '&id,&serial';
Enter value for id: 151
Enter value for serial: 38346
old   1: alter system kill session '&id,&serial'
new   1: alter system kill session '151,38346'

System altered.

SQL> /
Enter value for id: 46
Enter value for serial: 7585
old   1: alter system kill session '&id,&serial'
new   1: alter system kill session '46,7585'

System altered.


SQL>
SQL>
SQL> drop user sprtsg4 cascade;






User dropped.

SQL> SQL> SQL> SQL> SQL> SQL>