Link to home
Start Free TrialLog in
Avatar of Ezra Shiram
Ezra ShiramFlag for United States of America

asked on

Script to Restore Files Based File Name

Hello,
We accidentally deleted files. We have a backup but it is not reliable and did not backup these files properly. A lot of them are missing. We do happened to have these missing files archived in another location. I would like to see if we can automate a restore from this archived location.

The main production network share has a structure of "C:\FTP Folder\PO#\Date\PO#_Item#\League_Item#_Team_Player_Color\". To find this path in the "archived" location we need to use the last folder in the main production path (ex: League_Item#_Team_Player_Color). So, after each underscore is another folder in the archived location. So we would go to the archived location and it would be "F:\League\Item#\Team\Player\Color". Is there a script that we can make to pull the files from the archived location to the main production share?

Not sure if this is possible via a script, but that is what I am hoping for.

Thank You!!
Avatar of Krompton
Krompton
Flag of United States of America image

You asked for a way to automate this; is this because of the number of files or are you expecting to have to repeat this procedure?

For a one-time restore, XCopy or RoboCopy may suit your needs.

Krompton
Avatar of Steven Carnahan
Try this batch file:

echo off
set str="Folder\PO#\Date\PO#_Item#\League_Item#_Team_Player_Color\"
set str2=%str:Folder\PO#\Date\PO#_=F:\%
set str3=%str2:_=\%
echo %str3%
pause

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Steven Carnahan
Steven Carnahan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bill Prew
Bill Prew

So, you want to look at each of these folders in the main server location, and then do what?  Copy all files from the backup location?  What if they already exist in the main server, overwrite, or skip?

~bp
REVISED:

If you need to process multiple folders in source folder c:\ftp, try this.

Note:
- I've placed an ECHO so you can see what the command does. It does not do the actual copy. To run it for real, remove the ECHO
- I used XCOPY command. Of course, use whatever command you like.
echo off
setlocal enabledelayedexpansion

set arch=C:\FTP Folder\PO#\Date\PO#_Item#
set patt=*

set targetdir=c:\targetdir\

pushd %arch%
for /d %%a in (%patt%) do (
  set str=%%a
  set str2=!str:_=\!
  ECHO xcopy /y /i /e "f:\!str2!" "%targetdir%"
)
popd
goto :eof

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial