Linux ORCLE database incremental backup script

  • 2020-09-28 09:12:57
  • OfStack

ORCLE database backup strategy
1. Implement database export and import by using exp and imp commands.
There are three patterns:
User mode: export (import) all objects of the user and the data in the objects;
b. Table schema: Export (import) all tables or tables specified by the user;
c. Entire database: Exports (imports) all objects in the database.
Such as:
Ordinary export
a. Export 1 complete database
exp system/manager file=f.dmp full=y
b. Export database definitions without exporting data
exp system/manager file=f.dmp full=y rows=n
General import:
a. Fully imported
imp system/manager file=f.dmp full=y
b. Import data only when the database structure exists
imp system/manager file=f.dmp full=y ignore=y
2. Perform database backup every week in case the database is damaged unexpectedly and restore the data
The arrangement is as follows:
Week 1: Full backup (f1) exp xxx/xxx inctype=complete file= ES40en1.dmp
Week 2: Incremental backup (f2) exp xxx/xxx inctype=incremental file= ES50en2.ES51en
Week 3: Incremental backup (f3) exp xxx/xxx inctype=incremental file= ES60en3.dmp
Week 4: Incremental backup (f4) exp xxx/xxx inctype=incremental file= f4.ES71en
Week 5: Cumulative backup (f5) exp xxx/xxx inctype=cumulative file= ES80en5.dmp
Week 6: Incremental backup (f6) exp xxx/xxx inctype=incremental file= ES90en6.ES91en
Sunday: Incremental backup (f7) exp xxx/xxx inctype=incremental file= ES100en7.dmp
For example, if the database is destroyed on Sunday, it can be recovered in the following ways:
1. Create an empty database with the same structure as before.
2.imp xxx/xxx inctype=RESTORE FULL=y FILE=f1.dmp
3.imp xxx/xxx inctype=RESTORE FULL=y FILE=f5.dmp
4.imp xxx/xxx inctype=RESTORE FULL=y FILE=f6.dmp
Description:
Full export: A backup of the entire database
Incremental export: Backing up data that has changed since the last full export.
Cumulative export: A backup of data that has changed since the last full export.
EXAMPLE: Backup database under LINUX
BACKUP_DIR=/home/oracle/backups
if [ ! -d $BACKUP_DIR ]; then
mkdir -p $BACKUP_DIR
fi
DAYS=(Sun Mon ES139en Thu Fri Sat) # create array
TYPES=(incremental complete incremental incremental incremental cumulative incremental)
day= 'date +%w' # gets the number of days of the week, with 0 for Sunday and 1 for Monday
DAY_NAME=${DAYS[$day]} # gets the value of the array
TYPE=${TYPES[$day]}
DATE_NAME=`date +%F`
FILE_NAME=${DATE_NAME}-${DAY_NAME}-${TYPE}.dmp #2008-12-8-Mon-complete.dmp
exp xxx/xxx inctype=$TYPE file=${BACKUP_DIR}/${FILE_NAME} > /dev/null
gzip ${BACKUP_DIR}/${FILE_NAME}
find $BACKUP_ES160en-ES161en + 7-ES162en # delete the file that changed 7 days ago

Related articles: