linux下自動備份oracle資料庫-rman

peng163fj發表於2015-04-13

[oracle@omsdb01 backup]$ more /home/backup/backup.sh

#!/bin/sh

time=$(date '+%Y%m%d' )

mkdir /home/backup/$time

rman target / log=/home/backup/rman.log cmdfile=/home/backup/rman.txt

exit

scp -r /home/backup/$time oracle@192.168.11.76:/home/rman/share


[給雙節點信任]

omsdg01

ssh-keygen -t rsa

ssh-keygen -t dsa


omsdg02

ssh-keygen -t rsa

ssh-keygen -t dsa


omsdg01

cat ~/.ssh/*.pub >> ~/.ssh/authorized_keys

ssh oracle@omsdg01 cat ~/.ssh/*.pub >> ~/.ssh/authorized_keys


omsdg02

cat ~/.ssh/*.pub >> ~/.ssh/authorized_keys

ssh oracle@omsdg02 cat ~/.ssh/*.pub >> ~/.ssh/authorized_keys

這一步不用輸入密碼則成功,失敗則重新開始


[oracle]crontab -l

crontab -e

00 22 * * * /home/backup/backup.sh >/home/backup/test.log 2>&1 &

時 分 日月周 執行sh                輸出至


more backup.sh

ORACLE_HOME/bin/rman target / log=/home/backup/rman.log cmdfile=/home/backup/rman.txt

exit


more rman.txt

sql 'alter system archive log current';

sql 'alter session set nls_date_format="dd.mm.yyyy hh24:mi:ss"';

RUN

{

configure controlfile autobackup on;

set command id to 'backup4oa';

ALLOCATE CHANNEL c1 DEVICE TYPE disk;

ALLOCATE CHANNEL c2 DEVICE TYPE disk;

backup AS COMPRESSED BACKUPSET full database tag ORCL_FULL format '/backup/%T_%d_%T_%s_%p

_FULL';

sql 'alter system archive log current';

backup tag ORCL_ARCHIVE format '/backup/%T_%d_%T_%s_%p_ARCHIVE' archivelog all delete all

 input;

backup tag ORCL_CONTROL current controlfile format '/backup/%T_%d_%T_%s_%p_CONTROLFILE';

backup spfile format= '/backup/%T_%d_%T_%s_%p_SPFILE';

release channel c1;

release channel c2;

}

exit;

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/21302630/viewspace-1571519/,如需轉載,請註明出處,否則將追究法律責任。

相關文章