You are on page 1of 4

ASM MD_BACKUP and MD_RESTORE:-->

md_backup command and md_restore are used to obtain the SQL statements to recreate the disk groups and
all the dependencies such as directories, templates, aliases and disk group attributes.

When we restore RMAN backup to a lost diskgroup or to a different server we will get errors something like
ORA-01119: error in creating database file ...
ORA-17502: ksfdcre:4 Failed to create file ...
ORA-15001: diskgroup "DATA" does not exist or is not mounted

md_backup
An ASM instance doesnt store data. It maintains the storage metadata such as the names of the disk groups,
directories, and so on and stores this metadata in the disk headers. This means that if there is a disk crash and
we lose the disk headers, were in trouble. we can use RMAN to restore a backup for the database itself, but
well have to first re-create the ASM disk groups and directories. If we havent kept careful records, were in
trouble again. Even if we have the records, we must still take the time to re-create the necessary ASM
metadata. In Oracle Database 11g, the ASMCMD utility is extended to provide ASM metadata backup and
restore functionality through the md_backup and md_restore commands. This functionality is known as the
ASM metadata backup and restore (AMBR). The goal is to enable you to easily re-create an ASM disk group
with an identical template and alias directory structure, using the backup of the ASM metadata. This eliminates
the need for manually re-creating the disk groups and the necessary directories or templates following the loss
of an ASM disk group. The new md_backup option in Oracle Database 11g lets you perform an ASM metadata
backup for a disk group. The command will back up into a backup text file, disk group metadata including fail
groups, disks, attributes, aliases, and templates. Heres the syntax of the md_backup command:
md_backup [-b <backup_file>]
[-g '<diskgroup_name>,<diskgroup_name>,...']
The following lists the various flags and their meanings:
Fla
g

Description

-b

Specifies the location in which you want to store the


intermediate backup file.

-g

Specifies the diskgroup name that needs to be backed up.

The -b option lets you specify the backup file to store the information. By default, the filename is
ambr_backup_intermediate_file.
The -g option lets you specify the disk groups to back up. The command backs up all disk groups by default.
md_backup is ran from the ASMCMD> prompt. It very simply creates a file that is a backup of your metadata,
for all of your disk groups, or just a few if you want to specify. By default, it writes to the current directory and

backs up all of the mounted disk groups header files. Heres an example showing how to use the md_backup
command to back up a single disk group named admdsk1.
ASMCMD> md_backup -b /tmp/dgbackup070222 -g admdsk1
The md_backup command shown here uses the -g option to create a backup of the disk group admdsk1 and
saves it in the /tmp/ dgbackup070222 file. The -b option specifies that the backup information containing the
ASM metadata be recorded in the file named asmblp1 instead of in the default file named
ambr_backup_intermediate_file.
md_restore
The md_restore command is the counterpart of the md_backup command and helps us restore the ASM
metadata for a disk group. Before we can restore data files in a disk group, we must first restore the disk group
using this command. The md_restore command has the following syntax:
md_restore -b <backup_file> [-li]
[-t (full)|nodg|newdg] [-f <sql_script_file>]
[-g '<diskgroup_name>,<diskgroup_name>,...']
[-o '<old_diskgroup_name>:<new_diskgroup_name>,...']
The following lists the various flags and their meanings:

Flag

Description

-b

Reads the metadata information from backup_file.

-l

Prints the messages to a file.

-i or
--silent

If md_restore encounters an error, it will stop. Specifying this flag


ignores any errors.

-t

Specifies the type of diskgroup to be created:


full - Create diskgroup and restore metadata.
nodg - Restore metadata only.
newdg - Create diskgroup with a different name and restore
metadata, -o is required to rename.

-f or -S

Write SQL commands to sql_script_file instead of executing them.

-g or -G

Select the diskgroups to be restored. If no diskgroups are defined,


then all diskgroups will be restored.

-o

Rename diskgroup old_dg_name to new_dg_name.

We can initiate the creation of a disk group as well as restore its metadata by executing the md_restore
command. The following examples show how to use this command in various scenarios:
Restoring a disk group from the backup script and creating a copy:
ASMCMD> md_restore -t full -g asmdsk1 -i backup_file
Restoring an existing disk groups metadata:

ASMCMD> md_restore -t nodg - asmdsk1 -i backup_file


Restoring a disk group and creating a new disk group:
ASMCMD> md_restore -t newdg -o 'DGNAME=asmdsk1:asmdsk2' -i backup_file
The md_restore command restores the disk groups, creates the attributes such as disk_repair_time, modifies
the templates, and creates the directories. Its important to understand that any data in the disk groups will be
lost, however. The md_restore command creates a disk group and the directories without any data. The
md_restore uses the backup file created by md_backup command, which backs up just the ASM metadata. You
must use your RMAN database backups to restore the information on the re-created disk groups. The following
md_restore command example specifies the -f flag to create a text file with the commands to create the disk
groups, directories, and so on.
ASMCMD> md_restore -b dgroup1.backup -t full -f create_dgroup1.sql
You can execute the md_restore command with the -f option on a regular basis to maintain a record of the ASM
metadata.

This script will help us to take metadata backup


dtm='date +%d%m%y%H%M%S'
LOG_FILE=/tmp/asm_backup.${dtm}

rm /app/oracle/TEST/backup/export/asm_dg.backup
HOSTNAME='hostname'
if [ -s /etc/oratab ] ; then
ORATAB=/etc/oratab
elif [ -s /var/opt/oracle/oratab ] ; then
ORATAB=/var/opt/oracle/oratab
elif [ -s /etc/opt/oracle/oratab ] ; then
ORATAB=/etc/opt/oracle/oratab
else
echo "ORATAB is missing" 2>&1 1>> $LOG_FILE
cat $LOG_FILE
exit 1
fi
cat ${ORATAB}|awk -F\# '{print $1}'|grep -v '^$'|awk -F\: '{print $1" "$2" "$3}' |while read ORACLE_SID
ORACLE_HOME BOOT_FLAG
do
if [ "${ORACLE_SID}" = "+ASM" -a "${BOOT_FLAG}" = "Y" ] ; then
export ORACLE_SID
export ORACLE_HOME
export BOOT_FLAG
PATH=$ORACLE_HOME/bin:$PATH
export PATH
asmcmd lsdg
asmcmd md_backup -b /app/oracle/TEST/backup/export/asm_dg.backup
#ASMCMD> md_restore -t full -g RECOVER /tmp/dg.backup
fi
done

NOTE:- it will not restore datafile or any other files which was there on that diskgroup we'll have to use RMAN to

restore those missing files.

You might also like