Customizing the Barebones Restore Script
Late last week and earlier this week I posted two different Visual Basic scripts. Being someone who doesn't know much about VB scripting and knew even less when I started on this process I felt it would probably be beneficial for those like me to go over the scripts and give some examples of adding other files that may need to be backed up. So I posted an article on modifying the backup script I posted earlier. If you were using the restore script, found here, you may want to modify that one as well, understanding that process will be the goal of this article.
Restoring Another File
Define your location
Last time I started by backing up a custom settings file for our document management product. We will start by entering the information required to restore that file. If you don't remember, that product's name was Document Locator. In order to keep some level of similarity between the two scripts we can bring the same location string back over from the backup script. Again we will fit it between the same two lines we did previously.
strNK2Folder = "\Application Data\Microsoft\Outlook\" strDocLocator = "\Application Data\ColumbiaSoft\" strDocSettings = "C:\Documents and Settings\"
Again note this is not the full path it is just a subpath beneath the profile. If you are restoring to another location that is not under the profile you may need to define a full path.
Create a Sub Function
We are again performing MOST of the steps required for our CopyNK2 sub function, so we will start by copying that one.
This time the source path remains the same in our new function. If you take a look at the folder we backed our data up to you would see that the NK2 files and the SES files are stored in the same directory together, while the Favorites and My Documents folders exist in that directory as well, but are labeled as they were on the source computer. We could have put them into subfolders, but as we are identifying them by extension so it wasn't necessary this time.
Looking at the NK2 function you may recognize that the sixth and seventh lines of this sub function are creating the Application Data and Microsoft folders respectively. Obviously we will not need to create the Microsoft folder so we can remove that line and the same remains for the Application Data folder as this function has already created it for us.
Leaving the Application Data line won't cause us any problems as we have turned off the error reporting to prevent it from warning us the folder already exists, but by removing it we will need to make sure that this new sub function is invoked after the older one we are basing it from.
The last of our fso.createfolder lines will need to be kept and modified. On this line we will change our strNK2Folder string to reflect the name of our new string, strDocLocator. While we are at it we will need to modify those same strings in the line below that one and change our extension we copy to *.ses from the *.nk2 extension.
When all is said and done our new function will look a lot like this one:
Sub CopySES(strBaseName)
'Backup Document locator repository catalog
strSrcPath = strSource & strComputerName & "\" & strBaseName & "\"
Set fso = CreateObject("Scripting.FileSystemObject")
on error resume next
fso.createfolder(strDestFolder & strDocLocator)
fso.CopyFile strSrcPath & "*.ses" , strDestFolder & strDocLocator
on error goto 0
End Sub
Add New Sub Function to List
Again we will want to be careful it is invoked in the right order so we file this one right behind the older CopyNK2 function above and make sure it follows the same convention.
CopyNK2(subfolder.name) CopySES(subfolder.name)
Restoring Another Folder
Just as with backing up another folder, adding that new folder to be restored was actually very easy to do.
In our backup example we chose to add some of the user's data to our barebones scripts. By backing up the My Documents folder we gained some major comfort for our users, but also decided to commit the extra resources to storing that data. If you go much beyond one or two folders then you will again probably want to reconsider using PC Transplant instead.
Create a Sub Function
The function we are taking as an example for our new function will be the CopyFavorites just as it was with the backup script.
Because there are no additional subfolders to create we can grab the whole function and simply change the "\Favorites" statement to "\My Documents". (Do not forget the backslash "\" your restore will fail without it.) When we are finished the new function will look like this:
Sub CopyMyDocs(strBaseName)
'Restore My Documents Folder
strSrcPath = strSource & strComputerName & "\" & strBaseName & "\My Documents"
Set fso = CreateObject("Scripting.FileSystemObject")
on error resume next
fso.createfolder(strDestfolder & "\My Documents")
fso.CopyFolder strSrcPath, strDestFolder & "\My Documents"
on error goto 0
End Sub
Add New Sub Function to List
Now we have this new sub function to restore our My Documents folder we'll add this one just as we did the last one, below the function it is copied from.
CopyFavorites(subfolder.name) CopyMyDocs(subfolder.name)
Other Information
The same testing recommendations would apply to testing the restore script as the backup script so make sure to check out that article again if you have problems restoring files.
If you look closely at this script in its original form you will notice it prompts you to input the source computer number and will return a message if it is not in the restore folder. In the limited amount of time I have been using these scripts I have not found a way where this will work very well when run from the Deployment Console.
If in your environment the computer names would remain the same you could use DS tokens to replace that information and fill in the computer name automatically. However in its current form I would suggest making this script something manually run by the end user or by a technician before the new or reloaded equipment was delivered.
I again welcome any questions or suggestions that would lead to the improvement of these scripts. I share them with you, because I needed something to fit a specific function and get very specific on the data that was transferred from one machine to another. When I couldn't find something to fit this process I knew that it was possible other people were looking as well. Thank you for your time and good luck in whatever process or project you might be using these scripts.
