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

Yes, I could, but all users are encouraged to turn their computers off, and they have gotten used to it by now. So all computers are turned off at 2AM, so this would not work.

Thanks

Ben
 
Do some research regarding turning the computers off. For one thing none will get updates overnight. Second turning a PC off frequently has been proven to shorten the lifespan of the PC.

It is like a light bulb. have you ever been in a room and had the light bulb just die? Probably not, usually the bulb only dies when you flip the switch. Same deal for your PC. Or to put it another way, you don't turn your server off at night and it keeps on working. Treat your PCs the same way.

I hope you find this post helpful.

Regards,

Mark
 
I am using this script as well. Is there a way to change it to use Volume Shadow Copy? The idea is that the backup can run even if Outlook is open.
 
would it be possible to integrate this script from copywithvss.cmd + to use the vshadow.exe from the sdk for both xp/2003 server ?

setlocal

@REM test if we are called by VSHADOW
if NOT "%CALLBACK_SCRIPT%"=="" goto :IS_CALLBACK

@REM
@REM Get the source and destination path
@REM

set SOURCE_DRIVE_LETTER=%~d1
set SOURCE_RELATIVE_PATH=%~pnx1
set DESTINATION_PATH=%2

@REM
@REM Create the shadow copy - and generate env variables into a temporary script.
@REM
@REM Then, while the shadow is still live
@REM recursively execute the same script.
@REM

@echo ...Determine the scripts to be executed/generated...

set CALLBACK_SCRIPT=%~dpnx0
set TEMP_GENERATED_SCRIPT=GeneratedVarsTempScript.cmd

@echo ...Creating the shadow copy...

%~dp0\vshadow.exe -script=%TEMP_GENERATED_SCRIPT% -exec=%CALLBACK_SCRIPT% %SOURCE_DRIVE_LETTER%

del /f %TEMP_GENERATED_SCRIPT%

@goto :EOF

:IS_CALLBACK
setlocal

@REM
@REM This generated script should set the SHADOW_DEVICE_1 env variable
@REM

@echo ...Obtaining the shadow copy device name...

call %TEMP_GENERATED_SCRIPT%

@REM
@REM This should copy the file to the right location
@REM

@echo ...Copying from the shadow copy to the destination path...

copy "%SHADOW_DEVICE_1%\%SOURCE_RELATIVE_PATH%" %DESTINATION_PATH%
 
Bence,

It's always a good idea to add comments to your script so later on after a few months you can go back and know exactly what each section is doing. Check out Markdmac's login script faq to get examples.
 
Hi

That is a great idea, and I will do it for sure. However, I am still not ready with the script. Ever since I havent posted here I am using the script in its latest form, but it isnt perfect yet.

Since this was brought up again, I will try to complete the script. So the question goes...

Does anyone have an idea how to check if the Folder we are trying to copy the PST file from is empty, or has some PST files? The script fails when there is no PST file in the folder. If the folder doesnt exist, the script continues on, but it cannot do the same for the PST file. This means, either there is a PST file or ther isnt, the script will try to copy it, and if there isnt one, the script will fail, and stop.

Thanks

Ben
 
When you bind to the folder you can enumerate the files in it and do a count of how many files there are. That will tell you if the directory is empty. Likewise you can enumerate files and use an If then to see if the extension is PST and create a file count.

Something like this:
Code:
 Set fso = createobject("Scripting.FileSystemObject")
  
  Set oFolder = fso.GetFolder(Path)
  pstCount = 0
  For Each oFile In oFolder.files
     If (Lcase(Right(oFile.Name,3)) = "pst" Then
           pstCount = pstCount + 1	
     End If
  Next

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
Hi

Do I need another IF THEN to start copying the file? I mean do I need an IF pstCount = 1 THEN copy.

If so, could you walk me through putting it in my script?

Thanks

Ben
 
How is that for a challange? Okay then, when I get in tomorrow, I will test the script and post something.

Thanks for encouraging,

Ben
 
I am using this script. It is supposed to backup each friday and only one time each friday in case the user reboots many times that day. My script always says

"WshShell.Popup "Your emails have already been copied today", 20" even if I have deleted the regkey with the date. Somebody see an obvious error somewhere.?

On Error Resume Next
Dim WshNetwork, WshShell, objFSO, dayOfWeek, lastBackup, strUserName, strUserprofile

Set WshNetwork = CreateObject("Wscript.Network")
Set WshShell = CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strUserName = WshShell.ExpandEnvironmentStrings("%username%")
strUserprofile = WshShell.ExpandEnvironmentStrings("%userprofile%")




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

If dayOfWeek<>6 Then WScript.Quit

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

If Not Err Then
If lastBackup = date(now) Then
' Already backed up today, quit script
WshShell.Popup "Your emails have already been copied today", 20
WScript.Quit
Else
' Copy the file
WshShell.Popup "Your emails are being backed up now (Do not open OUTLOOK for a few minutes). You may safely leave the machine, it will proceed automatically (DO NOT CLOSE ANY OPEN WINDOWS!!)", 20
objFSO.CopyFile strUserprofile & "\Local Settings\Application Data\Microsoft\Outlook\*.pst" , "\\Ade-domain\Mail\" & 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
WshShell.Popup "Your emails are being backed up now (Do not open OUTLOOK for a few minutes). You may safely leave the machine, it will proceed automatically (DO NOT CLOSE ANY OPEN WINDOWS!!)", 20
objFSO.CopyFile strUserprofile & "\Local Settings\Application Data\Microsoft\Outlook\*.pst" , "\\Ade-domain\Mail\" & strUserName & "\"
WshShell.RegWrite "HKLM\Software\Synovate\PSTCopyFlag", date, "REG_SZ"
End If
 
sorry guys, found the error

If lastBackup = date(now)

should have been

If lastBackup = date
 
This is a greate vbscript! Good Job

Thanks in Advance

Sincerely; Oscar
 
Hey Guys

In order to run this script on the server does the user need to be an Administrator to run it. I notice that the file does not get backed up. I also notice that the script does not write to the Registry. WHy?

Thanks in Advance

Sincerely; Oscar
 
from what i remember this script was going to be run as part of a logon script...so for this to work and write to the registry then the user who was logging on would need rights to write to the registry (perhaps you could change the location to be a HKCU location and then you wouldnt have the problem? and perhaps this would be better as more than one user might be on teh same mahcine etc) the user would also need permissions to create files on the server where you want their pst files to be backed up to...so perhaps you can use their homedirectory for this? they should have rights to that or a share/folder on a server which has a url of \\servername\pstfiles\%username%
 
Hi

Right, as MrMovie suggests, I guess you could just pipe the flag to a .txt file instead of the registry entry, and that would be okay. Or you can completely leave that part out, but that case, it will run more than once if the user logs off the same day over and over again. I have a few users over 10GB of PSTs in total, so for them, this would be a nightmare.

And yes, all of our users are Admins of their own PC's, as we have such software which requires that, so I didnt have this barrier before me.

I still didnt come around learning about VB scripting, and therefore I still didnt complete the last step.

Would someone be kind enough to complete this final step? The error is that the script checks all directories I supplied in the script if they exist, but it cannot check if there is a PST file in it, or not. So in a case, where the C:\mail directory exists, but its empty, the script will fail with an error. Any possibility to overcome this would be great, even if the script keeps running by ignoring the error.

Thanks, and I am glad after all that more people can use this very useful script of which was built by so many people over this thread.

Ben
 
Hey Guys

I'm using what mrmovie suggest to write it to the HKCU and it working fine. I'm having a problem with the script checking if the file has been backed up today. I have


If lastBackup = date Then
' Already backed up today, quit script
WshShell.Popup "Your emails have already been copied today", 20
WScript.Quit
Else


''Run the Backup

End If


I don't get the pop saying that the file has been backed up already. Instead the script keep on running. WHY?

Thanks in Advance

Sincerely; Oscar
 
Hey Guys

I running the script which write to the Registry in the file called HKCU. I have notice that if I have three client logging on to the same computer and client one Log on first then the script runs, However if client two or three Logs on the same computer the same day then the script does not run because the registry has the same day as client one. Now where could I write the day the file is backing up too? I need to back it up to the client profile on the registry. Any Ideas?

Thanks in Advance

Sincerely; Oscar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top