This is the 28th day of my participation in the August Text Challenge.More challenges in August

preface

  • When rMAN is used for backup and restoration, the client execution record cannot be directly displayed. You can use SQL to query the progress.

RMAN backup

  • The following commands can be directly copied and executed.

1 Configure the backup path and scheduled task

  • Backup Path Setting
SCRIPTSDIR=/home/oracle/scripts
BACKUPDIR=/backup
mkdir -p $BACKUPDIR $SCRIPTSDIR
Copy the code
  • Write scheduled task
cat <<EOF>>/var/spool/cron/oracle
30 00 * * 0 ${SCRIPTSDIR}/dblevel0_backup.sh
30 00 * * 1-6 ${SCRIPTSDIR}/dbleve1_backup.sh
EOF
Copy the code

2 Complete scripts

{
	echo '#! /bin/sh'
	echo 'source ~/.bash_profile'
	echo 'backtime=`date +"20%y%m%d%H%M%S"`'
	echo "rman target / log=${BACKUPDIR}/full_backup_\${backtime}.log<<EOF"
	echo 'run {'
	echo 'allocate channel c1 device type disk; '
	echo 'allocate channel c2 device type disk; '
	echo 'crosscheck backup; '
	echo 'crosscheck archivelog all; '
	echo 'sql"alter system switch logfile"; '
	echo 'delete noprompt expired backup; '
	echo 'delete noprompt obsolete device type disk; '
	echo "backup database include current controlfile format '${BACKUPDIR}/backfull_%d_%T_%t_%s_%p';"
	echo 'backup archivelog all DELETE INPUT format '${BACKUPDIR}/archivelog_%d_%T_%t_%s_%p'; '
	echo 'release channel c1; '
	echo 'release channel c2; '
	echo '} '
	echo 'EOF'} > >${SCRIPTSDIR}/dbbackup_full.sh
Copy the code

Note: Full script is equivalent to incremental 0 backup.

3 Incremental backup script

  • Perform level 0 incremental backup scripts at 00:30 every Sunday
{
	echo '#! /bin/sh'
	echo 'source ~/.bash_profile'
	echo 'backtime=`date +"20%y%m%d%H%M%S"`'
	echo "rman target / log=${BACKUPDIR}/level0_backup_\${backtime}.log<<EOF"
	echo 'run {'
	echo 'allocate channel c1 device type disk; '
	echo 'allocate channel c2 device type disk; '
	echo 'crosscheck backup; '
	echo 'crosscheck archivelog all; '
	echo 'sql"alter system switch logfile"; '
	echo 'delete noprompt expired backup; '
	echo 'delete noprompt obsolete device type disk; '
	echo "backup incremental level 0 database include current controlfile format '${BACKUPDIR}/backlv0_%d_%T_%t_%s_%p';"
	echo 'backup archivelog all DELETE INPUT format '${BACKUPDIR}/archivelog_%d_%T_%t_%s_%p'; '
	echo 'release channel c1; '
	echo 'release channel c2; '
	echo '} '
	echo 'EOF'} > >${SCRIPTSDIR}/dbbackup_lv0.sh
Copy the code
  • Do level 1 incremental backup scripts from Monday to Saturday at 00:30
{
	echo '#! /bin/sh'
	echo 'source ~/.bash_profile'
	echo 'backtime=`date +"20%y%m%d%H%M%S"`'
	echo "rman target / log=${BACKUPDIR}/level1_backup_\${backtime}.log<<EOF"
	echo 'run {'
	echo 'allocate channel c1 device type disk; '
	echo 'allocate channel c2 device type disk; '
	echo 'crosscheck backup; '
	echo 'crosscheck archivelog all; '
	echo 'sql"alter system switch logfile"; '
	echo 'delete noprompt expired backup; '
	echo 'delete noprompt obsolete device type disk; '
	echo "backup incremental level 1 database include current controlfile format '${BACKUPDIR}/backlv1_%d_%T_%t_%s_%p';"
	echo 'backup archivelog all DELETE INPUT format '${BACKUPDIR}/archivelog_%d_%T_%t_%s_%p'; '
	echo 'release channel c1; '
	echo 'release channel c2; '
	echo '} '
	echo 'EOF'} > >${SCRIPTSDIR}/dbbackup_lv1.sh
Copy the code

4 View the RMAN backup progress SQL

    SELECT sid,
           serial#,
           CONTEXT,
           sofar,
           totalwork,
           round(sofar / totalwork * 100.2) "%_COMPLETE"
      FROM gv$session_longops
     WHERE opname LIKE 'RMAN%'
       AND opname NOT LIKE '%aggregate%'
       AND totalwork ! = 0
       AND sofar <> totalwork;
Copy the code

RMAN restoration

1 Recovery Script

  • Start the database to Nomount
sqlplus / as sysdba
startup nomount
Copy the code
  • Rman restore control file, open database to mount
rman target /
restore controlfile from '/backup/control.bak';
alter database mount;
Copy the code
  • Rman restores the database
rman target /
restore database;
recover database;
Copy the code
  • Open database to resetlogs
alter database open resetlogs;
Copy the code

2 View the RMAN recovery progress SQL

SELECT sid,
       serial#,
       CONTEXT,
       sofar,
       totalwork,
       round(sofar / totalwork * 100.2) "% Complete"
  FROM v$session_longops
 WHERE opname LIKE 'RMAN:%'
   AND opname NOT LIKE 'RMAN: aggregate%';
Copy the code

This is the end of sharing ~

If you think the article is helpful to you, please like it, favorites it, pay attention to it, comment on it, and support it four times with one button. Your support is the biggest motivation for my creation.

Think twice before you act