Backup / Restore Oracle DB

  • Backup Oracle DB in NOARCHIVELOG mode.In sqlplus console,
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    $ sqlplus / as sysdba (sqlplus /nolog then conn /as sysdba)
    SQL> archive log list;
    SQL> show parameter DB_RECOVERY_FILE_DEST;
    SQL> alter system set db_recovery_file_dest='/flash_recovery_area' scope=both;
    SQL> shutdown immediate;
    SQL> startup mount;
    // at this time, run RMAN> backup database;
    // OR change archive log mode
    SQL> alter database archivelog;
    SQL> alter database open;
    SQL> archive log list;
    SQL> alter system switch logfile; ( OR alter system archive log current)
    SQL> select operation, status, mbytes_processed, start_time, end_time from v$rman_status order by start_time;

If archivelog mode is enabled

1
2
3
4
5
6
7
RMAN> backup incremental level 0 database plus archivelog delete input;
OR
RMAN> backup as compressed backupset incremental level 0 database include current controlfile plus archivelog;
OR
RMAN> backup as compressed backupset incremental level 0 database include current controlfile plus archivelog delete all input;
ADN
RMAN> backup incremental level 1 database plus archivelog delete input;

In rman prompt,

1
2
3
4
5
6
7
8
9
10
11
12
13
$ rman
RMAN> connect target /;
RMAN> list backup;
RMAN> list backup summary;
RMAN> backup as compressed backupset tag 'weeekly_prd01_tbls_bk_only' tablespace prd01;
RMAN> backup as compressed backupset database plus archivelog ;

RMAN> run { # backup directly in noarchive mode
shutdown immediate;
startup mount;
backup database;
alter database open;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
RMAN> show all;
CONFIGURE RETENTION POLICY TO REDUNDANCY 1;
CONFIGURE BACKUP OPTIMIZATION ON;
CONFIGURE DEFAULT DEVICE TYPE TO DISK;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/tmp/backup/%F';
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET;
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1;
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1;
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/tmp/backup/dbkup_%Y%M%D_%U';
CONFIGURE MAXSETSIZE TO UNLIMITED;
CONFIGURE ENCRYPTION FOR DATABASE OFF;
CONFIGURE ENCRYPTION ALGORITHM 'AES128';
CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE;
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE;
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_CHHDEV2.f';

Full version of backup

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/ksh

DATABASE=CHHDEV2

RUNTIME=`date '+%H%M_%d%m%Y'`

BACKUPDIR=/tmp/backup

LOGFILE=${BACKUPDIR}/${ORACLE_SID}_${RUNTIME}.log

LEVEL=0

exec >> ${LOGFILE} 2>&1

$ORACLE_HOME/bin/rman msgno target / nocatalog <<EOF!

CONFIGURE RETENTION POLICY TO REDUNDANCY 3; # default 1

# CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 14 DAYS; # default 1

CONFIGURE BACKUP OPTIMIZATION ON; # default OFF

CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default

CONFIGURE CONTROLFILE AUTOBACKUP ON; # default OFF

CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '${BACKUPDIR}/ora_cf%F'; # default '%F'

CONFIGURE DEVICE TYPE DISK PARALLELISM 3; # default 1

CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default

CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default

CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '${BACKUPDIR}/ora_df%t_s%s_s%p';

CONFIGURE MAXSETSIZE TO UNLIMITED; # default

CONFIGURE SNAPSHOT CONTROLFILE NAME TO '${BACKUPDIR}/snapcf_${DATABASE}.f';

SHOW ALL;

sql "alter system switch logfile";

CROSSCHECK ARCHIVELOG ALL;

# BACKUP AS COMPRESSED BACKUPSET INCREMENTAL LEVEL 0 DATABASE INCLUDE CURRENT CONTROLFILE PLUS ARCHIVELOG DELETE ALL INPUT;

# BACKUP AS COMPRESSED BACKUPSET DATABASE INCLUDE CURRENT CONTROLFILE PLUS ARCHIVELOG DELETE ALL INPUT;

# BACKUP DATABASE INCLUDE CURRENT CONTROLFILE PLUS ARCHIVELOG DELETE ALL INPUT;

# backup AS COMPRESSED BACKUPSET database include current controlfile format '${BACKUPDIR}/ora_df%t_s%s_s%p';

# backup AS COMPRESSED BACKUPSET archivelog UNTIL TIME '(SYSDATE - 1)' not backed up 1 times format '${BACKUPDIR}/ora_arc%t_s%s_s%p';

# delete noprompt archivelog until time '(SYSDATE -1)' backed up 1 times to device type disk;

BACKUP AS COMPRESSED BACKUPSET INCREMENTAL LEVEL ${LEVEL} DATABASE INCLUDE CURRENT CONTROLFILE PLUS ARCHIVELOG;

DELETE NOPROMPT COPY OF ARCHIVELOG ALL COMPLETED BEFORE 'SYSDATE-5';

sql "alter database backup controlfile to trace as ''${BACKUPDIR}/ctrlfile_${DATABASE}_${RUNTIME}''";

allocate channel for maintenance type disk;

delete noprompt obsolete device type disk;

CROSSCHECK BACKUP;

CROSSCHECK ARCHIVELOG ALL;

REPORT OBSOLETE;

DELETE FORCE NOPROMPT OBSOLETE;

DELETE FORCE NOPROMPT expired backup of archivelog all;

DELETE FORCE NOPROMPT expired backup;

LIST BACKUP OF DATABASE;

LIST BACKUP OF ARCHIVELOG ALL;

LIST BACKUP;

release channel;

EXIT

EOF!

exit

  • Store Oracle DB
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    RMAN> SET DBID 70161972;
    RMAN> RUN {
    startup force nomount;
    SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/tmp/backup/%F';
    RESTORE CONTROLFILE to '/tmp/controlfile' FROM AUTOBACKUP;
    RESTORE SPFILE to pfile '/tmp/pfile' FROM AUTOBACKUP;
    //OR
    restore controlfile from autobackup;
    restore spfile from autobackup;

    SET ARCHIVELOG DESTINATION TO '/tmp/temp_restore';
    RESTORE ARCHIVELOG ALL;

    startup mount;
    restore database;
    recover database;
    sql 'alter database open RESETLOGS';
    }

Reference:
https://support.software.dell.com/netvault-backup/kb/140173
http://dbaworkshop.blogspot.hk/2012/07/how-to-backup-database-in-noarchivelog_31.html
http://ss64.com/ora/rman_backup.html
http://www.dba-oracle.com/t_rman_incremental_backups.htm
http://www.dba-oracle.com/concepts/rman_recovery_database_spfile.htm
http://www.dba-oracle.com/concepts/rman.htm
http://www.dba-oracle.com/concepts/rman_online_offline_backups.htm
http://www.dba-village.com/village/dvp_forum.OpenThread?ThreadIdA=44077&DestinationA=RSS
http://docs.oracle.com/cd/E11882_01/backup.112/e10642/rcmadvre.htm
http://docs.oracle.com/cd/B19306_01/backup.102/b14192/recov004.htm#i1032364