Skip to Main Content
Ted Struik - Oracle
Home
Ted Struik - Oracle
Search
Site Map
Statistics
Page Errors
Apex
General
Autocomplete
Conditions
Errors
Items used in PL/SQL
Validations
Dynamic Actions
Logs
Version
App-wide Items
Error Handling
Apex Views
Apex Upgrade 4.2 to 5.1
Database Dependencies
Show Source Code
URLs
Authorization
Modal Dialogs
Apex Office Print (AOP)
Apex-Sert
Reports
Checkboxes
Download
Errors
Nowrap Columns
Substitution Strings
Use IR results in pl/sql
Clickable Row
Row Highlight
Translate Filters etc.
Bar Charts
Column Usage
Reset Pagination
Hide IR Actions menu items
Get Classic Report query
Interactive Grid
ORA-20987
ERR-1002
Copying Text
IG Info
Images & Fonts
Standard Icons & Fonts
WebDav
Font Awesome
Icons/image popup LOV
Lists
Hierarchy
LOVs
Definition Bug
Set 1-item LOV to Disabled
With Clause Errors
Modal LOV Plugin
HTML / CSS / JavaScript
Vertical Align
Legend CSS
Geolocation
Apex.confirm
Pie Charts
Codemirror
Theme Roller
Catching Key Strokes
Browser Cache
Locale
RequireJS
Collapsible Regions
Import / Export
Dynamic Translations
Translated Pages
APEXExport (java)
apex_export (pl/sql)
Component Settings
Charts
Translate Charts
[Reports] Bar Charts
Shuttles
Shuttle Sorting
Disable Shuttle Items
Menus
Accordion-Like
Scroll bug
Authorization
Session State
About Session State
Rollback & Commit
Performance of v()
Apex Clone Session
Request
Collections
ORA-20101 & ORA-20104
ORA-00001
Max Row Count
(PL)SQL
External Tables
SQL Plus
Conditions
Long
ORDImage
Date & Timestamp
CGI environment
Sys_context
Rounding percentages
Apex_string.split in SQL
Dbms_metadata
Instr
Regular Expressions
Rollback to Savepoint
Use table aliases
(Pipelined) Bulk Collect
JSON
Source Code Search (PL/SQL)
Source Code Search (SQL)
Format Models
Pipelined Table Functions
Hint no_unnest
Listagg
DBA
Backup & Restore
Users
Export & Import
DBMS Jobs
Tablespaces
Table Size
Flush cache
Access Control List (ACL)
Locks
Java
Constraints
Object Dependencies
Package Dependencies 1
Package Dependencies 2
Grants
SQL History
Startup Errors
ORDS
Miscellaneous
Holidays
E-mail
NLExtract
Windows
VPN
VMware
Links
Google
Visualization Orgchart
Hide Search Results
Reverse Proxy
To-do List
Cytoscape
Graphics
Upscaling
Amazon Prices
Domoticz
DDoS
Hobbies
Motorcycles
'95 Kawasaki ZZR 600
'94 Kawasaki ZZR 1100
'91 Honda CBR 600 F2
'95 Kawasaki ZZR 1100
'99 Honda CBR 1100 XX
'00 Honda CBR 1100 XX
'02 Kawasaki ZX-12R (NL)
'05 Ducati 999 (NL)
'08 Honda Fireblade
'07 Suzuki Bandit 1250A
'18 Suzuki GSX-S 1000 F
MotoGP
Garfield
Lyrics
Skydive
Woodworking
Pantorouter
16 inch Bandsaw
Introduction
Frame
Wheels
Wheel mounts
Blade guides
Trunions and table
Enclosure
Alignment and more
Box Joint Jig
Foldable Sawhorses
Strip Sander XL
Photography
Sony RX10 IV
Search For
Backup script
Example of a backup script under Linux (CentOS/RedHat/Oracle).
This script exports all data from a set of schemas, exports a few Apex applications and their workspace, makes a .tar.gz file out of all these files plus the backup script file(s), and copies the resulting .tar.gz file to a remote backup location.
The script can be run as root - user oracle is probably also possible but root is easier.
Note that this script copies the export file to OneDrive, which is what I happen to use, but of course any other (network/cloud) storage option is fine.
If you want to use OneDrive, the info at
https://www.maketecheasier.com/sync-onedrive-linux/
is very helpful.
APEXExport requires some setup (java, environment) before you can use it properly. More info on that can be found
here
.
Note that (depending on the database version you use) you may have to change the values for ORACLE_HOME & APEX_HOME, and also change the CLASSPATH path to point to another version of the ojdbc jar file.
Execute as OS user oracle or root:
#!/bin/bash export ORACLE_HOME=/opt/oracle/product/21c/dbhomeXE export NLS_LANG=AMERICAN_AMERICA.AL32UTF8 export PATH=/usr/local/bin:/usr/bin/java:$ORACLE_HOME/bin:$PATH export JAVA_HOME=/usr/bin/java export APEX_HOME=$ORACLE_HOME/apex export CLASSPATH=$ORACLE_HOME/jdbc/lib/ojdbc8.jar:$APEX_HOME/utilities:$CLASSPATH:. LOGFILE=/backup/backup.log UP=`ps -ef|grep -i pmon|grep -v grep|wc -l` if [ "$UP" -ge "1" ] then cd /backup rm -f *.gz rm -f *.dmp expdp system/password@XEPDB1 dumpfile=expdp.dmp directory=export_dir logfile=backup.log schemas=DEV_OWNER,ESB_OWNER,ISR_AUTH,ISR_CORE,ISR_MONITOR,ISR_OWNER,ISR_TRACE,ISR_USER,LOG_OWNER,SMS_1_OWNER,SMS_1_POS,SMS_1_WS,PLPDF reuse_dumpfiles=y PREV_DIR=${PWD} cd $ORACLE_HOME/apex/utilities java oracle/apex/APEXExport -db localhost:1521:XEPDB1 -user APEX_220100 -password password -applicationid 25384 2>&1 | tee -a $LOGFILE java oracle/apex/APEXExport -db localhost:1521:XEPDB1 -user APEX_220100 -password password -expWorkspace 2>&1 | tee -a $LOGFILE mv f*.sql $PREV_DIR mv w*.sql $PREV_DIR cd $PREV_DIR tar czf - *.sql *.dmp *.sh *.log *.parm > export_apex.tar.gz 2>&1 | tee -a $LOGFILE mv export_apex.tar.gz export_apex_$(date +%Y_%m_%d).tar.gz rm -f ./OneDrive/DMZ-DB-08/export_apex_*.tar.gz cp export_apex_*.tar.gz ./OneDrive/DMZ-DB-08/ onedrive --synchronize --upload-only --no-remote-delete 2>&1 | tee -a $LOGFILE rm -f *.sql *.dmp # Verify if an Oracle error has been raised if grep -q ORA- $LOGFILE then echo "ERROR: An Oracle error has occurred, check $LOGFILE" exit 1 fi else echo "ERROR: Database is not running. Backup will be skipped." 2>&1 | tee $LOGFILE exit 1 fi
Backup with parameter file
Variation on the script above, using a parameter file.
This script exports all data from a set of schemas, excluding a number of tables. The rest is the same as above.
Change this line:
expdp system/password@XEPDB1 dumpfile=expdp.dmp directory=export_dir logfile=backup.log schemas=DEV_OWNER,ESB_OWNER,ISR_AUTH,ISR_CORE,ISR_MONITOR,ISR_OWNER,ISR_TRACE,ISR_USER,LOG_OWNER,SMS_1_OWNER,SMS_1_POS,SMS_1_WS,PLPDF reuse_dumpfiles=y
To:
expdp system/password@XEPDB1 parfile=backup.parm
Create the parameter file backup.parm:
dumpfile=expdp.dmp exclude=TABLE:"IN ('PBY_DATA_TABLE', 'PBY_QTABLE', 'PBY_IMDB_TITLES')" directory=backup_dir logfile=backup.log schemas=DEV_OWNER,ESB_OWNER,ISR_AUTH,ISR_CORE,ISR_MONITOR,ISR_OWNER,ISR_TRACE,ISR_USER,LOG_OWNER,SMS_1_OWNER,SMS_1_POS,SMS_1_WS,PLPDF reuse_dumpfiles=y
Restore using database files
You can rebuild a database very easily (and fast) on a new server, by restoring its data files from the "oradata" directory. Nothing new, but I was quite amazed at how smoothly this works.
Provided you took care of these steps, restore is a breeze:
Your backup of the datafiles in the "oradata" directory was made with the DB shut down normally.
The server you are restoring to is either (a backup of) the exact same server you backed up, or a new server that has Oracle installed in the exact same way (same oracle home, instance name, etc.). Hostname, network configuration etc. can be different.
As an example, I did the following to restore an XE 11g database (from a dead server to a new virtual machine):
Stop the database:
As root: /etc/init.d/oracle-xe stop
Move the new ("empty") database files to /tmp, just in case:
As oracle: cd /u01/app/oracle/oradata/XE
As oracle: mkdir /tmp/xe_new_backup
As oracle: mv *.dbf /tmp/xe_new_backup/
Restore the original data files and make sure oracle:dba is the owner (make sure oracle:dba is correct for you, change to the owner of the new ("empty") data files if needed):
As root: cd /u01/app/oracle/oradata/XE
As root: cp /backup/oradata/XE/*.dbf .
As root: chown oracle:dba *.dbf
Finalize:
As oracle: cd /u01/app/oracle/oradata/XE
As oracle: sqlplus sys/password as sysdba
As oracle: SQL> startup mount
As oracle: SQL> recover database until cancel
As oracle: SQL> alter database open resetlogs;
Stop & start database:
As root: /etc/init.d/oracle-xe stop
As root: /etc/init.d/oracle-xe start
More info:
https://community.oracle.com/thread/874166?start=0&tstart=0