Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script to back up PST files from all computers to Server 2

Status
Not open for further replies.

bence8810

IS-IT--Management
Jul 20, 2005
241
AE
Dear Script Gurus,

Please note that I am a complete beginner with Scripting, I kind of dont even know what scripts are :) Having said that, I am in need to put all PST files from users' computers to a server which will be backed up as one.

I have a "script" (DOS batch file) which copies the PST file to the server upon boot (Using GPO and logon script). The problem is that while the PST file is being copied, the computer still boots up and shows the desktop, so the user can launch Outlook, and the Copy all of a sudden fails.

How would I go about a very simple script that wouldnt allow them to Open Outlook, or just to Note them not to open until it finishes. I basically need to run this script for every user once a week, maybe 7 users a day. We have 35 users.

The exchange server is exhausted with the amount of Email everyone has, so I needed to start archiving to local PST folders, but those are not backed up yet.

Thanks for any pointers, and I am open to new ideas of how to backup as well.

Thanks,

Ben
 
Hi

If you still have some patience for this unskilled Hungarian :) I would like to ask another thing. First of all, this is how my script looks like now. I added a few more directories to look into for PST files.

Code:
Select Case WeekDay(Now())
 'where number after "Case" means Sunday=1 Saturday=7
   Case 4
      Set WshShell = CreateObject("Wscript.Shell")
      On Error Resume Next
      strTemp = WshShell.RegRead("HKLM\Software\Synovate\PSTCopyFlag")
      On Error Goto 0
      If CStr(strTemp) <> CStr(Date) Then
         Set objFSO = CreateObject("Scripting.FileSystemObject")
         strUserName = WshShell.ExpandEnvironmentStrings("%username%")
         objFSO.CopyFile "D:\Mail\*.pst" , "\\bckupsrv1\PST-Backup\" & strUserName & "\"
      On Error Resume Next
	 objFSO.CopyFile "C:\Mail\*.pst" , "\\bckupsrv1\PST-Backup\" & strUserName & "\"
      On Error Resume Next
	 objFSO.CopyFile "C:\Documents and Settings\" & strUserName & "\Local Settings\Application 

Data\Microsoft\Outlook\*.pst" , "\\bckupsrv1\PST-Backup\" & strUserName & "\"
      On Error Resume Next
         Set objFSO = Nothing
         'set the FLAG
         WshShell.RegWrite "HKLM\Software\Synovate\PSTCopyFlag", Date
      End If
      Set WshShell = Nothing
End Select

My concern now is that all users pretty much leave the office between 5-7PM, and that would result 35 users transferring gigs and gigs of PST files to the server within that 2 hour time frame.

Is there a way to add into the script, that the following users A B C and D will do the backup on Monday, E F G and H users will do it on thursday for instance? I guess this could be added somehow to the beginning of the script, and in that case, the logoff script would run every day, just for different users on each day. So for the 5 days we have in a work week, 7-7 people would be doing their backups a given day. And I could ballance the users so that each day I have a few with High amount of Data and some lighter ones.

Thanks

Ben
 
add an addition Select Case statement

strUserName = WshShell.ExpandEnvironmentStrings("%username%")

strDay = 2 'default for unknown configed user

Select Case UCase(strUserName)
Case john, alan, steve
strDay = 3
Case judy, sophie, laura
strDay = 5
End Select

Select Case CStr(WeekDay(Now()))
'where number after "Case" means Sunday=1 Saturday=7
Case CStr(strDay)

'or might just need If statement
If CStr(Weekday(Now())) = CStr(strDay) Then

.....

you might want to go one step more and go for an AD group membership query??? or set an ExtendedAttrib of AD to handle the selcection but i guess it depends on your userbase???? or you could go for certain letters of alphabet having certain days...the possibilities are endless
 
Hi

Sorry, I am not getting this. I dont know where to plug in the lines you mentioned above. If I put it at the beginning, it complains "Object required WshShell"

Thanks

