RMAN

作者: 古飞_数据 | 来源:发表于2023-10-08 09:56 被阅读0次
    
    
    1、RMAN基本概念和命令
    
    
    backup spfile format '/app/rmanbak/spfile_%d_%I_%T_%t.ora';
    
    list backup of spfile completed before 'sysdate';
    
    restore spfile from '/app/rmanbak/spfile_ORCL_1651659091_20230203_1127818641.ora';
    
    
    RMAN> backup current controlfile format '/app/rmanbak/control_%d_%I_%T_%t_%s_%p.ctl';
    list backup of controlfile;
    
    select name from v$controlfile;
    
    --模拟数据插入
    SQL> insert into t1 values(1,'Tome');1 row created.
    SQL> commit;
    --查询控制文件位置
    SQL> select name from v$controlfile;
    --删除控制文件
    SQL> host rm /app/oracle/oradata/ORCL/control01.ctl
    SQL> host rm /app/oracle/oradata/ORCL/control02.ctl
    
    RMAN> restore controlfile from '/app/rmanbak/control_ORCL_1651659091_20230203_1127833229_267_1.ctl';
    
    RMAN> alter database mount;
    RMAN> recover database;
    
    数据库恢复完成之后,必须以resetlogs模式才能打开数据库。
    
    --打开数据库
    RMAN> alter database open;
    RMAN-00571: ===========================================================
    RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
    RMAN-00571: ===========================================================
    RMAN-03002: failure of sql statement command at 02/03/2023 15:24:43
    ORA-01589: must use RESETLOGS or NORESETLOGS option for database open
    --以resetlogs模式打开数据库
    RMAN> alter database open RESETLOGS;
    Statement processed
    
    RMAN> copy datafile 1 to '/home/oracle/rmanback/system01.dbf';
    
    RMAN> list copy;
    list copy of datafile 1;
    
    select file_id,file_name from dba_data_files order by 1;
    
    SQL> host rm /app/oracle/oradata/ORCL/system01.dbf
    
    
    备份时限制备份片的大小
    RMAN> RUN{
    CONFIGURE CHANNEL DEVICE TYPE DISK MAXPIECESIZE 100M;
    BACKUP datafile 1 FORMAT '/app/rmanbak/DATAFILE_SYSTEM_%d_%s_%p_%T';
    CONFIGURE CHANNEL DEVICE TYPE DISK clear;
    };
    
    
    备份时压缩备份集
    RMAN> backup as compressed backupset datafile 1 format='/app/rmanbak/DATAFILE_SYSTEM_%d_%s_%p_%T.dbf';
    
    list backup of datafile 1;
    
    RMAN> run {restore datafile 1;
    recover datafile 1;
    alter database open;}
    
    
    恢复数据文件时改变数据文件的位置
    report schema;
    backup datafile 2 format '/app/rmanbak/DATAFILE_TEST_%d_%s_%p_%T.dbf';
    
    SQL> host rm /app/oracle/oradata/ORCL/test01.DBF
    SQL> startup force;
    
    RMAN> run {set newname for datafile 2 to '/app/oracle/datafile/test.dbf';    
    restore datafile 2;
    switch datafile all;
    recover datafile 2;
    alter database open;} 
    
    report schema;
    
    

    删除rman上周备份,之后再次备份数据库

    vi /home/oracle/scripts/rman_backup.sh
    #!/bin/bash
    source /home/oracle/.bash_profile
    rman target / log /home/oracle/scripts/log/accor_full_bak_`date +"%Y%m%d"`.log << EOF
    run
    {
    report obsolete;
    delete noprompt obsolete;
    delete noprompt backup completed before 'sysdate-7';
    allocate channel c1 device type disk format '+FRADG/*****/BACKUPSET/%U';
    allocate channel c2 device type disk format '+FRADG/*****/BACKUPSET/%U';
    allocate channel c3 device type disk format '+FRADG/*****/BACKUPSET/%U';
    allocate channel c4 device type disk format '+FRADG/*****/BACKUPSET/%U';
    allocate channel c5 device type disk format '+FRADG/*****/BACKUPSET/%U';
    backup as compressed backupset database;
    release channel c1;
    release channel c2;
    release channel c3;
    release channel c4;
    release channel c5;
    }
    exit
    EOF
    
    
    https://blog.csdn.net/liang921119/article/details/129441679
    
    https://blog.csdn.net/liang921119/category_12171421.html
    

    相关文章

      网友评论

          本文标题:RMAN

          本文链接:https://www.haomeiwen.com/subject/vepebdtx.html