Multiple copies (cp) with Oracle ASM asmcmd tool?

Since no platform or version is mentioned, I assume Unix/Linux and 11gR2.

First of all, check Running ASMCMD in Noninteractive Mode. This explains that we can use ASMCMD in a script so whatever we can dream of, we can script. In this case in order to copy files we can use

asmcmd command options

A simple example is shown here Running ASMCMD commands in a script Change this example slightly to get it to copy all files in a local directory, also using this Using the ASMCMD cp command as input:

ls | while read FILE
do
   asmcmd cp $FILE +data/orcl/datafile/$FILE
done

I am not sure how smart it is to run multiple copies in parallel. It all depends on what your hardware can handle. If you want to run in parallel, run the copies in the background but be a little careful, when running too much in parallel, it will definately cause a slower throughput than running in a sequential way.

For windows it will be slightly different, the loop construct will be different.

I hope this helps.


For example, on Linux (or other Unix-type systems):

for i in $(asmcmd ls +DG_AL/EMREP/ARCHIVELOG/2012_12_04); do
  asmcmd cp +DG_AL/EMREP/ARCHIVELOG/2012_12_04/$i /u01
done

This technique would be useful if you were copying from the ASM to the filesystem locally.

Just as a refresher, the way this script works is:

  • asmcmd ls +DG_AL/EMREP/ARCHIVELOG/2012_12_04: list files inside that ASM directory. The list contains filenames only, not the paths.
  • for i in $(command) ; do ... ; done: iterate over the output of command, using $i as the loop variable. $i will contain the name of one file (without path) inside the loop
  • asmcmd cp [asm_path]/$i [external_path]: copies one file from ASM to an external path.

You could do external to ASM the same way (do an ordinary ls or find for the loop command, and exchange the paths in the copy), or even ASM to ASM (both paths can be ASM paths for asmcmd cp).

Tags:

Oracle