Backup incremental level and scripts

1. Full backup

run {

allocate channel 'dev1' type disk   ;

allocate channel 'dev2' type disk ;

allocate channel 'dev3' type disk ;

backup full  tag 'dbfull' format '/o9i/testrman/full%u_%p_%c' database ;

sql 'alter system archive logcurrent' ;

backup filesperset 3   archivelog all delete input;

release channel dev1;

release channel dev2;

release channel dev3;

}

 

2. Level0 backup(Except the offline tablespace)

run {

allocate channel 'dev1' type disk   ;

allocate channel 'dev2' type disk ;

allocate channel 'dev3' type disk ;

backup incremental level 0  tag 'dbL0' format'/o9i/testrman/basic%u_%p_%c' database skip readonly;

sql 'alter system archive logcurrent' ;

backup filesperset 3   archivelog all delete input;

release channel dev1;

release channel dev2;

release channel dev3;

}

 

3. TheLevel 1 backup

run {

allocate channel 'dev1' type disk   ;

allocate channel 'dev2' type disk ;

allocate channel 'dev3' type disk ;

backup incremental level 1  tag 'dbL1' format'/o9i/testrman/basic%u_%p_%c' ddatabase skip readonly;     # Don't use it if it is unnecessary.

sql 'alter system archive logcurrent' ;

backup filesperset 3   archivelog all delete input;

release channel dev1;

release channel dev2;

release channel dev3;

}

 

4. TheLevel 2 backup

run {

allocate channel 'dev1' type disk;

allocate channel 'dev2' type disk;

allocate channel 'dev3' type disk;

backup incremental level 2  tag 'dbL2' format'/o9i/testrman/basic%u_%p_%c' ddatabase skip readonly;

sql 'alter system archive logcurrent' ;

backup filesperset 3   archivelog all delete input;

release channel dev1;

release channel dev2;

release channel dev3;

}

 

5. Backup someone tablespace(Like ‘users’)

run {

allocate channel 'dev1' type disk   ;

allocate channel 'dev2' type disk ;

allocate channel 'dev3' type disk ;

backup tag 'tsusers' format'/o9i/testrman/basic%u_%p_%c' tablespace users;

sql 'alter system archive logcurrent' ;

backup filesperset 3  archivelog all delete input;

release channel dev1;

release channel dev2;

release channel dev3;

}

 

6. Backup the archive log

run {

allocate channel 'dev1' type disk   ;

allocate channel 'dev2' type disk ;

allocate channel 'dev3' type disk ;

backup filesperset 3 archivelogall delete input;

release channel dev1;

release channel dev2;

release channel dev3;

}

 

7. Backp the CATALOG(Just use the exp/imp)

exp pafile=exp.dat

$ vi exp.dat

userid=rman/rman

file=rmanexp.dmp

 

8. The rman back scripts

/opt/oracle/rman_compbak/bin

/opt/oracle/rman_compbak/data

/opt/oracle/rman_compbak/arch

/opt/oracle/rman_compbak/log

In the bin folder:

--- 1). Filename: backup_cldb.cmd

run {
#Hot database level 0 whole backup
#allocate channel t1 type disk connect 'sys/oracle';
#allocate channel t2 type disk connect 'sys/oracle';
allocate channel t1 type disk;
allocate channel t2 type disk;
backup
  incremental level 0
  #skip inaccessible
  #filesperset 6 
  #recommended format
  format '/opt/oracle/rman_compbak/data/db_%s_%p_%T_%d'
  # AS COMPRESSED backupset
  (database);
  #delete obsolete;
sql 'alter system archive log current';
#backup all archive logs
backup
  #skip inaccessible
  #filesperset 10
  format '/opt/oracle/rman_compbak/arch/arclogback_%s_%p_%t_%d'
  # AS COMPRESSED backupset
  (archivelog all delete input);
  #delete obsolete;
BACKUP
  FORMAT '/opt/oracle/rman_compbak/data/cntrl_%s_%p_%t'
  CURRENT CONTROLFILE;
release CHANNEL t1 ;
release CHANNEL t2 ;
}

--- 2). Filename: backup_db.sh

rman target / nocatalog cmdfile=/opt/oracle/rman_compbak/bin/backup_cldb.cmd 1>>/opt/oracle/rman_compbak/log/backup_db.log 2>&1

--- 3). Filename: arch_back.cmd

run {
allocate channel t1 type disk;
sql 'alter system archive log current';
#backup all archive logs
backup
  skip inaccessible
  #filesperset 10
  format '/opt/oracle/rman_compbak/arch/arclogback_%s_%p_%t_%d'
  # AS COMPRESSED backupset
  (archivelog all delete input);
#delete obsolete;
release CHANNEL t1 ;
}

--- 4). Filename: arch_back.sh

rman target / nocatalog cmdfile=/opt/oracle/rman_compbak/bin/arch_back.cmd 1>>/opt/oracle/rman_compbak/log/backup_arch.log 2>&1

 

9. Add the jobs

Login using the rootuser:

# crontab -e 

Add two rows:

# 2:00 am erveryday

0 2 * * * su - oracle -c/opt/oracle/rman_compbak/bin/backup_db.sh

#ervery 3 hours(If the full backup didn’t finished in the 4 hours, don’tbegin to backup the archive, and need to delay.)

0 0,6,9,12,15,18,21 * * * su - oracle -c /opt/oracle/rman_compbak/bin/arch_back.sh

你可能感兴趣的:(Backup incremental level and scripts)