Ben

 
Select Case WeekDay(Now())
'where number after "Case" means Sunday=1 Saturday=7
Case 4
Set WshShell = CreateObject("Wscript.Shell")


take the Set WshShell...' out and put it right at the start, and then move the Set WshShell = Nothing to be out of the Select Case as well.

you could probably do the same for the FSO as well. the reason i put them in the Case statement is that you dont actually need to create them unless you are actually going to run the update, or if the day is correct, they arent expensive objects to create so shouldnt matter if they are declared right at the top of your script...

i wouldnt go for your use of On Error Resume next all the while as well
 
Hi

Well, what can I say. I am going round and round, but I cannot plug your code in the script without it giving me some errors. Could you plug it in the script please? In that case I could "hopefuly" see what I was missing.

For the On Error Resume next, you mean that I plugged it in after each command to copy file from a certain location? I did that becasue on some computers there is no D driver, or there is no C:\mail folder, and the script errored out if that happened, and this fixed it. How can I do that properly?

Thanks, and sorry to give you hard time, I am really not getting this just yet.

Ben
 
I would advise against using the user names. Better to make the users members of a group and check for group membership and based on that group use the above suggestion from MrMovie to set the day. This will eliminate the need to alter the script every time you have a change in users.

You can refer to my FAQ for sample code on binding to the user object and enumerating group memberships. faq329-5798

I hope you find this post helpful.

Regards,

Mark
 
You should first check if a file or folder exists:

Code:
If objFSO.FolderExists("C:\Mail") Then
   'Do something
Else
   'Not there do something else
End If

I hope you find this post helpful.

Regards,

Mark
 
Hi

Mark, thanks for the suggestion. I will try to implement that part as soon as I get the scrip running again. Having Groups does sound like a better option.

This is the script, which I tried to write based on MrMovie's posts. I am sure this is completely ridiculous. It doesnt error out, but doesnt work either. Please indicate where I have the problem.

Thanks

Ben

Code:
Set WshShell = CreateObject("Wscript.Shell")
      'On Error Resume Next
strUserName = WshShell.ExpandEnvironmentStrings("%username%")

strDay = 2 'default for unknown configed user

Select Case UCase(strUserName)
   Case bfrank, alan, steve
      strDay = 4
   Case judy, sophie, laura
      strDay = 5
End Select

Select Case CStr(WeekDay(Now()))
 'where number after "Case" means Sunday=1 Saturday=7
   Case CStr(strDay)


      strTemp = WshShell.RegRead("HKLM\Software\Synovate\PSTCopyFlag")
      On Error Goto 0
      If CStr(strTemp) <> CStr(Date) Then
         Set objFSO = CreateObject("Scripting.FileSystemObject")
         strUserName = WshShell.ExpandEnvironmentStrings("%username%")
         objFSO.CopyFile "D:\Mail\*.pst" , "\\bckupsrv1\PST-Backup\" & strUserName & "\"
      On Error Resume Next
	 objFSO.CopyFile "C:\Mail\*.pst" , "\\bckupsrv1\PST-Backup\" & strUserName & "\"
      On Error Resume Next
	 objFSO.CopyFile "C:\Documents and Settings\" & strUserName & "\Local 

Settings\Application Data\Microsoft\Outlook\*.pst" , "\\bckupsrv1\PST-Backup\" & 

strUserName & "\"
      On Error Resume Next
         Set objFSO = Nothing
         'set the FLAG
         WshShell.RegWrite "HKLM\Software\Synovate\PSTCopyFlag", Date
      End If
      
End Select
Set WshShell = Nothing
 
Case values need to be in quotes. Also I think you need to use an OR if having multiple values though I am not positive on that.

I hope you find this post helpful.

Regards,

Mark
 
'strip out the logic then build in the actual copy tasks

Set WshShell = CreateObject("Wscript.Shell")
strUserName = WshShell.ExpandEnvironmentStrings("%username%")

strDay = 2 'default for unknown configed user

Select Case UCase(strUserName)
Case bfrank, alan, steve
strDay = 4
Case judy, sophie, laura
strDay = 5
End Select

