471,853 Members | 1,588 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,853 software developers and data experts.

Question: restore from backup in relative path...

BD
Hi there.

Using 8.2 on Windows.

I have a situation where I have a db backup, which I want to deploy to
a group of developer workstations.

The target directory for the database files will be consistent, but
the location that the backup file is on may vary.
I have gone through the entire backup and restore process, and it
works fine.

Where I'm running into an issue is using a relative path for the
location of the backup file.

I would like to use the following:

"db2 restore db NEWDB from %bkupdir% to c: into %dbname% redirect"

....I would then set tablespace containers, CONTINUE the restore, and
then rollforward.

Both 'bkupdir' and 'dbname' are variables which are set in a config
batch file.

I have ECHO set on, and I can see the correct path being displayed
when the restore command echos back after getting the variable names.
But I continually get the 'path for file or device... is not valid'
error message.

Are relative paths workable in this kind of situation?

....the reason I want to use relative paths is that I want to send out
the backup file in the version control software we are using. The path
that the various workstations may have checked out their source into
may vary.

There are other options, I guess - but I'd like to be able to make the
relative path work.

Thanks!!

BD.
Jun 27 '08 #1
2 4135
BD wrote:
Hi there.

Using 8.2 on Windows.

I have a situation where I have a db backup, which I want to deploy to
a group of developer workstations.

The target directory for the database files will be consistent, but
the location that the backup file is on may vary.
I have gone through the entire backup and restore process, and it
works fine.

Where I'm running into an issue is using a relative path for the
location of the backup file.

I would like to use the following:

"db2 restore db NEWDB from %bkupdir% to c: into %dbname% redirect"

...I would then set tablespace containers, CONTINUE the restore, and
then rollforward.

Both 'bkupdir' and 'dbname' are variables which are set in a config
batch file.

I have ECHO set on, and I can see the correct path being displayed
when the restore command echos back after getting the variable names.
But I continually get the 'path for file or device... is not valid'
error message.

Are relative paths workable in this kind of situation?

...the reason I want to use relative paths is that I want to send out
the backup file in the version control software we are using. The path
that the various workstations may have checked out their source into
may vary.

There are other options, I guess - but I'd like to be able to make the
relative path work.

Thanks!!

BD.
From the RESTORE DB reference:

FROM directory/device

The >>>fully qualified<<< path name of the directory or device...

Sorry, but both BACKUP DB and RESTORE DB require absolute paths.
Assuming you're using batch files on Windows 2000 or above (or possibly
XP - I'm a bit fuzzy on the exact versions when some of this
functionality was introduced...) there's a couple of ways around this:

1) Use the %CD% environment variable which expands to the current
working directory. For example:

db2 RESTORE DB NEWDB FROM "%CD%\%BKUPDIR%" TO C: INTO %DBNAME% REDIRECT

2) Alternatively, if BKUPDIR is passed to the batch file on the command
line, you can use the ~f expansion on it. For example, if BKUPDIR is
%1, and DBNAME is %2:

db2 RESTORE DB NEWDB FROM "%~f1" TO C: INTO %2 REDIRECT

CMD extensions need to be enabled for these expansions to work, but
this is the default on WinNT and above (to absolutely guarantee they're
enabled you can use SETLOCAL ENABLEEXTENSIONS at the top of the batch
file). As in the above examples, don't forget to quote these paths in
case the expansions introduce paths containing spaces.
Cheers,

Dave.
Jun 27 '08 #2
BD
1) Use the %CD% environment variable which expands to the current
working directory. For example:

db2 RESTORE DB NEWDB FROM "%CD%\%BKUPDIR%" TO C: INTO %DBNAME% REDIRECT
This %CD% environment variable appears to do the trick. Thanks kindly!
Jun 27 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by emmexx | last post: by
3 posts views Thread by butatista | last post: by
3 posts views Thread by Jon Jacobs | last post: by
3 posts views Thread by Frank Stefani | last post: by
reply views Thread by newman | last post: by
reply views Thread by mitrofun63 | last post: by
NeoPa
reply views Thread by NeoPa | last post: by
reply views Thread by YellowAndGreen | last post: by
aboka
reply views Thread by aboka | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.