View Full Version : Make a Backup Copy of Directory (W2K)
khorton44
06-12-2002, 05:33 PM
How would you go about writing a scipt to copy a directory from one server to another. I'm trying to make an extra backup copy in case of tape backup failure. I've tried the following but it only seems to work once afterwards it won't write over the destination copy again.
Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.CopyFolder "H:\Goldmine5", "C:\Goldmine_Backup\Goldmine5"
Thanks in advance for any help you provide.
FSO.CopyFolder will not overwrite existing folders as you have already discovered. To work around this you can do one of a few things;
1- Have the script delete the old folder before copying the new one.
The problem with this method is what if the script fails just after deleting the folder and before copying the new one? You’ll end up without a backup copy of the folder.
Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
fso.DeleteFolder ("C:\Goldmine_Backup\Goldmine5")
FSO.CopyFolder "H:\Goldmine5", "C:\Goldmine_Backup\Goldmine5"
Set FSO = Nothing
2- Append the date to the end of the folder name. That way, you have a unique name for each folder. Of course you’ll have to format the date to create a valid folder name.
This will give you the power to restore a copy earlier than yesterday’s copy if you wanted to.
The problem with this is you’ll end up with a large number of copies and use more hard disk space.
Here is the code for this method;
CurrentDate = Date
MyDay = Day(CurrentDate)
MyMonth = Month(CurrentDate)
MyYear = Year(CurrentDate)
MyDate = MyDay & "-" & MyMonth & "-" & MyYear
Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.CopyFolder "H:\Goldmine5", "C:\Goldmine_Backup\Goldmine5 " & MyDate
Set FSO = Nothing
3- This is my favourite, use xcopy. You’ll find it in the system32 folder. open a command prompt & type, “xcopy /?” For help.
Create a “.bat” file with a line similar to this;
xcopy "H:\Goldmine5" "C:\Goldmine_Backup\Goldmine5" /E /I /H /R /K /O /X /Y > c:\Xcopied.txt
I’ve piped the output of the xcopy command to a text file “c:\xcopied.txt”. This is to test the command, delete this part “> c:\Xcopied.txt” if you don’t need to keep a log file.
Jama
khorton44
06-13-2002, 09:01 PM
Thanks Jama, I see the problem with the first method. I couldn't get Xcopy to work. Might that have anything to do with the drive being copied being a mapped drive? I will use your second suggestion for now and just delete the extra folders from time to time.
How about doing it a mixture of the two ways. Copy to a temp backup folder, verify the size, then delete the true backup and copy again, then delete the temp backup. accounts for errors and keeps the file space down.
Powered by vBulletin™ Version 4.1.0 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.