If CStr(strDay) = CStr(Weekday(Now()) Then
Msgbox "i should call a sub routine to handle my copy jobs"
End If
 
This part.
[tt]
Select Case CStr(WeekDay(Now()))
'where number after "Case" means Sunday=1 Saturday=7
Case CStr(strDay)


strTemp = WshShell.RegRead("HKLM\Software\Synovate\PSTCopyFlag")
[red]'[/red]On Error Goto 0
[red]'[/red]If CStr(strTemp) <> CStr(Date) Then
[blue]Case Else[/blue]
Set objFSO = CreateObject("Scripting.FileSystemObject")
strUserName = WshShell.ExpandEnvironmentStrings("%username%")
objFSO.CopyFile "D:\Mail\*.pst" , "\\bckupsrv1\PST-Backup\" & strUserName & "\"
[red]'[/red]On Error Resume Next
objFSO.CopyFile "C:\Mail\*.pst" , "\\bckupsrv1\PST-Backup\" & strUserName & "\"
[red]'[/red]On Error Resume Next
objFSO.CopyFile "C:\Documents and Settings\" & strUserName & "\Local Settings\Application Data\Microsoft\Outlook\*.pst" , "\\bckupsrv1\PST-Backup\" &
strUserName & "\"
[red]'[/red]On Error Resume Next
Set objFSO = Nothing
'set the FLAG
WshShell.RegWrite "HKLM\Software\Synovate\PSTCopyFlag", Date
[red]'[/red]End If

End Select
[/tt]
 
yeap, sorry quotes indeed, option explicit at the top of your script would have shown up my mistake
 
Hi

Thanks for all the posts.

So I tried to combile the script. I incorporated the quotes (hope at the right places), and I tried to complete the script from the

Code:
If CStr(strDay) = CStr(Weekday(Now()) Then

part on....

However, it fails at exactly that part. It says,

Line 13
Char 39
Error Expected ')'

This is how the script looks. Please check how I wrote the NEXT command between the IF commands. I am not sure that is correct.

If you see the posts I started this whole thread above, you will know how much I am unskilled with scripts. I hope I am not giving anyone a headache.

Thanks

Ben

Script as follows

Code:
Set WshShell = CreateObject("Wscript.Shell")
strUserName = WshShell.ExpandEnvironmentStrings("%username%")

strDay = 2 'default for unknown configured user

Select Case UCase(strUserName)
   Case "bfrank", "alan", "steve"
      strDay = 4
   Case "judy", "sophie", "laura"
      strDay = 5
End Select

If CStr(strDay) = CStr(Weekday(Now()) Then
   Set WshShell = CreateObject("Wscript.Shell")
      On Error Resume Next
      strTemp = WshShell.RegRead("HKLM\Software\Synovate\PSTCopyFlag")
      On Error Goto 0
End If
Next
If CStr(strTemp) <> CStr(Date) Then
         Set objFSO = CreateObject("Scripting.FileSystemObject")
         strUserName = WshShell.ExpandEnvironmentStrings("%username%")
         objFSO.CopyFile "D:\Mail\*.pst" , "\\bckupsrv1\PST-Backup\" & strUserName & "\"
      On Error Resume Next
	 objFSO.CopyFile "C:\Mail\*.pst" , "\\bckupsrv1\PST-Backup\" & strUserName & "\"
      On Error Resume Next
	 objFSO.CopyFile "C:\Documents and Settings\" & strUserName & "\Local Settings\Application Data\Microsoft\Outlook\*.pst" , "\\bckupsrv1\PST-Backup\" & strUserName & "\"
      On Error Resume Next
         Set objFSO = Nothing
         'set the FLAG
         WshShell.RegWrite "HKLM\Software\Synovate\PSTCopyFlag", Date
      End If
 
First, replace UCase with LCase
Then: CStr(Weekday(Now())[!])[/!]

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi

Thanks. That issue is solved. It gets passed that.

Of course the part I edited is bad, so it errors now for line 19 char 1

Unexpected NEXT.

How can I connect the two IF commands?

Thanks

Ben
 
delete the Next, sorry i dont know where i got that from :), im off home, swimming pool, sauna etc, sisters birthday today, happy birthday Kath
 
Thanks, but before you start feeling guilty, the NEXT came from my wicked mind, and it wasnt you suggesting it :)

I hope you have fun at the party, happy birthday to your sister, Kath.

Back on the topic, I got the NEXT out, and it sort-of works. It runs the script once, and then it wont run it, just like it was intended. That is when I put number 4 (wednesday) by the username of bfrank, which is me. When I change the number to 5 lets say, and run the script, it will still run it, even thought it is wednesday, and not thursday.

I am sure I got something wrong at the script. Could you please check it if all looks ok? And that I put the quotes to the right place, around the usernames?

Thanks

Ben

Code:
Set WshShell = CreateObject("Wscript.Shell")
strUserName = WshShell.ExpandEnvironmentStrings("%username%")

strDay = 2 'default for unknown configured user

Select Case LCase(strUserName)
   Case "bfrank", "alan", "steve"
      strDay = 4
   Case "judy", "sophie", "laura"
      strDay = 5
End Select

If CStr(strDay) = CStr(Weekday(Now())) Then
   Set WshShell = CreateObject("Wscript.Shell")
      On Error Resume Next
      strTemp = WshShell.RegRead("HKLM\Software\Synovate\PSTCopyFlag")
      On Error Goto 0
End If
Next
If CStr(strTemp) <> CStr(Date) Then
         Set objFSO = CreateObject("Scripting.FileSystemObject")
         strUserName = WshShell.ExpandEnvironmentStrings("%username%")
         objFSO.CopyFile "D:\Mail\*.pst" , "\\bckupsrv1\PST-Backup\" & strUserName & "\"
      On Error Resume Next
     objFSO.CopyFile "C:\Mail\*.pst" , "\\bckupsrv1\PST-Backup\" & strUserName & "\"
      On Error Resume Next
     objFSO.CopyFile "C:\Documents and Settings\" & strUserName & "\Local Settings\Application Data\Microsoft\Outlook\*.pst" , "\\bckupsrv1\PST-Backup\" & strUserName & "\"
      On Error Resume Next
         Set objFSO = Nothing
         'set the FLAG
         WshShell.RegWrite "HKLM\Software\Synovate\PSTCopyFlag", Date
      End If
 
Well that, just the NEXT is taken out. Sorry I left it in when posted the earlier comment.

Ben
 
its your If End If nesting, or lack of it :)

