2

Say I have a folder with a series of symbolic links:

ussdv103:en195d; default$  pwd
/oradba/app/oracle/admin/database1
ussdv103:en195d; default$  ls -ltr
exp -> /oradba/app/oracle/acfsmounts/global/STREAM2a/database1/exp
dpdump -> /oradba/app/oracle/acfsmounts/global/STREAM2a/database1/dpdump
backup -> /oradba/app/oracle/acfsmounts/global/STREAM2a/database1/backup

Then I issue the following commmands to link it to a different STREAM directory:

unlink $ORACLE_BASE/admin/database1/backup
unlink $ORACLE_BASE/admin/database1/dpdump
unlink $ORACLE_BASE/admin/database1/exp
mkdir -p /oradba/app/oracle/acfsmounts/global/STREAM1a/database1/backup
mkdir -p /oradba/app/oracle/acfsmounts/global/STREAM1a/database1/dpdump
mkdir -p /oradba/app/oracle/acfsmounts/global/STREAM1a/database1/exp
ln -s $ORACLE_BASE/acfsmounts/global/STREAM1a/database1/backup $ORACLE_BASE/admin/database1/backup
ln -s $ORACLE_BASE/acfsmounts/global/STREAM1a/database1/dpdump $ORACLE_BASE/admin/database1/dpdump
ln -s $ORACLE_BASE/acfsmounts/global/STREAM1a/database1/exp    $ORACLE_BASE/admin/database1/exp

Then I would use the following command to copy data from the old STREAM directory to the new STREAM directory:

cp -p -r /oradba/app/oracle/acfsmounts/global/STREAM##/database1/ /oradba/app/oracle/acfsmounts/global/STREAM1a/.

But I have to replace ## so that it reflects the location of the old STREAM directory, so the command will look like this:

cp -p -r /oradba/app/oracle/acfsmounts/global/STREAM2a/database1/ /oradba/app/oracle/acfsmounts/global/STREAM1a/.

How can I capture information about the old STREAM directory before unlinking it so that my copy command automatically replaces ## with the correct location of the old STREAM directory? Is there a Unix/Linux variable I can assign the old symbolic link to and then reference that in the copy command?

1 Answer 1

1

Store your old file destinations in a variable using the command readlink to read link information.

OLDBACKUP=`readlink $ORACLE_BASE/admin/database1/backup`
OLDDUMP=`readlink $ORACLE_BASE/admin/database1/backup`
OLDEXP=`readlink $ORACLE_BASE/admin/database1/exp`
NEWBACKUP="/oradba/app/oracle/acfsmounts/global/STREAM1a/database1/backup"
NEWDUMP="/oradba/app/oracle/acfsmounts/global/STREAM1a/database1/dpdump"
NEWEXP="/oradba/app/oracle/acfsmounts/global/STREAM1a/database1/exp"
unlink $ORACLE_BASE/admin/database1/backup
unlink $ORACLE_BASE/admin/database1/dpdump
unlink $ORACLE_BASE/admin/database1/exp
mkdir -p $NEWBACKUP
mkdir -p $NEWDUMP
mkdir -p $NEWEXP
ln -s $NEWBACKUP $ORACLE_BASE/admin/database1/backup
ln -s $NEWDUMP $ORACLE_BASE/admin/database1/dpdump
ln -s $NEWEXP    $ORACLE_BASE/admin/database1/exp

cp -p -r $OLDBACKUP $NEWBACKUP
cp -p -r $OLDDUMP $NEWDUMP
cp -p -r $OLDEXP $NEWEXP
3
  • Is there anyway to parse out everything after the STREAM directory? $: OLD_STREAM=readlink $ORACLE_BASE/admin/database1/backup $: echo $OLD_STREAM $: /oradba/app/oracle/acfsmounts/global/STREAM1a/database1/backup I would like it to echo: /oradba/app/oracle/acfsmounts/global/STREAM1a/ Commented May 23, 2014 at 15:13
  • I'm trying to automate that... For ease of implementation I think I should get it to echo "/oradba/app/oracle/acfsmounts/global/STREAM1a/database1/" The regular expression .*\/database1\/ will achieve this but I need to figure out how to use substrings in Linux to use that regular expression. Commented May 23, 2014 at 15:40
  • OLD_STREM=$(echo $(dirname $(dirname $OLDBACKUP))) Commented May 23, 2014 at 15:44

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.