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 SkipVought 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
0
0
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
 
Case 2
Set WshShell = CreateObject("Wscript.Shell")
On Error Resume Next
strTemp = WshShell.RegRead("HKLM\Software\MyFirm\PSTCopyFlag")
On Error Goto 0
If strTemp <> Date Then
Set objFSO = CreateObject("Scripting.FileSystemObject")
strUserName = WshShell.ExpandEnvironmentStrings("%username%")
objFSO.CopyFile "D:\Personal\Mail\*.pst" , "\\bckupsrv1\PST-Backup\" & strUserName & "\"
Set objFSO = Nothing
'set the FLAG
WshShell.RegWrite "HKLM\Software\MyFirm\PSTCopyFlag", Date
End If
Set WshShell = Nothing
 
Hi

The script doesnt exactly work. I changed only a few things, like the MyFirm to My company's name, etc. Here is what I have exactly now:

Code:
Select Case WeekDay(Now())

   Case 3
      Set WshShell = CreateObject("Wscript.Shell")
      On Error Resume Next
      strTemp = WshShell.RegRead("HKLM\Software\Synovate\PSTCopyFlag")
      On Error Goto 0
      If strTemp <> Date Then
         Set objFSO = CreateObject("Scripting.FileSystemObject")
         strUserName = WshShell.ExpandEnvironmentStrings("%username%")
         objFSO.CopyFile "D:\Mail\*.pst" , "\\bckupsrv1\PST-Backup\" & strUserName & "\"
         Set objFSO = Nothing
         'set the FLAG
         WshShell.RegWrite "HKLM\Software\Synovate\PSTCopyFlag", Date
      End If
      Set WshShell = Nothing

The error I get is this:

Script: blab-bla-etc-etc.vbs

Line: 18
Char: 29
Error: Ex[ected 'END'
Code: 800A03F6
Source: Microsoft VBScript compilation error

Thanks for any help,

Ben
 
Sorry, to extend my previous post, there are two lines above the script, those are commented out, so the line 18 the error referes to, is this
Code:
Set WshShell = Nothing

Ben
 
do you have an 'End Select' statement after the Set WshShell = Nothing?
 
I am an idiot, what can I say. thanks.

That is fixed now, but the script doesnt do the check right. No matter how many times I run it, it will still copy all files, and take a long time. The Registry key is created though, as per below:

HKEY_LOCAL_MACHINE\SOFTWARE\Synovate\PSTCopyFlag

and the value is 4/11/2006

This is the full script as it looks now:

Code:
Select Case WeekDay(Now())

   Case 3
      Set WshShell = CreateObject("Wscript.Shell")
      On Error Resume Next
      strTemp = WshShell.RegRead("HKLM\Software\Synovate\PSTCopyFlag")
      On Error Goto 0
      If strTemp <> Date Then
         Set objFSO = CreateObject("Scripting.FileSystemObject")
         strUserName = WshShell.ExpandEnvironmentStrings("%username%")
         objFSO.CopyFile "D:\Mail\*.pst" , "\\bckupsrv1\PST-Backup\" & strUserName & "\"
         Set objFSO = Nothing
         'set the FLAG
         WshShell.RegWrite "HKLM\Software\Synovate\PSTCopyFlag", Date
      End If
      Set WshShell = Nothing
End Select

Thanks for any help,

Ben
 
Have you looked at using the utility?

For the script, I would do something like this:

1. Check for the day of the week (in number format)
2. Read the registry flag to see if it matches the day of the week.
3. If match do nothing, exit script
4. No match or key not present then initiate a copy, when completed set the flag value to today

This should work for you except in cases where a user does nto log in for a week.

For your 10GB PST, beat the user over the head. Have them archive their years of data into smaller PST files based on year or if they are THAT busy that it is all current seperate by month. A PST that large is not only a burden on the network but also just waiting to become corrupt. PST files over 2GB are a dangerous gamble with data.

I hope you find this post helpful.

Regards,

Mark
 
Hi Mark,

Yes I looked at the Utility, and I found that it cannot be controlled remotely, and I rather have a script transfer the files than having to go to each station, set it up, and enforce the use of it, even though it reminds the users. I have heard bad experiences where users never mind things, and IT is responsible of course:(

Besides, this script can be useful to transfer other things than PST files, etc. I may have the need for it.

The PST files arent that large, just a few users have several years of Emails, and they need to look into it rather often. I may enforce some things, like we dont back up the old files anymore, but store them on a tape, and they can keep a copy on their machines, without it being backed, etc.

For the script, I am really crippled as far as knowledge goes. I dont know how to implement what you just wrote. I am trying to learn slowly from these posts.

Thanks

Ben
 
Code:
On Error Resume Next
Dim WshShell, objFSO, dayOfWeek, lastBackup

Set WshShell = CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

'Get the current day of the week.  Sunday =1 Saturday =7
dayOfWeek = Weekday(Now)

'Check last time we backed up
lastBackup = WshShell.RegRead("HKLM\Software\Synovate\PSTCopyFlag")

 If Not Err Then
    If dayOfWeek = lastBackup Then
	' Already backed up today, quit script
       WScript.Quit
    Else
    ' Copy the file
       objFSO.CopyFile "D:\Mail\*.pst" , "\\bckupsrv1\PST-Backup\" & strUserName & "\"
       WshShell.RegWrite "HKLM\Software\Synovate\PSTCopyFlag", dayOfWeek, "REG_SZ"
    End If
 Else
 	' Need this section for first time if the reg key did not exist or there was an error checking it.
 	' Copy the file
	objFSO.CopyFile "D:\Mail\*.pst" , "\\bckupsrv1\PST-Backup\" & strUserName & "\"
    WshShell.RegWrite "HKLM\Software\Synovate\PSTCopyFlag", dayOfWeek, "REG_SZ"
 End If

I hope you find this post helpful.

Regards,

Mark
 
Dear Mark,

Thanks so much for writing this. I am a bit lost, as you seem to use a different set of Codes. Something I dont get, is how do I tell it to run the script on Tuesday only. The script that Mrmovie wrote, had the following:

Select Case WeekDay(Now())

Case 3

Your code seem to have it differently.

Also, at the end, I dont see the "End Select". I need to plug it in myself, right? I really dont want to seem too dumb, but I am :)

Thanks

Ben
 
Sorry I did not realize that was a requirement which will require the follwoing changes to the code I posted.

Code:
'==========================================================================
'
' NAME: 
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.TheSpidersParlor.com[/URL]
' COPYWRITE (c) 2005 All Rights Reserved
' DATE  : 4/11/2006
'
' COMMENT: 
'
'==========================================================================
On Error Resume Next
Dim WshNetwork, WshShell, objFSO, dayOfWeek, lastBackup

Set WshNetwork = CreateObject("Wscript.Network")
Set WshShell = CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

strUserName = WshNetwork.Username

'Get the current day of the week.  Sunday =1 Saturday =7
dayOfWeek = Weekday(Now)

If dayOfWeek<>3 Then WScript.Quit

'Check last time we backed up
lastBackup = WshShell.RegRead("HKLM\Software\Synovate\PSTCopyFlag")

 If Not Err Then
    If lastBackup = date Then
	' Already backed up today, quit script
       WScript.Quit
    Else
    ' Copy the file
       objFSO.CopyFile "D:\Mail\*.pst" , "\\bckupsrv1\PST-Backup\" & strUserName & "\"
       WshShell.RegWrite "HKLM\Software\Synovate\PSTCopyFlag", date, "REG_SZ"
    End If
 Else
 	' Need this section for first time if the reg key did not exist or there was an error checking it.
 	' Copy the file
	objFSO.CopyFile "D:\Mail\*.pst" , "\\bckupsrv1\PST-Backup\" & strUserName & "\"
    WshShell.RegWrite "HKLM\Software\Synovate\PSTCopyFlag", date, "REG_SZ"
 End If

I hope you find this post helpful.

Regards,

Mark
 
sorry Ben, really bad form on my part

If strTemp <> Date Then

when comparing stuff one should always explicitly convert...

If CStr(strTemp) <> CStr(Date) Then

that will get things cooking, sorry, i dont tend to test stuff that i post...or that i write and unleash @ work :)
 
