蓝帆天诚
一、rman备份
control keep 时间需要改为14
[oracle@orcl rman]$ crontab -l
40 0 * * * /home/oracle/rman/rman.sh
[oracle@orcl ~]$ cat /home/oracle/rman/rman.sh
#!/bin/sh
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export ORACLE_SID=orcl
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
backtime=`date +"20%y%m%d%H%M%S"`
rman target / log=/home/oracle/rman/log/backupall_$backtime.log <<EOF
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
crosscheck backup;
crosscheck archivelog all;
delete noprompt expired backup;
sql 'alter system switch logfile';
backup database format '/backup/db_%d_%T_%U';
backup archivelog all format '/backup/arc_%T_%s_%U';
backup current controlfile format '/backup/cntrl_%T_%p_%s_%U';
backup spfile format '/backup/sp_%d_%U_%T.sp';
crosscheck backup;
crosscheck archivelog all;
delete noprompt archivelog until time 'sysdate-3';
delete noprompt backup of database completed before 'sysdate - 10';
delete noprompt backup of archivelog until time 'sysdate-10';
release channel c1;
release channel c2;
release channel c3;
release channel c4;
}
EOF
echo "backup complete! " >> /home/oracle/rman/log/backupall_$backtime.log
[oracle@jhx rman]$ chmod a+x rman.sh
例2:
[oracle@tzgtdb01 rman]$ cat tzfull.sh
export ORACLE_HOME=/u01/app/oracle/product/12.2.0.1/dbhome_1
export ORACLE_BASE=/u01/app/oracle
export ORACLE_SID=tzgtdb1
export TMPDIR=/home/oracle/xtts
export PATH=$ORACLE_HOME/bin:$PATH:$ORACLE_HOME/OPatch
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
rman target / >> /home/oracle/rman/log/tzlevel0_`date +"%Y%m%d"`.log << EOF
run {
allocate channel c1 device type disk;
allocate channel c2 device type disk;
crosscheck archivelog all;
crosscheck backup;
backup database filesperset 5 format '+DATAC1/rman/tzlevel0_%d_%s_%T.db0';
backup current controlfile format '+DATAC1/rman/tzctl_%d_%s_%T.db0';
delete NOPROMPT OBSOLETE RECOVERY WINDOW OF 7 DAYS;
release channel c1;
release channel c2;
}
exit;
EOF
二、只删归档
[oracle@tzgtdb01 rman]$ cat tzrm_arch.sh
export ORACLE_HOME=/u01/app/oracle/product/12.2.0.1/dbhome_1
export ORACLE_BASE=/u01/app/oracle
export ORACLE_SID=tzgtdb1
export TMPDIR=/home/oracle/xtts
export PATH=$ORACLE_HOME/bin:$PATH:$ORACLE_HOME/OPatch
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
rman target / > /home/oracle/rman/log/tzrm_arch_`date +"%Y%m%d"`.log << EOF
run {
allocate channel c1 device type disk;
allocate channel c2 device type disk;
crosscheck archivelog all;
crosscheck backup;
delete noprompt archivelog until time "sysdate - 30";
release channel c1;
release channel c2;
}
exit;
EOF
adg备库只删归档:
[oracle@tzgtdb01 rman]$ cat tzrm_arch.sh
export ORACLE_HOME=/u01/app/oracle/product/12.2.0.1/dbhome_1
export ORACLE_BASE=/u01/app/oracle
export ORACLE_SID=tzgtdb1
export TMPDIR=/home/oracle/xtts
export PATH=$ORACLE_HOME/bin:$PATH:$ORACLE_HOME/OPatch
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
rman target / > /home/oracle/rman/log/tzrm_arch_`date +"%Y%m%d"`.log << EOF
run {
allocate channel c1 device type disk;
allocate channel c2 device type disk;
crosscheck archivelog all;
crosscheck backup;
delete noprompt archivelog until time "sysdate - 30";
release channel c1;
release channel c2;
}
exit;
EOF