All technological notes.
Full Backup and Incremental BackupFull Backups
whole database backup.data block in the file.Features:
full backups by default if neither FULL nor INCREMENTAL is specified. 默认备份类型all blocks into the backup set or image copy, skipping only those data file blocks that are not part of an existing segment.
image copy: the entire file contents are reproduced exactly.backup sets: Unused block compression causes never-written blocks to be skipped.注意, 忽略未用 block;忽略不在 segment 的 block.vs incremental backup strategy
full backup
incremental backup strategyincremental backup.incremental backupslevel 0 backup 物理上相同full image copy backup can be incrementally updated by applying incremental backups with the RECOVER command.恢复时, 映像备份可以加载NOARCHIVELOG mode
full or incremental) of a database that is in NOARCHIVELOG mode, if the database is not open.Incremental Backup
level 0 backuplevel 1 backup
Differential: defaultCumulativeIncremental Backups
level 0 backup or a level 1 backup.level 0 backup:
data files except blocks that have never been used.full backup.VS Full backup: 对 level 1 的影响
level 0 backup (as well as an image copy) can be used as the base for a level 1 backupfull backup can never be used as the base for a level 1 backup.level 1 backup:
Differential:
incremental backupincremental backup at either level 1 or level 0.Cumulative:
level 0-- To perform an incremental backup at level 0
BACKUP INCREMENTAL LEVEL 0 DATABASE;
-- To perform a differential incremental backup
BACKUP INCREMENTAL LEVEL 1 DATABASE;
-- To perform a cumulative incremental backup
BACKUP INCREMENTAL LEVEL 1 CUMULATIVE DATABASE;
-- to apply incremental backups to data file image copies.
BACKUP AS COPY INCREMENTAL LEVEL 0 DATABASE;
Image copies are updated with all changes up to the incremental backup SCN.Incremental backup reduces the time required for media recovery.incrementally updated backups, you can use the SWITCH command during the recovery operation.Applying incremental backups to data file image copies:
roll forward (recover) an image copy to the specified point in time by applying the incremental backups to the image copy. 可以将增量备份适用到映像备份上image copy is updated with all changes up through the SCN at which the incremental backup was taken. 通过 SCN, 最终将映像备份更新到增量备份的时间点.media recovery just as it would use a full image copy taken at that SCN 结果与全映像相同Benefits:
full image copy of the database every day.好处是减少日常开销reduce the time required for media recovery (using archive logs)恢复时, 用时短,因为减少使用 archivelog
archive logs only since the last incremental backup.full image copy after the incremental restoration.
incremental backup file, you simply restart the recovery process. RMAN automatically determines the required incremental backup files to apply, from before the image data file copy until the time at which you want to stop the recovery process. 如果恢复失败, 则只需重启恢复即可. 将会自动决定适用文件.catalog, RMAN automatically uses the latest version of the image copy. 自动选择最新的映像备份
image copy.不能合并时,会报错.Example
recover copy of database with tag 'daily inc';
backup incremental level 1 for recover of copy with tag 'daily inc' database;
| RECOVER | BACKUP | |
|---|---|---|
| Day 1 | Nothing | Create image copies |
| Day 2 | Nothing | Create incremental level 1 |
| Day 3 and onward | Recover copies based on incremental | Create incremental level 1 |
RECOVER command does nothing.image copies to recover.BACKUP command creates the image copies.RECOVER command, again, does nothing. This is because there is no incremental backup yet.BACKUP command creates the incremental backup, now that baseline image copies have been created on day 1. 产生第一个增量备份RECOVER command applies the changes from the incremental backup to the image copies.BACKUP command takes another incremental backup, which will be used to recover the image copies on day 4.#!/bin/sh
sqlplus /nolog <<EOF
connect / as sysdba
ALTER SESSION set container=pdb1;
DROP TABLESPACE INVENTORY INCLUDING CONTENTS and DATAFILES CASCADE CONSTRAINTS;
CREATE SMALLFILE TABLESPACE "INVENTORY"
DATAFILE '/u01/app/oracle/oradata/ORCL/pdb1/inventory01.dbf' SIZE 30M,
'/u01/app/oracle/oradata/ORCL/pdb1/inventory02.dbf' size 40M REUSE
AUTOEXTEND ON NEXT 1M MAXSIZE UNLIMITED LOGGING
EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;
drop user inventory cascade;
create user inventory identified by pass4INV
default tablespace inventory;
grant connect, resource to inventory;
ALTER USER inventory QUOTA UNLIMITED ON INVENTORY;
exit;
EOF
sqlplus / as sysdba <<EOF
ALTER SESSION set container=pdb1;
CREATE TABLE INVENTORY.PRODUCT_MASTER
( PRODUCT_ID NUMBER(7)
, PRODUCT_NAME VARCHAR2(50) NOT NULL
, CODE VARCHAR2(10) NOT NULL
, REORDER_THRESHOLD NUMBER(5)
, COST NUMBER(5, 2)
, PRICE NUMBER(5, 2)
, CONSTRAINT PK_INV PRIMARY KEY (PRODUCT_ID) VALIDATE ,
CONSTRAINT CHK_GT_0 CHECK (reorder_threshold > 0) VALIDATE ) TABLESPACE INVENTORY;
CREATE TABLE INVENTORY.PRODUCT_ON_HAND
(
WAREHOUSE_ID NUMBER(3),
PRODUCT_ID NUMBER(7),
QUANTITY NUMBER(5),
WAREHOUSE_CITY VARCHAR2(30),
LAST_UPDATE DATE,
CONSTRAINT PK_POH
PRIMARY KEY (WAREHOUSE_ID, PRODUCT_ID) VALIDATE,
CONSTRAINT FK_PROD_ON_HAND_PROD_ID
FOREIGN KEY (PRODUCT_ID) REFERENCES
INVENTORY.PRODUCT_MASTER (PRODUCT_ID) VALIDATE
);
CREATE TABLE INVENTORY.OBSOLETE_PRODUCTS
AS select product_id, product_name, code, cost, price
from inventory.product_master;
CREATE INDEX INVENTORY.OBS_CODE ON INVENTORY.OBSOLETE_PRODUCTS (CODE);
create index inventory.prod_name_code
on inventory.product_master(product_name,code);
create index inventory.poh_prod_id_qty on
inventory.product_on_hand(product_id, quantity);
set echo on
alter table inventory.product_master nologging
/
insert /*+ append */ into INVENTORY.PRODUCT_MASTER
select
100000 + rownum,
'NAME' || dbms_random.string('a',mod(abs(dbms_random.random),30) + 16),
dbms_random.string('a',10),
mod(abs(dbms_random.random),1000) + 100,
25.25,
50.88
from dba_objects
/
commit
/
insert /*+ append */ into inventory.product_master
select
200000 + rownum,
'NAME' || dbms_random.string('a',mod(abs(dbms_random.random),30) + 16),
dbms_random.string('a',10),
mod(abs(dbms_random.random),1000) + 100,
25.25,
50.88
from dba_objects
/
commit
/
insert /*+ append */ into inventory.product_master
select
300000 + rownum,
'NAME' || dbms_random.string('a',mod(abs(dbms_random.random),30) + 16),
dbms_random.string('a',10),
mod(abs(dbms_random.random),1000) + 100,
25.25,
50.88
from dba_objects
/
commit
/
alter table inventory.product_master logging
/
create index inventory.code_func on inventory.product_master (upper(substr(code,5,2)));
alter table inventory.product_master add (primary_source varchar2(50), secondary_source varchar2(50));
alter table inventory.product_master add (obsoleted date);
exit
EOF
mkdir -p /home/oracle/backup/orcl
run {
-- set channel's name, device type as DISK, set path to store backup
ALLOCATE CHANNEL "chl" DEVICE TYPE DISK FORMAT "/home/oracle/backup/orcl/%U";
-- implement incremental level 0 bacup db as image copies, add tag,
BACKUP AS COPY TAG 'BASE01' INCREMENTAL LEVEL 0 DATABASE;
}
The script performs an incrimental level 0 backup to a specific directory.