I normally try to test but must admit I am guilty here too. I did the same thing MrMovie.

I hope you find this post helpful.

Regards,

Mark
 
howdi Mark,
do you work in the States? whats the IT market like over at the moment???
 
Depends on the area of the country and skill set of course, but I think the market is good. I know a lot of companies with openings, problem is finding people to fit the requirements. The New York area is especially good as is the Altanta Georia area.

I am in the Phoenix Arizona area and it is slower here but there are jobs to be had depending on your pay requirements. Anything between $45-75K is easy to land, once you get above the $75K area it is tougher.

I hope you find this post helpful.

Regards,

Mark
 
Hi

Thanks to both of you for posting . I will test things tomorrow, I am not in anymore. I am in Hungary, and we are rather in the evening.

I appreciate both of your helps,

I will post results,

Regards,

Ben
 
cheers Mark,
i have friends in NY and Atlanta, fancy a bit of a break from the UK so will have to look into it.

have a nice evening people
 
I love that this is an international forum. Nice to know you are helping people in far off countries. :)

I hope you find this post helpful.

Regards,

Mark
 
Hi

Yes, indeed it is an international forum. English is the most widely spoken language on Earth at developed countries, so you have better chance looking at English forums, than one on your mother tounge.

Well, if I may add for the fun/laugh of it, IT pro jobs are going between 10K - 30K tops in Hungary, but I guess that wont attract any of you here :) A freshman out of college can hardly imagine more than 10K for the first few years. If you speak decent english, have some experience, you might look at 15K for starter. :D

Cheers, and thanks for the outstanding support. I have gotten much support from here, thus I come back often...

Maybe one day I will have the knowledge to help others as well.

Ben
 
I guess the pay all depends on what you are used to right? Cost of living etc. It is kind of sad to think that I paid more for my Harley Davidson than some people make in a year.

I do however remember when I got out of the military I had a rule to earn my age X $1000. I don't knwo when it happended but that soon changed to be double my age X $100 and went up from there. The markey has really changed over the years and salaries have gone up for people with the number of years of experience as I have, but at the same time I have found that there is a salary cap as well that the market won't exceed as base salary.

I hope you find this post helpful.

Regards,

Mark
 
Hi There,

I am back in, and tested both scripts. Mark, your script will run fine, but will not stop even when the backup has been completed at the given day. If I run it again, it will run. The Registry key is created correctly, with the date in it.

MrMovie, your script did the trick, it will run once, and never again on that given day. I have done extensive testing, and things look great.

For the Economic part of the discussion, you are right Mark. Cost of living, and expectations are different than in Western Europe, or in the US, Japan, etc. We can make a decent living off the money we earn, but of course most people dont have Harley Davidsons, and cars for each member of the family, like it is in the US. I used to live in LA for 5 years, so I kind of know what life is like over there. All I can say, there are good things everywhere, and the more place you get to, the more you learn.

Cheers,

Ben
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top