User Backup Script
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- houstonguy78
- Posts: 4
- Last visit: Thu Nov 15, 2007 3:50 am
User Backup Script
Does anyone know where I can find a backup script that will search a user's c: drive for particular files (*.xls, *.doc etc...), create a backup folder on their home drive H: and copy those files to that folder? Thanks for your help.
- houstonguy78
- Posts: 4
- Last visit: Thu Nov 15, 2007 3:50 am
User Backup Script
Does anyone know where I can find a backup script that will search a user's c: drive for particular files (*.xls, *.doc etc...), create a backup folder on their home drive H: and copy those files to that folder? Thanks for your help.
- houstonguy78
- Posts: 4
- Last visit: Thu Nov 15, 2007 3:50 am
User Backup Script
Yes actually I did do some searching there. Maybe I should clarify my request. I am looking for a script that I can run remotely that will backup the specified user's .pdf, .xls, .mdb, .ppt, .pst, .url and .pdf files from their c: drive and copy them to their H: drive into a folder named backup. Thanks.
- houstonguy78
- Posts: 4
- Last visit: Thu Nov 15, 2007 3:50 am
User Backup Script
Perms are not an issue since I am an admin. The reason that I say the C: drive is because sometimes users save files to the root of c:. Otherwise, I'd say to just search the user's profile. By the way, these are 2000 and XP machines. Each user has their own folder on the share. eg. servernameusersjlsmith The majority of these machines are single user so that won't be an issue. Ideally, I'd want to kick off this script (where they have no idea it's running) for the currently logged on user remotely. We are in the process of replacing old machines and we want to be able to kick off the script, swap out their machine for the new one and move on to the next user. Manually backing up their files really slows us down! Thanks.
- jdelatorre@hfinc.com
- Posts: 54
- Last visit: Wed Jan 30, 2008 1:42 am
User Backup Script
This should get you started. Didnt do any testing as I dont have the environment or time at the moment.
strComputer = InputBox("Enter Computer Name") If IsEmpty(strComputer) Then WScript.Quit End If Set objFso = CreateObject("Scripting.FileSystemObject")crtUser= loggedonUser(strComputer) dstFolder = "h:Backup"&crtUser&""srcFolder = ""&strComputer&"c$"
WorkWithSubFolders srcFolder
Sub WorkWithSubFolders(AFolder) CheckExt AFolder Set MoreFolders = AFolder.Subfolders For Each TempFolder In MoreFolders WorkWithSubFolders (TempFolder) Next End Sub
Sub CheckExt(AFolder) On Error Resume Next Set TheFiles = AFolder.Files For Each Afile In TheFiles select Case ucase((objFSO.GetExtensionName (AFile))) ' Add other ext as needed. Case "PDF" objFso.CopyFile Afile, dstFolder, True Case "XLS" objFso.CopyFile Afile, dstFolder, True Case "PPT" objFso.CopyFile Afile, dstFolder, True End Select NextEnd Sub
Function loggedonUser(strComputer)
Set objWMIService = GetObject("winmgmts:" & strComputer & "rootcimv2") Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48) For Each objItem in colItems User = objItem.UserName Next arrUser=Split(User,"") loggedonUser = arrUser(1)
End Function
strComputer = InputBox("Enter Computer Name") If IsEmpty(strComputer) Then WScript.Quit End If Set objFso = CreateObject("Scripting.FileSystemObject")crtUser= loggedonUser(strComputer) dstFolder = "h:Backup"&crtUser&""srcFolder = ""&strComputer&"c$"
WorkWithSubFolders srcFolder
Sub WorkWithSubFolders(AFolder) CheckExt AFolder Set MoreFolders = AFolder.Subfolders For Each TempFolder In MoreFolders WorkWithSubFolders (TempFolder) Next End Sub
Sub CheckExt(AFolder) On Error Resume Next Set TheFiles = AFolder.Files For Each Afile In TheFiles select Case ucase((objFSO.GetExtensionName (AFile))) ' Add other ext as needed. Case "PDF" objFso.CopyFile Afile, dstFolder, True Case "XLS" objFso.CopyFile Afile, dstFolder, True Case "PPT" objFso.CopyFile Afile, dstFolder, True End Select NextEnd Sub
Function loggedonUser(strComputer)
Set objWMIService = GetObject("winmgmts:" & strComputer & "rootcimv2") Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48) For Each objItem in colItems User = objItem.UserName Next arrUser=Split(User,"") loggedonUser = arrUser(1)
End Function
- jdelatorre@hfinc.com
- Posts: 54
- Last visit: Wed Jan 30, 2008 1:42 am
User Backup Script
doh! forgot about Xcopy.Now that Jim has knocked my brain cobwebs loose. Robocopy is also an option for you too. type robocopy /? at the cmd prompt for avail switches.
- jdelatorre@hfinc.com
- Posts: 54
- Last visit: Wed Jan 30, 2008 1:42 am
User Backup Script
What you can do is use portions of the script above (to get the logged on user, and set the users home network folder to copy to) and feed into the script appropiate Robocopy or Xcopy switches.
Since you are going to run this against multiple machines then I would go with Robocopy as it is a little more flexible and has better logging capabilites.
Since you are going to run this against multiple machines then I would go with Robocopy as it is a little more flexible and has better logging capabilites.