FileCopy alternative

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Good morning,

Once again I need your help (another thing I don't know this is becoming a little too frequent). Anyways...


I wrote an autoexecutable program to automatically backup my database's back-end once a day using the FileCopy function. The problem is that is only will work if nobody has the back-end open (hence, nobody is using the database). Is there a way to copy it even if someone is currently using the database?

Thank you,

Daniel
 
Yes, a batch file will copy the file as long as the file is open in shared
mode. Use Shell to run the batch file.

Example:
Shell "command.com /c <path>\copydb.bat", vbMinimizedNoFocus

Example batch file to keep 9 copies:
@echo off
if exist \\computer\HiddenShare$\*.* goto Begin
echo Destination not found
if not exist \\computer\HiddenShare$\*.* goto end

rem Replace the file that doesn't exist
rem If more that one doesn't exist the first
rem one that doesn't exist is the one to goto

:Begin
if not exist \\computer\HiddenShare$\*.1 goto one
if not exist \\computer\HiddenShare$\*.2 goto two
if not exist \\computer\HiddenShare$\*.3 goto three
if not exist \\computer\HiddenShare$\*.4 goto four
if not exist \\computer\HiddenShare$\*.5 goto five
if not exist \\computer\HiddenShare$\*.6 goto six
if not exist \\computer\HiddenShare$\*.7 goto seven
if not exist \\computer\HiddenShare$\*.8 goto eight
if not exist \\computer\HiddenShare$\*.9 goto nine
if not exist \\computer\HiddenShare$\*.10 goto ten

goto end

:one
copy \\server\database\MyDatabase*.md? \\computer\HiddenShare$\*.md?.1
if exist \\computer\HiddenShare$\*.2 del \\computer\HiddenShare$\*.2
goto end

:two
copy \\server\database\MyDatabase*.md? \\computer\HiddenShare$\*.md?.2
if exist \\computer\HiddenShare$\*.3 del \\computer\HiddenShare$\*.3
goto end

:three
copy \\server\database\MyDatabase*.md? \\computer\HiddenShare$\*.md?.3
if exist \\computer\HiddenShare$\*.4 del \\computer\HiddenShare$\*.4
goto end

:four
copy \\server\database\MyDatabase*.md? \\computer\HiddenShare$\*.md?.4
if exist \\computer\HiddenShare$\*.5 del \\computer\HiddenShare$\*.5
goto end

:five
copy \\server\database\MyDatabase*.md? \\computer\HiddenShare$\*.md?.5
if exist \\computer\HiddenShare$\*.6 del \\computer\HiddenShare$\*.6
goto end

:six
copy \\server\database\MyDatabase*.md? \\computer\HiddenShare$\*.md?.6
if exist \\computer\HiddenShare$\*.7 del \\computer\HiddenShare$\*.7
goto end

:seven
copy \\server\database\MyDatabase*.md? \\computer\HiddenShare$\*.md?.7
if exist \\computer\HiddenShare$\*.8 del \\computer\HiddenShare$\*.8
goto end

:eight
copy \\server\database\MyDatabase*.md? \\computer\HiddenShare$\*.md?.8
if exist \\computer\HiddenShare$\*.9 del \\computer\HiddenShare$\*.9
goto end

:nine
copy \\server\database\MyDatabase*.md? \\computer\HiddenShare$\*.md?.9
if exist \\computer\HiddenShare$\*.10 del \\computer\HiddenShare$\*.10
goto end

:ten
copy \\server\database\MyDatabase*.md? \\computer\HiddenShare$\*.md?.10
if exist \\computer\HiddenShare$\*.1 del \\computer\HiddenShare$\*.1

:end

--
Wayne Morgan
MS Access MVP


Daniel said:
Good morning,

Once again I need your help (another thing I don't know this is becoming a
little too frequent). Anyways...
I wrote an autoexecutable program to automatically backup my database's
back-end once a day using the FileCopy function. The problem is that is
only will work if nobody has the back-end open (hence, nobody is using the
database). Is there a way to copy it even if someone is currently using the
database?
 
Dan,
I have done it by writing a DOS batch file and call this
from within Access. This works for me as it doesn't seem
to care whether the file is open or not.

Trevor T
-----Original Message-----
Good morning,

Once again I need your help (another thing I don't know
this is becoming a little too frequent). Anyways...
I wrote an autoexecutable program to automatically backup
my database's back-end once a day using the FileCopy
function. The problem is that is only will work if nobody
has the back-end open (hence, nobody is using the
database). Is there a way to copy it even if someone is
currently using the database?
 
Daniel said:
I wrote an autoexecutable program to automatically backup my database's back-end once a day using the FileCopy function. The problem is that is only will work if nobody has the back-end open (hence, nobody is using the database). Is there a way to copy it even if someone is currently using the database?


Others have shown that the Copy command can copy an open
file, but that only points out that it unaware of file
usage. The reason that FileCopy refuses to do this is
because copying an open file can produce an unusable result.
The file can easily be in an unknown state as data tables
are in the process of being updated and, if copied, the copy
will also be in an unknown state, possibly corrupted as an
mdb file.

Backing up a database is a serious operation and to be
reliable must be treated very carefully. If you can be sure
that all users of the backend mdb are quiescent (using an
LDB utility) then, FileCopy can be used, but if the file is
in fact in use, then don't try to copy it.
 
Wayne,

Is there a simpler way to use the shell to copy a file. I don't need the
serial backups...I just want the shell to copy a file from D:\ to C:\. I
have tried various ways, but I cannot seem to get it to work. Is there a
simple statement using the shell?
 
Okay, I read the entire thread.

While Wayne's right that a batch file will copy the file as long as the file
is open in shared mode, that doesn't make it a good idea. If the database is
in use, it's entirely possible that what's copied may be inconsistent. In
other words, while you can do it, it may be pointless.
 
Back
Top