asmcmd use and options

15
ASM HANDS-ON TRAINING Lab 21 ASMCM Use And Options Alejandro Vargas | Principal Support Consultant Oracle Advanced Customer Services INDEX Summary ....................................................................................................................................................................... 2 Asmcmd -p .................................................................................................................................................................... 2 cp ................................................................................................................................................................................... 3 du ................................................................................................................................................................................... 5 find ................................................................................................................................................................................. 6 ls .................................................................................................................................................................................... 7 lsct ................................................................................................................................................................................. 8 md_backup and md_restore ....................................................................................................................................... 11 remap .......................................................................................................................................................................... 15 Other commands ......................................................................................................................................................... 15 1/15

Upload: arwahannan

Post on 28-Apr-2015

13 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: ASMCMD Use and Options

ASM HANDS-ON TRAININGLab 21 ASMCM Use And Options

Alejandro Vargas | Principal Support ConsultantOracle Advanced Customer Services

INDEX

Summary ....................................................................................................................................................................... 2 Asmcmd -p .................................................................................................................................................................... 2 cp ................................................................................................................................................................................... 3 du ................................................................................................................................................................................... 5 find ................................................................................................................................................................................. 6 ls .................................................................................................................................................................................... 7 lsct ................................................................................................................................................................................. 8 md_backup and md_restore ....................................................................................................................................... 11 remap .......................................................................................................................................................................... 15 Other commands ......................................................................................................................................................... 15

1/15

Page 2: ASMCMD Use and Options

ASM HANDS-ON TRAININGLab 21 ASMCM Use And Options

Summary

On this lab we will review some of the useful set of commands provided by the ASM command line utility.

Some of the asmcmd commands display information, these information is based on v$asm views, other commands actually make changes to the structure like mkdir or rm.

Asmcmd -p

Invoiking asmcmd with the –p parameter enables showing the path at asmcmd’s prompt

[oracle@asmxpt ~]$ asmcmd -pASMCMD [+] > cd +DATADGER/SATI11/DATAFILEASMCMD [+DATADGER/SATI11/DATAFILE] > lsSOE.270.679170079SOEINDEX.271.679170087SYSAUX.260.679144103SYSTEM.259.679144027UNDOTBS1.261.679144167USERS.262.679144213

2/15

Page 3: ASMCMD Use and Options

ASM HANDS-ON TRAININGLab 21 ASMCM Use And Options

cp

To copy files from ASM to ASM or to ASM to File System or from File System to ASM.

On this example we copy the controlfile to a backup directory

ASMCMD> cd DATADGER/sati11/parameterfileASMCMD> lsspfile.256.679143615spfilesati11.oraASMCMD> cp spfilesati11.ora /u01/app/oracle/BACKUP/sati11copying +DATADGER/sati11/parameterfile/spfilesati11.ora -> /u01/app/oracle/BACKUP/sati11/spfilesati11.ora

The cp command can be used also to copy files over the network, it accepts the following parameters

-i Interactive, prompt before copy file or overwrite-f Force, if an existing destination file, remove it and try again without user interaction-r Recursive, copy forwarding sub-directories recursively

On this example we make a backup of the whole database sati12 to FS, first we generate a script that contain copy commands.

To generate the script we use from the OS prompt the asmcmd ls command with the full path top the datafile directory

asmcmd ls DATADGCLN/sati11/datafile | awk '{print "asmcmd cp +DATADGCLN/sati11/datafile/"$1" /u01/app/oracle/BACKUP/sati12/"$1}' >asmcpfiles

[oracle@asmxpt]$ mkdir /u01/app/oracle/BACKUP/sati12[oracle@asmxpt sati12]$ asmcmd ls DATADGCLN/sati11/datafile | awk '{print "asmcmd cp

3/15

Page 4: ASMCMD Use and Options

ASM HANDS-ON TRAININGLab 21 ASMCM Use And Options

