Wednesday, January 9, 2013

Database Backup - Your First Approach

-- This Article describe the actual steps done in order to backup a database
-- These are the most basic manual steps but also the most effective

-- The most basic steps are the following
 -- 1. Change database to work in ARCHIVE LOG mode
 -- 2. Perform a full backup for first time from OS
 -- 3. Create rman catalog database, register your database
 -- 4. Backup your database FULL Backup monthly, Incremental levle 0 weekly, Incremental levle 1 daily

-- Here are the actual steps

-------------------------------------------------------------------------------------------
-- Step 1: Enable Archive log mode

-- A good practice to have a separate area for backing up every thing so we create a filesystem called /backup under which we create a folder for archived logs named archived_logs & another folder for the flash area for each database and will named _flash_rec_area

-- 1. Set Archive log destination
> export ORACLE_SID=
> sqlplus / as sysdba
SQL> alter system set log_archive_dest_1='LOCATION=/backup/archived_logs' scope = both;
SQL> archive log list    -- To check the changes

-- 2. Enable Archive log mode
SQL> shutdown immediate
SQL> startup mount
SQL> alter database archivelog;
SQL> alter database open;

-- To generate some archives and to see them
SQL> alter system switch logfile;
SQL> /
SQL> /
SQL> archive log list
SQL> host ls /backup/archived_logs
------------------------------------------------------------------------------------------------

-- Step 2: Shutdown the database and perform a full backup from OS

-- 1. shutdown database
> sqlplus / as sysdba
SQL> shutdown immediate
SQL> quit

-- 2. Set the flash recovery area for the target database
-- we will put it also under the backup file system we created
SQL> alter system set db_recovery_file_dest = '/backup/db11g_flash_rec_area' scope=both;

-- 3. backup the folder that coantains all database files to the flash area of database
> cd /u01/app/oracle/oradata
> cp -R db11g /backup/db11g_flash_rec_area/db11g_FIRST_FULL_BACKUP
-------------------------------------------------------------------------------------------------------

-- Step 3: Create rman catalog database, register your target database into it
-- in 11g it need about 1.5GB of space

-- 1. using dbca create new DB named rman with no sample schemas or EM control
-- just the database

-- 2. create rman user and grant him the required resources
> export ORACLE_SID=rman
> sqlplus / as sysdba
SQL> create user rman identified by rman
     default tablespace users
     temporary tablespace temp;
SQL> grant resource, connect to rman;
SQL> grant recovery_catalog_owner to rman;
SQL> alter user rman quota unlimited on users;
SQL> quit;

-- 3. create rman catalog
> cd $ORACLE_HOME/bin
> ./rman catalog rman@rman
RMAN> create catalog;
RMAN> quit

-- To verify the catalog creation check its tables and views
> export ORACLE_SID=rman
> sqlplus rman@rman
SQL> select table_name from user_tables;
SQL> select view_name from user_views;
SQL> quit;

-- 4. register the target database into rman catalog
> export ORACLE_SID=db11g
> cd $ORACLE_HOME/bin
> ./rman catalog rman@rman target /
RMAN> register database;
RMAN> quit;
-------------------------------------------------------------------------------------------------------


-- Step 4: Backup your database FULL Backup monthly, Incremental levle 0 weekly, Incremental levle 1 daily

-- First To see ALL rman settings
> export ORACLE_SID=db11g
> cd $ORACLE_HOME/bin
> ./rman catalog rman@rman target /

RMAN> show all;

-- see the current files of your target database
RMAN> report schema;

-- 1. backup the target database full backup monthly
RMAN> backup database tag=JAN_2013;                        -- Repeat every month

-- 2. backup the target database incremental level 0 weely
RMAN> backup incremental level=0 database tag=WEEK_1;     -- Repeat every week

-- 3. backup the target database incremental level 1 daily
RMAN> backup incremental level=1 database tag=SAT;        -- Repeat every day

RMAN> quit;

No comments: