1. Create a backup path under the root user:
mkdir /opt/backupchown oralce:oinstall /opt/backup
2. Oracle user creates backup script path:
mkdir /opt/app/oracle/bincd /opt/app/oracle/bin
3. Create a backup script
vi backup.sh#!/bin/shexport ORACLE_BASE=/opt/app/oracleexport ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1export PATH=$PATH:$ORACLE_HOME/bin:.export ORACLE_SID=zd#export NLS_LANG=american_america.UTF8#export NLS_LANG=AMERICAN_AMERICA.AL32UTF8CURDATE=$(date ‘+%Y%m%d%H%M%S‘)backup_directory=/opt/backup/data_file_prefix=zdBACKUP_FILE=$backup_directory/zd$CURDATE.dmpdelete_prev_month_data_file(){ premonth=$(date -d"5 days ago" ‘+%Y%m%d‘) rm -rf $backup_directory/$data_file_prefix$premonth* || true}#exp zd/[email protected] FILE=$BACKUP_FILE tablespaces=‘zd‘exp zdwebsite/[email protected] FILE=$BACKUP_FILE owner=‘zdweb‘delete_prev_month_data_fileexit 0
4. Scheduled Tasks
crontab -e0 5 * * * /opt/app/oracle/bin/backup.sh
5, crontab Description:
The first * represents minutes per hour of execution 0-59
The second * represents hours per day of the first few hours of execution 0-23
The third * represents the day of the month of the day of execution 1-31
Fourth * indicates the monthly calendar of the month to execute 1-12
The fifth * represents the day of the week of weekly execution 0-6
Oracle Database Shell Backup script