+DATADGCLN/sati11/datafile/"$1" /u01/app/oracle/BACKUP/sati12/"$1}' >asmcpfiles[oracle@asmxpt sati12]$ chmod 700 asmcpfiles[oracle@asmxpt sati12]$ ./asmcpfilescopying +DATADGCLN/sati11/datafile/SYSAUX.260.679144103 -> /u01/app/oracle/BACKUP/sati12/SYSAUX.260.679144103copying +DATADGCLN/sati11/datafile/SYSTEM.259.679144027 -> /u01/app/oracle/BACKUP/sati12/SYSTEM.259.679144027copying +DATADGCLN/sati11/datafile/UNDOTBS1.261.679144167 -> /u01/app/oracle/BACKUP/sati12/UNDOTBS1.261.679144167copying +DATADGCLN/sati11/datafile/USERS.262.679144213 -> /u01/app/oracle/BACKUP/sati12/USERS.262.679144213

[oracle@asmxpt sati12]$ ls -l /u01/app/oracle/BACKUP/sati12total 1971520-rwx------ 1 oracle dba 438 Feb 20 07:56 asmcpfiles-rw-r----- 1 oracle dba 664477696 Feb 20 07:57 SYSAUX.260.679144103-rw-r----- 1 oracle dba 734011392 Feb 20 07:58 SYSTEM.259.679144027-rw-r----- 1 oracle dba 361766912 Feb 20 08:00 UNDOTBS1.261.679144167-rw-r----- 1 oracle dba 256581632 Feb 20 08:00 USERS.262.679144213

4/15

Page 5: ASMCMD Use and Options

ASM HANDS-ON TRAININGLab 21 ASMCM Use And Options

du

Display total space used for files on the current directory recursively. The output show two values, the first one is the total amount of data, and the second is this value multiplied by the number of mirrors, when using external redundancy both values will be the same. The –H flag suppress the headers. Note that lsdg show the total and free space, while du shoe the used space and total space used by all mirrors if used.

ASMCMD> lsdgState Type Rebal Sector Block AU Total_MB Free_MB Req_mir_free_MB Usable_file_MB Offline_disks NameMOUNTED EXTERN N 512 4096 1048576 4094 1677 0 1677 0 DATADGCLN/MOUNTED EXTERN N 512 4096 1048576 4094 1482 0 1482 0 DATADGER/MOUNTED EXTERN N 512 4096 1048576 6141 2815 0 2815 0 FRADG/ASMCMD> duUsed_MB Mirror_used_MB 8193 8193ASMCMD> du -H 8193 8193

ASMCMD> du DATADGCLN/Used_MB Mirror_used_MB 2364 2364ASMCMD> du DATADGER/Used_MB Mirror_used_MB 2559 2559ASMCMD> du FRADG/Used_MB Mirror_used_MB 3270 3270

5/15

Page 6: ASMCMD Use and Options

ASM HANDS-ON TRAININGLab 21 ASMCM Use And Options

find

Find permit to display file names stored on ASM according to file type or name pattern, the file types that can be used for searching are the following

ARCHIVELOG, AUTOBACKUP, BACKUPSET, CHANGETRACKING, CONTROLFILE, DATAFILE, ONLINELOG, PARAMETERFILE and TEMPFILE

The following command locates all spfiles on all directories. ASM root directory is indicated by the plus sign ‘+’

ASMCMD> find + *spfile*+DATADGCLN/SATI11/PARAMETERFILE/spfile.256.679143615+DATADGCLN/SATI11/PARAMETERFILE/spfilesati11.ora+DATADGER/SATI11/PARAMETERFILE/spfile.256.679143615+DATADGER/SATI11/PARAMETERFILE/spfilesati11.ora

The following command find all controlfiles on all directories under the root directory

ASMCMD> find -t CONTROLFILE + *+DATADGCLN/SATI11/CONTROLFILE/current.257.679143905+DATADGCLN/SATI11/CONTROLFILE/current.258.679143907+DATADGCLN/SATI12/CONTROLFILE/Current.270.679159021+DATADGCLN/SATI12/CONTROLFILE/Current.271.679159021+DATADGER/SATI11/CONTROLFILE/current.257.679143905+DATADGER/SATI11/CONTROLFILE/current.258.679143907

