Quantcast
Channel: Teguh Triharto Learning Center
Viewing all articles
Browse latest Browse all 413

.::: Backup restore Export import expdp impdp from schema to another schema in oracle using crontab :::.

$
0
0
 

correlation https://teguhth.blogspot.com/2024/12/backup-restore-export-import-expdb.html


1. backup manual

[oracle@teguhth ~]$ expdp aisyah/hanin@localhost:1521/tgh DIRECTORY=DATA_PUMP_DIR DUMPFILE=aisyah_schema.dmp LOGFILE=aisyah_schema.log SCHEMAS=aisyah

Export: Release 19.0.0.0.0 - Production on Tue Apr 22 14:10:38 2025
Version 19.3.0.0.0

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

Connected to: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Starting "AISYAH"."SYS_EXPORT_SCHEMA_01":  aisyah/********@localhost:1521/tgh DIRECTORY=DATA_PUMP_DIR DUMPFILE=aisyah_schema.dmp LOGFILE=aisyah_schema.log SCHEMAS=aisyah
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type SCHEMA_EXPORT/STATISTICS/MARKER
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type SCHEMA_EXPORT/TABLE/COMMENT
Processing object type SCHEMA_EXPORT/TABLE/IDENTITY_COLUMN
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/TRIGGER
. . exported "AISYAH"."BARANG"                           6.984 KB       6 rows
. . exported "AISYAH"."CUSTOMER"                         7.554 KB       6 rows
. . exported "AISYAH"."EMPLOYEES"                        6.359 KB       2 rows
. . exported "AISYAH"."EMPLOYEES_CHANGE_LOG"             8.312 KB       5 rows
. . exported "AISYAH"."PASOK"                            7.695 KB      12 rows
. . exported "AISYAH"."PEMBELIAN"                        7.835 KB      15 rows
. . exported "AISYAH"."SUPLIER"                          7.578 KB       6 rows
Master table "AISYAH"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for AISYAH.SYS_EXPORT_SCHEMA_01 is:
  /home/oracle/backup/aisyah_schema.dmp
Job "AISYAH"."SYS_EXPORT_SCHEMA_01" successfully completed at Tue Apr 22 14:11:39 2025 elapsed 0 00:00:58

[oracle@teguhth ~]$

 
2. create script   /home/oracle/impdp_restore.sh

[oracle@teguhth ~]$ cat /home/oracle/impdp_restore.sh
datex=$(date "+%Y-%m-%d %H:%M:%S.%N")
echo "$datex --->>> Restore Begin"
echo "$datex --->>> Restore Begin"> log_restore.txt

export ORACLE_HOME=/u01/app/oracle/product/19.0.0/dbhome_1
export ORACLE_SID=tgh
export PATH=$ORACLE_HOME/bin:$PATH

impdp aisyah_training/hanin@tgh DIRECTORY=DATA_PUMP_DIR DUMPFILE=aisyah_schema.dmp LOGFILE=import_force.log REMAP_SCHEMA=aisyah:aisyah_training TABLE_EXISTS_ACTION=REPLACE >> log_restore.txt

datey=$(date "+%Y-%m-%d %H:%M:%S.%N")
echo "$datey --->>> Restore Finish"
echo "$datey --->>> Restore Finish">> log_restore.txt
[oracle@teguhth ~]$

 


3. crontab

[oracle@teguhth ~]$ crontab -l
27 14 22 4 * sh /home/oracle/impdp_restore.sh
[oracle@teguhth ~]$


4. if manual restore, close any session

SELECT s.sid, s.serial#
FROM v$session s
WHERE s.username = 'AISYAH_TRAINING';

ALTER SYSTEM KILL SESSION '70,14402' IMMEDIATE;


5. check again for aisyah_training

SELECT t.*, SYS_CONTEXT('USERENV', 'SESSION_USER') AS os_user
FROM tab t;



 

Viewing all articles
Browse latest Browse all 413

Trending Articles