If CStr(strDay) = CStr(Weekday(Now())) Then
Set WshShell = CreateObject("Wscript.Shell")
On Error Resume Next
strTemp = WshShell.RegRead("HKLM\Software\Synovate\PSTCopyFlag")
On Error Goto 0
If CStr(strTemp) <> CStr(Date) Then
Set objFSO = CreateObject("Scripting.FileSystemObject")
strUserName = WshShell.ExpandEnvironmentStrings("%username%")
objFSO.CopyFile "D:\Mail\*.pst" , "\\bckupsrv1\PST-Backup\" & strUserName & "\"
On Error Resume Next
objFSO.CopyFile "C:\Mail\*.pst" , "\\bckupsrv1\PST-Backup\" & strUserName & "\"
On Error Resume Next
objFSO.CopyFile "C:\Documents and Settings\" & strUserName & "\Local Settings\Application Data\Microsoft\Outlook\*.pst" , "\\bckupsrv1\PST-Backup\" & strUserName & "\"
On Error Resume Next
Set objFSO = Nothing
'set the FLAG
WshShell.RegWrite "HKLM\Software\Synovate\PSTCopyFlag", Date
End If
End If


ps. had good time at sisters, thanks
 
i would chuck some Wscript.Echo "here n" in your script so you can check how your logic is working out. it makes life easier with debugging, plus your use of On Error Resume Next will hide what is really happening, which makes the Wscript.Echos even more important, comment them out when you want to put the script live.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top