6/15

Page 7: ASMCMD Use and Options

ASM HANDS-ON TRAININGLab 21 ASMCM Use And Options

ls

ls can be used the same way as the OS ls command to list files and directory. There are several useful flags that can be used together with ls

• ls -l displays striping and redundancy information• ls -s displays file space information. • ls -d displays information about the directory• ls -r sort the output in reverse order• ls -t sorts the output by timestamp• ls -L displays information about the file that referenced by an alias• ls -a displays the absolute path of aliases• ls -g includes the INST_ID useful on a cluster environment• ls -H Does not display column headings.

ASMCMD> ls DATADGER/sati11/datafileSOE.270.679170079SOEINDEX.271.679170087SYSAUX.260.679144103SYSTEM.259.679144027UNDOTBS1.261.679144167USERS.262.679144213ASMCMD> ls -l DATADGER/sati11/datafileType Redund Striped Time Sys NameDATAFILE UNPROT COARSE FEB 19 20:00:00 Y SOE.270.679170079DATAFILE UNPROT COARSE FEB 19 20:00:00 Y SOEINDEX.271.679170087DATAFILE UNPROT COARSE FEB 20 13:00:00 Y SYSAUX.260.679144103DATAFILE UNPROT COARSE FEB 19 20:00:00 Y SYSTEM.259.679144027DATAFILE UNPROT COARSE FEB 19 20:00:00 Y UNDOTBS1.261.679144167

7/15

Page 8: ASMCMD Use and Options

ASM HANDS-ON TRAININGLab 21 ASMCM Use And Options

DATAFILE UNPROT COARSE FEB 19 20:00:00 Y USERS.262.679144213ASMCMD> ls -s DATADGER/sati11/datafileBlock_Size Blocks Bytes Space Name 8192 8202 67190784 69206016 SOE.270.679170079 8192 5121 41951232 42991616 SOEINDEX.271.679170087 8192 89993 737222656 739246080 SYSAUX.260.679144103 8192 89601 734011392 736100352 SYSTEM.259.679144027 8192 53121 435167232 437256192 UNDOTBS1.261.679144167 8192 31321 256581632 257949696 USERS.262.679144213ASMCMD> ls -ds DATADGER/sati11/datafileBlock_Size Blocks Bytes Space Name datafile/

lsct

This command display the ASM clients, that is the databases that have files based on ASM and are connected to it. The diskgrpoup name is optional. Adding the –g flag display the instance ID, that is useful on cluster environments. –H suppress the headers

ASMCMD> lsct DATADGCLNDB_Name Status Software_Version Compatible_version Instance_Name Disk_Groupsati12 CONNECTED 11.1.0.7.0 11.1.0.0.0 sati12 DATADGCLNASMCMD> lsct -g DATADGCLNInstance_ID DB_Name Status Software_Version Compatible_version Instance_Name Disk_Group 1 sati12 CONNECTED 11.1.0.7.0 11.1.0.0.0 sati12 DATADGCLNASMCMD> lsct -gH 1 sati11 CONNECTED 11.1.0.7.0 11.1.0.0.0 sati11 DATADGER 1 sati11 CONNECTED 11.1.0.7.0 11.1.0.0.0 sati11 FRADG 1 sati12 CONNECTED 11.1.0.7.0 11.1.0.0.0 sati12 DATADGCLN

lsdsk

8/15

Page 9: ASMCMD Use and Options

ASM HANDS-ON TRAININGLab 21 ASMCM Use And Options

This command display the information related to ASM disks, there are several flags that can be used to control the output, they can be mixed to join in te output the columns contained displayed by each flag

• lsdsk -k display capacity information• lsdsk -s display throughput and performance information.• lsdsk -p display status information.• lsdsk -t display time related information• lsdsk -g includes INST_ID , useful on a cluster environment• lsdsk -d restricts output to disks that belong to an specific group

