一个数据库备份的例子
1.将数据库停机改为归档模式
SQL> archive log list
SQL> shutdown immediate
SQL> startup mount
SQL> alter database archivelog;
SQL> alter database open;
2.将数据库归档指向ASM
SQL>alter system set db_recovery_file_dest_size = 200G;
SQL>alter system set db_recovery_file_dest = '+DATA';
3.将数据库备份冗余设置为2,将备份文件设置为/home下的某个目录
RMAN>CONFIGURE CONTROLFILE AUTOBACKUP ON; #设置自动备份控制文件
RMAN> CONFIGURE RETENTION POLICY TO REDUNDANCY 2;
RMAN> CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/home/oracle/backup/%U', '+DATA';
设置备份在本地、存储上各有一份:
RMAN>CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 2;
RMAN>CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 2;
4.制定每周全备份一次,每天备份归档或不做任何操作,只在全备份时删除冗余外的归档和备份。
使用crontab来调度脚本实现定时备份数据库,删除归档。
# crontab -l
0 0 * * 6 su - oracle backup.sh //每周6凌晨0点全备数据库
#
# su - oracle
$ cat /home/oracle/app/oracle/product/11.2.0/dbhome_1/bin/backup.sh
rman target / cmdfile=/home/oracle/backup.rman log=/home/oracle/backup _`date +%Y%m%d%H%M%S`.log
$ cat /home/oracle/backup.rman
backup device type disk database plus archivelog delete all input;
allocate channel for maintenance type disk;
delete noprompt obsolete device type disk;
# crontab -l
0 0 * * * su - oracle backuparch.sh //每天凌晨0点备份归档
0 0 * * * su - oracle dellog.sh //每天凌晨0点处理日志,只保存7天日志
#
# su - oracle
$ cat /home/oracle/app/oracle/product/11.2.0/dbhome_1/bin/backuparch.sh
rman target / cmdfile=/home/oracle/backuparch.rman log=/home/oracle/backuparch _`date +%Y%m%d%H%M%S`.log
$ cat /home/oracle/backuparch.rman
backup archivelog all delete input;
$ cat /home/oracle/app/oracle/product/11.2.0/dbhome_1/bin/dellog.sh
find /home/oracle/backup*.log –mtime +7 –exec rm {} \;
作者 “个人记录”
- 发表评论
-
- 最新评论 更多>>