#!/bin/sh
sqlplus / as sysdba<<EOF
ALTER SESSION set container=pdb1;
CONNECT inventory/pass4INV@pdb1
/* retrieve a random integer between 1 an 100 use that as a mod function */
/* to change the obsolete date for product ids in the table */
update product_master set obsoleted = SYSDATE
where mod(product_id,100) IN (
select (round(dbms_random.value(1,100))) from dual)
/
commit;
exit
EOF
run {
-- set channel's name, device type as DISK, set path to store backup
ALLOCATE CHANNEL "chl" DEVICE TYPE DISK FORMAT "/home/oracle/backup/orcl/%U";
-- implement incremental level 1 backup, add tag,
BACKUP TAG 'incr_update' INCREMENTAL LEVEL 1 DATABASE;
}

run {
ALLOCATE CHANNEL "chl" DEVICE TYPE DISK FORMAT "/home/oracle/backup/orcl/%U";
RECOVER COPY OF DATABASE WITH TAG 'BASE01';
}

#!/bin/sh
rman target "'/ as sysdba'"<<EOF
delete NOPROMPT backup of tablespace pdb1:INVENTORY;
exit;
EOF
sqlplus /nolog >> /tmp/cleanup.log 2>&1 <<EOF
connect / as sysdba
alter session set container=pdb1;
DROP USER inventory cascade;
DROP TABLESPACE INVENTORY INCLUDING CONTENTS and DATAFILES;
exit
EOF