ASMCMD> lsdsk -k *VOLCLN1Total_MB Free_MB OS_MB Name Failgroup Library Label UDID Product Redund Path 2047 841 2047 VOL1ER VOL1ER ASM Library-Generic Linux,version2.0.3(KABI_V2) VOLCLN1 UNKNOWN ORCL:VOLCLN1

ASMCMD> lsdsk -s Reads Write Read_Errs Write_Errs Read_time Write_Time Bytes_Read Bytes_Written Path167668 108023 0 0 1099.812 894.324 2914014208 1302784000 ORCL:VOL1ER 64299 46999 0 0 670.528 352.968 1141705728 517582848 ORCL:VOL2ER 157 21318 0 0 1.446 142.262 2504192 139489280 ORCL:VOLBLK1 1544 1498 0 0 40.869 31.563 958976 51897856 ORCL:VOLBLK3 39 487 0 0 .547 28.462 159744 52272128 ORCL:VOLBLK4 19237 21664 0 0 508.275 76.133 115082752 96664576 ORCL:VOLCLN1 18177 1155 0 0 519.998 13.405 94441472 13027328 ORCL:VOLCLN2

ASMCMD> lsdsk -pGroup_Num Disk_Num Incarn Mount_Stat Header_Stat Mode_Stat State Path 2 0 3916047300 CACHED MEMBER ONLINE NORMAL ORCL:VOL1ER 2 1 3916047301 CACHED MEMBER ONLINE NORMAL ORCL:VOL2ER 3 0 3916047302 CACHED MEMBER ONLINE NORMAL ORCL:VOLBLK1 3 1 3916047303 CACHED MEMBER ONLINE NORMAL ORCL:VOLBLK3 3 2 3916047304 CACHED MEMBER ONLINE NORMAL ORCL:VOLBLK4 1 0 3916047298 CACHED MEMBER ONLINE NORMAL ORCL:VOLCLN1 1 1 3916047299 CACHED MEMBER ONLINE NORMAL ORCL:VOLCLN2

9/15

Page 10: ASMCMD Use and Options

ASM HANDS-ON TRAININGLab 21 ASMCM Use And Options

ASMCMD> lsdsk -tCreate_Date Mount_Date Repair_Timer Path18-FEB-09 19-FEB-09 0 ORCL:VOL1ER18-FEB-09 19-FEB-09 0 ORCL:VOL2ER12-FEB-09 19-FEB-09 0 ORCL:VOLBLK112-FEB-09 19-FEB-09 0 ORCL:VOLBLK318-FEB-09 19-FEB-09 0 ORCL:VOLBLK418-FEB-09 19-FEB-09 0 ORCL:VOLCLN118-FEB-09 19-FEB-09 0 ORCL:VOLCLN2

10/15

Page 11: ASMCMD Use and Options

ASM HANDS-ON TRAININGLab 21 ASMCM Use And Options

md_backup and md_restore

Useful to create a backup of the structure of a diskgroup that can be restored at any time or used to generate a script that can be used to rebuild a directory structure and redundancy related configuration.

The metadata backup contains only definitions of directory structures and some configuration details but no data itself. It is useful to rebuild diskgroups before restoring a full backup.

md_backup has 2 flags, -b backup file name and –g diskgroup name

md_restore has several flags that permit to control its behavior to trigger different actions like create diskgroups, or create only directories, or write the output to an sql script

md_restore -b <use this backup_file>. md_restore -b <file> -t full : create disk group and restore metadata. md_restore -b <file> -t nodg : restore metadata only. md_restore -b <file> -t newdg -o ‘old_name:new_name’ : create and rename disk group old_name to new_name md_restore -b <file> -f <name.sql> : write the sql commands that rebuild metada on the <name.sql> script. md_restore -b <file> -g <dskgrp> : restore only diskgroup <dskgrp>, if not used restore all dg’s in the backup

This example backup metadata off all diskgroups

[oracle@asmxpt sati11]$ asmcmd md_backup -b ./sati11_and_sati12_md_backupDisk group to be backed up: DATADGCLNDisk group to be backed up: DATADGERDisk group to be backed up: FRADGCurrent alias directory path: SATI12Current alias directory path: SATI11/CONTROLFILECurrent alias directory path: SATI12/CONTROLFILECurrent alias directory path: SATI11

11/15

Page 12: ASMCMD Use and Options

ASM HANDS-ON TRAININGLab 21 ASMCM Use And Options

Current alias directory path: SATI12/CHANGETRACKINGCurrent alias directory path: SATI11/DATAFILECurrent alias directory path: SATI11/TEMPFILECurrent alias directory path: SATI11/ONLINELOGCurrent alias directory path: SATI11/PARAMETERFILECurrent alias directory path: SATI11/DATAFILECurrent alias directory path: SATI11/ONLINELOGCurrent alias directory path: SATI11/TEMPFILECurrent alias directory path: SATI11/CONTROLFILECurrent alias directory path: SATI11Current alias directory path: SATI11/PARAMETERFILECurrent alias directory path: SATI11/ARCHIVELOG/2009_02_18Current alias directory path: SATI11/BACKUPSETCurrent alias directory path: SATI11Current alias directory path: SATI12/BACKUPSETCurrent alias directory path: SATI12/ARCHIVELOG/2009_02_18Current alias directory path: SATI11/AUTOBACKUPCurrent alias directory path: SATI12/ARCHIVELOGCurrent alias directory path: SATI12/BACKUPSET/2009_02_20Current alias directory path: SATI11/CHANGETRACKINGCurrent alias directory path: SATI11/BACKUPSET/2009_02_18Current alias directory path: SATI12Current alias directory path: SATI11/ARCHIVELOG/2009_02_17Current alias directory path: SATI11/ARCHIVELOGCurrent alias directory path: SATI11/AUTOBACKUP/2009_02_18Current alias directory path: SATI11/AUTOBACKUP/2009_02_12Current alias directory path: SATI11/ARCHIVELOG/2009_02_20Current alias directory path: SATI11/DATAFILECurrent alias directory path: SATI11/ARCHIVELOG/2009_02_19Current alias directory path: SATI11/BACKUPSET/2009_02_17

12/15

Page 13: ASMCMD Use and Options

ASM HANDS-ON TRAININGLab 21 ASMCM Use And Options

These command backups metadata of each database diskgroup separately

[oracle@asmxpt sati11]$ asmcmd md_backup -b ./sati11_md_backup -g 'DATADGER'Disk group to be backed up: DATADGERCurrent alias directory path: SATI11/TEMPFILECurrent alias directory path: SATI11/CONTROLFILECurrent alias directory path: SATI11/DATAFILECurrent alias directory path: SATI11Current alias directory path: SATI11/ONLINELOGCurrent alias directory path: SATI11/PARAMETERFILE

[oracle@asmxpt sati11]$ asmcmd md_backup -b ./sati12_md_backup -g 'DATADGCLN'Disk group to be backed up: DATADGCLNCurrent alias directory path: SATI12Current alias directory path: SATI11/CONTROLFILECurrent alias directory path: SATI12/CONTROLFILECurrent alias directory path: SATI11Current alias directory path: SATI12/CHANGETRACKINGCurrent alias directory path: SATI11/DATAFILECurrent alias directory path: SATI11/TEMPFILECurrent alias directory path: SATI11/ONLINELOGCurrent alias directory path: SATI11/PARAMETERFILE

We cannot restore the metadata now that we have actual data on our diskgroups but we can write the commands to a script

[oracle@asmxpt sati11]$ asmcmd md_restore -b ./sati12_md_backup -f ./sati12_md_backup.sqlCurrent Diskgroup being restored: DATADGCLN

[oracle@asmxpt sati11]$ cat ./sati12_md_backup.sqlcreate diskgroup DATADGCLN EXTERNAL redundancy disk 'ORCL:VOLCLN1' name VOL1ER size 2047M disk

13/15

