Table of Contents

Linux backup scripts

/asmfs/rman_cmds/backup.sh

#!/bin/bash

if [ ! $1 ]
then
echo no parameter
exit 1
fi

export PATH=$PATH:/usr/local/bin

. /usr/local/bin/oraenv <<EOF
$2
EOF
export ORASID=$2

export ORACLE_SID=${2}1
rman nocatalog cmdfile=/asmfs/rman_cmds/$1 using $ORASID

/asmfs/rman_cmds/rman_logs.cmd

connect target /

CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 3 DAYS;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE  DISK TO '/backup_oracle/${ORASID}/cf_%F';
CONFIGURE BACKUP OPTIMIZATION ON;
CONFIGURE DEVICE TYPE disk PARALLELISM 3;
CONFIGURE DEFAULT DEVICE TYPE TO disk;
CONFIGURE CHANNEL 1 DEVICE TYPE DISK FORMAT  '/backup_oracle/${ORASID}/b_%U';
CONFIGURE SNAPSHOT CONTROLFILE NAME TO  '/tmp/${ORASID}_snapcf_oraol.f';

BACKUP ARCHIVELOG ALL DELETE INPUT;

ALLOCATE CHANNEL FOR MAINTENANCE DEVICE TYPE DISK;
CROSSCHECK BACKUP;
DELETE NOPROMPT EXPIRED BACKUP;
DELETE NOPROMPT OBSOLETE DEVICE TYPE DISK;
CROSSCHECK  ARCHIVELOG ALL;
DELETE NOPROMPT EXPIRED ARCHIVELOG ALL;

/asmfs/rman_cmds/rman_full.cmd

connect target /

CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 3 DAYS;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE  DISK TO '/backup_oracle/${ORASID}/cf_%F';
CONFIGURE BACKUP OPTIMIZATION ON;
CONFIGURE DEVICE TYPE disk PARALLELISM 1;
CONFIGURE DEFAULT DEVICE TYPE TO disk;
CONFIGURE CHANNEL 1 DEVICE TYPE DISK FORMAT  '/backup_oracle/${ORASID}/b_%U';
CONFIGURE SNAPSHOT CONTROLFILE NAME TO  '/tmp/${ORASID}_snapcf_oraol.f';
CONFIGURE COMPRESSION ALGORITHM 'HIGH';

BACKUP AS COMPRESSED BACKUPSET DATABASE PLUS ARCHIVELOG DELETE INPUT;

ALLOCATE CHANNEL FOR MAINTENANCE DEVICE TYPE DISK;
CROSSCHECK BACKUP;
DELETE NOPROMPT EXPIRED BACKUP;
DELETE NOPROMPT OBSOLETE DEVICE TYPE DISK;
CROSSCHECK  ARCHIVELOG ALL;
DELETE NOPROMPT EXPIRED ARCHIVELOG ALL;

Cron

0,30 * * * * /asmfs/rman_cmds/backup.sh rman_logs.cmd orcl 2>&1 >/dev/null
55 0 * * * /asmfs/rman_cmds/backup.sh rman_full.cmd orcl 2>&1 >/dev/null

Full backup old mode

exp system/manager@abc FULL=Y FILE=FULL.DMP
imp system/manager@abc FULL=Y FILE=FULL.DMP

Datapump

CREATE DIRECTORY dmpdir AS '/opt/oracle';
GRANT read, write ON DIRECTORY dmpdir TO scott;
expdp scott/tiger DIRECTORY=dmpdir DUMPFILE=scott.dmp

Restore

rman target /
startup nomount;
set dbid=xxxxxxxxx;
restore controlfile from '/backup_oracle/cffile';
shutdown immediate;
startup nomount;
alter database mount;
restore database;
recover database;
alter database open resetlogs;
restore controlfile;
recover database;
run{
ALLOCATE CHANNEL t1 DEVICE TYPE disk;
RESTORE CONTROLFILE FROM AUTOBACKUP;
ALTER DATABASE MOUNT;
RESTORE DATABASE;
SWITCH DATAFILE ALL;
RECOVER DATABASE;
}
LIST BACKUP OF DATABASE;
LIST BACKUP RECOVERABLE;
LIST BACKUP OF DATABASE SUMMARY;
LIST BACKUP OF DATAFILE 1;
LIST BACKUP OF ARCHIVELOG SEQUENCE;

Info

select GROUP_NUMBER, NAME,TOTAL_MB, FREE_MB, USABLE_FILE_MB from V$ASM_DISKGROUP;
select substr(name,1,10) name,substr(path,1,20) path, REDUNDANCY, TOTAL_MB, os_mb, free_mb from V$ASM_DISK;