Professional Documents
Culture Documents
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
-g
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
-l
-i or
--silent
-t
-f or -S
-g or -G
-o
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:
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