Page 14: ASMCMD Use and Options

ASM HANDS-ON TRAININGLab 21 ASMCM Use And Options

'ORCL:VOLCLN2' name VOL2ER size 2047M ;alter diskgroup /*ASMCMD AMBR*/DATADGCLN alter template ASM_STALE attributes (UNPROTECTED COARSE);alter diskgroup /*ASMCMD AMBR*/DATADGCLN alter template FLASHBACK attributes (UNPROTECTED FINE);alter diskgroup /*ASMCMD AMBR*/DATADGCLN alter template CONTROLFILE attributes (UNPROTECTED FINE);alter diskgroup /*ASMCMD AMBR*/DATADGCLN alter template BACKUPSET attributes (UNPROTECTED COARSE);alter diskgroup /*ASMCMD AMBR*/DATADGCLN alter template XTRANSPORT attributes (UNPROTECTED COARSE);alter diskgroup /*ASMCMD AMBR*/DATADGCLN alter template DATAGUARDCONFIG attributes (UNPROTECTED COARSE);alter diskgroup /*ASMCMD AMBR*/DATADGCLN alter template ARCHIVELOG attributes (UNPROTECTED COARSE);alter diskgroup /*ASMCMD AMBR*/DATADGCLN alter template AUTOBACKUP attributes (UNPROTECTED COARSE);alter diskgroup /*ASMCMD AMBR*/DATADGCLN alter template ONLINELOG attributes (UNPROTECTED FINE);alter diskgroup /*ASMCMD AMBR*/DATADGCLN alter template DUMPSET attributes (UNPROTECTED COARSE);alter diskgroup /*ASMCMD AMBR*/DATADGCLN alter template DATAFILE attributes (UNPROTECTED COARSE);alter diskgroup /*ASMCMD AMBR*/DATADGCLN alter template TEMPFILE attributes (UNPROTECTED COARSE);alter diskgroup /*ASMCMD AMBR*/DATADGCLN alter template CHANGETRACKING attributes (UNPROTECTED COARSE);alter diskgroup /*ASMCMD AMBR*/DATADGCLN alter template PARAMETERFILE attributes (UNPROTECTED COARSE);alter diskgroup /*ASMCMD AMBR */ DATADGCLN add directory '+DATADGCLN/SATI11';alter diskgroup /*ASMCMD AMBR */ DATADGCLN add directory '+DATADGCLN/SATI12';alter diskgroup /*ASMCMD AMBR */ DATADGCLN add directory '+DATADGCLN/SATI11/ONLINELOG';alter diskgroup /*ASMCMD AMBR */ DATADGCLN add directory '+DATADGCLN/SATI11/DATAFILE';alter diskgroup /*ASMCMD AMBR */ DATADGCLN add directory '+DATADGCLN/SATI11/CONTROLFILE';alter diskgroup /*ASMCMD AMBR */ DATADGCLN add directory '+DATADGCLN/SATI11/TEMPFILE';alter diskgroup /*ASMCMD AMBR */ DATADGCLN add directory '+DATADGCLN/SATI11/PARAMETERFILE';alter diskgroup /*ASMCMD AMBR */ DATADGCLN add directory '+DATADGCLN/SATI12/CONTROLFILE';alter diskgroup /*ASMCMD AMBR */ DATADGCLN add directory '+DATADGCLN/SATI12/CHANGETRACKING';

14/15

Page 15: ASMCMD Use and Options

ASM HANDS-ON TRAININGLab 21 ASMCM Use And Options

remap

This command permit to repair blocks when there is a read IO error. It will not repair physical corruption. (We will not try this command on the lab)

The syntax is : remap <disk_group_name> <disk_name> <block_range>

Example : remap DATADG ORCL:VOL21 5000-5999

Other commands

There are other commands that we will not test in this lab:

rm to remove files like the os rm command, mkalias/rmalias to create/remove aliases for files and directories, mkdir create directories, rm also remove directories, help display all commands available and help <command> display help on specific commands

End of Lab21

15/15