Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am working in small Lan Sever 2003 and 60 XP prof. workstation. I have one backup server also with win server 2003. I have created schedule task for may back data and system state on my main server . I want to know is it possible to know by mail on my one workstation PC that my back is compeleted successfully or not. If I need write script for this then how. Could any one give me an example.I am using ntbackup which is by default with windows server 2003.

I don't think ntbackup has a built in notification like a lot of other software. What you could do is write a batch file to email you when the job is done and set it to run immediately after.
NOTE: Most people set their backups to run during off hours (ie: 3 am) You might try setting yours to that and then manually check the backup first thing in the morning.

Well, the easiest way I can think of doing this would be using the net send command and it would look something like this:
net send [username] [message]
So, lets assume you're using the administrator account and you're logged in:
net send administrator Backup has been performed
That's pretty basic and simple and there are much better batchfile writers than myself (mechanix this is your cue *G*) who could show you how to write it and have it include the time/date stamp.
Another alternative would be to have it email you the same message and then the email itself would be time/date stamped. Unfortunately, I'm not sure how to do that one. I always set the backups to run in the middle of the night and then manually checked the log first thing in the morning to ensure it ran properly.
Once you have a working batchfile you have two choices. You could include the contents at the end of the backup batchfile (if you're doing it out of a batchfile and not using the backup wizard to create the backup set and schedule it) or, you could create a separate scheduled task pointing at that batchfile set to run after the backup is performed.
I would like to reiterate though that nothing will replace manually checking to ascertain that the backup and verification (I always set the backup to verify the files) have been done properly. In the above scenario, if there were problems, they wouldn't be reported to you....you'ld get the same message regardless.

Now that I think about it for a few more seconds.....if you can get it to email you, have it email the backup log file. This way you'd know immediately whether the backup ran properly or not. I'm not sure offhand where the backup log files are stored and I don't have access to a 2000/03 server to check but if you looked I'm sure you could find them....they will have the .log extension. This makes a lot more sense as it automates the process and gives you the full backup report.

Hi,
This script may help you :
Have a look to the date format because in France it is ddmmyyyy. In the function WMIDateStringToDate, you may have to switch "...7, 2.." and "...5, 2...".--
' Script VBS d'envoi par mel des fichiers contenus dans un répertoire en fonction de la date du fichier.
' Prévu pour envoyer des logs de NTBackup par mel
'
' Syntaxe :
' sendlog -e<expediteur> -d<destinataire> -o<objet> -s<serveur_smtp> -f<repertoire> -p<periode>
' sendlog /e<expediteur> /d<destinataire> /o<objet> /s<serveur_smtp> /f<repertoire> /p<periode>
' Paramètres obligatoires :
' <expediteur> : adresse email de l'expéditeur
' <destinataire> : adresse email du destinataire
' <objet> : objet (titre) du message
' <serveur_smtp> : adresse du serveur smtp
' <repertoire> : repertoire où se trouve les fichiers de log
' <periode> : nb de jours à prendre en compte
' NB : les chaines et nom de fichier sont à encadrer par des guillemets
' s'ils comportent des espaces
' NB : !!! le répertoire doit être noté avec des doubles \ !!!!
'
' Exemple :
' sendlog -enicolas.perdrix@microsoft.fr -dnicolas.perdrix@mandriva.fr -o"Rapport de Sauvegarde" -ssmtp.microsoft.fr -f"'\\Documents and Settings\\Nico\\Local Settings\\Application Data\\Microsoft\\Windows NT\\NTBackup\\data\\'" -p1
'
' Enverra un mel de nicolas.perdrix@microsoft.fr à nicolas.perdrix@mandriva.fr
' L'objet sera Rapport de Sauvegarde
' On enverra vers le serveur smtp.microsoft.fr
' On scannera le répertoire \Documents and Settings\Nico\...etc...
' On enverra les fichiers créés ou modifiés pendant la dernière journée
'
' N PERDRIX © 2005
' GRACE A
' JC BELLAMY © 2002
--strComputer = "."
Dim args, fso, f,shellSet objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objEmail = CreateObject("CDO.Message")
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
Set shell = WScript.CreateObject("WScript.Shell")
Set args = Wscript.Arguments
ForReading=1nbargs=args.count
defmoteur="cscript"
If nbargs=0 or testarg("?") or testarg("h") Then Syntaxe ""
' Test du moteur utilisé
TestHostIf not testarg("e") then Syntaxe "Email expéditeur absent"
If not testarg("d") then Syntaxe "Email destinataire absent"
If not testarg("o") then Syntaxe "Objet absent"
If not testarg("s") then Syntaxe "Serveur SMTP absent"
If not testarg("f") then Syntaxe "Répertoire absent"
If not testarg("p") then Syntaxe "Période absente"fromaddr=getarg("e")
If not IsValidEmail(fromaddr) Then Syntaxe "Email expéditeur invalide"
toaddr=getarg("d")
If not IsValidEmail(toaddr) Then Syntaxe "Email destinataire invalide"
objet=getarg("o")
smtpserv=getarg("s")
dirlog=getarg("f")
period=getarg("p")
period = CInt(period)Set colFiles = objWMIService.ExecQuery("Select * from CIM_DataFile where Path = " & dirlog)
For Each objFile in colFiles
CurrentDate = DateInfo & Now
modifyDate = objFile.LastModified
strReturn = WMIDateStringToDate(modifyDate)
dateDifference = Abs(DateDiff("d", CurrentDate, strReturn))
if dateDifference < period then
sendmail(objFile.Name)
end if
Next
-----------
' Sous programme de test du moteur
Sub TestHost
dim rep
strFullName =lcase(WScript.FullName)
strappli=lcase(Wscript.ScriptFullName)
i=InStr(1,strFullName,".exe",1)
j=InStrRev(strFullName,"\",i,1)
strCommand=Mid(strFullName,j+1,i-j-1)
if strCommand<>defmoteur then
rep=MsgBox( _
"Pour faciliter l'affichage, il est recommandé" & VBCRLF & _
"de lancer ce script avec """ & defmoteur & """" & VBCRLF & _
"Cela peut être rendu permanent avec la commande" & VBCRLF & _
"cscript //H:" & defmoteur &" //S /Nologo" & VBCRLF & _
"Voulez-vous que ce soit fait automatiquement?", _
vbYesNo + vbQuestion,strappli)
if rep=vbYes then
nomcmd="setscript.bat"
Set ficcmd = fso.CreateTextFile(nomcmd)
ficcmd.writeline "@echo off"
ficcmd.writeline "cscript //H:" & defmoteur & " //S /Nologo"
ficcmd.writeline "pause"
params=""
For i = 0 To nbargs-1
params=params & " " & args(i)
next
ficcmd.writeline chr(34) & strappli & chr(34) & params
ficcmd.writeline "pause"
ficcmd.close
shell.Run nomcmd, SW_SHOWNORMAL,true
WScript.Quit
end if
end if
end sub
-----------
Sub Syntaxe(info)
If info="" Then
msg= "Script d'envoi par mel des fichiers contenus dans un répertoire en fonction de la date du fichier." & VBCRLF
msg=msg & "N PERDRIX GRACE A JC BELLAMY" & VBCRLF
Else
msg="*** " & info & " ***" & VBCRLF
End If
msg=ms------------------" & VBCRLF
msg=msg & "Syntaxe : " & VBCRLF
msg=msg & " sendlog -e<expediteur> -d<destinataire> -o<objet> -s<serveur_smtp> -f<repertoire> -p<periode>" & VBCRLF
msg=msg & "" & VBCRLF
msg=msg & " sendlog /e<expediteur> /d<destinataire> /o<objet> /s<serveur_smtp> /f<repertoire> /p<periode>" & VBCRLF
msg=msg & "" & VBCRLF
msg=msg & "Paramètres obligatoires :" & VBCRLF
msg=msg & " <expediteur> : adresse email de l'expéditeur" & VBCRLF
msg=msg & " <destinataire> : adresse email du destinataire" & VBCRLF
msg=msg & " <objet> : objet (titre) du message" & VBCRLF
msg=msg & " <serveur_smtp> : adresse du serveur smtp" & VBCRLF
msg=msg & " <repertoire> : repertoire où se trouve les fichiers de log" & VBCRLF
msg=msg & " <periode> : nb de jours à prendre en compte" & VBCRLF
msg=msg & "" & VBCRLF
msg=msg & "NB : les chaines et noms de fichier sont à encadrer par des guillemets" & VBCRLF
msg=msg & " s'ils comportent des espaces" & VBCRLF & VBCRLF
msg=msg & " NB : !!! le répertoire doit être noté avec des doubles \ !!!!" & VBCRLF
msg=msg & "" & VBCRLF
msg=msg & "Exemples :"& VBCRLF
msg=msg & "" & VBCRLF
msg=msg & "sendlog -enicolas.perdrix@microsoft.fr -dnicolas.perdrix@mandriva.fr -o""Rapport de Sauvegarde"" -ssmtp.microsoft.fr -f""'\\Documents and Settings\\Nico\\Local Settings\\Application Data\\Microsoft\\Windows NT\\NTBackup\\data\\'"" -p1" & VBCRLF
msg=msg & "" & VBCRLF
wscript.echo msg
wscript.quit
End Sub
-----------
Function IsValidEmail(str)
Dim re
Set re = New RegExp
re.pattern = "\w+\@[.\w]+" 'Modèle du style "nnnnnn@dddddd"
IsValidEmail=re.Test(str)
End Function
-----------
Function testarg(param)
testarg=false
For i = 0 To nbargs-1
curarg=lcase(args(i))
If left(curarg,1)="/" or left(curarg,1)="-" Then
If mid(curarg,2,len(param))=param Then
testarg=true
exit function
End If
End If
Next
End Function
-----------
Function getarg(param)
getarg=""
For i = 0 To nbargs-1
curarg=lcase(args(i))
If left(curarg,1)="/" or left(curarg,1)="-" Then
If mid(curarg,2,len(param))=param Then
ch=mid(args(i),2+len(param))
If (left(ch,1)="""") and (right(ch,1)="""") Then ch=mid(ch,2,len(ch)-2)
getarg= ch
exit function
End If
End If
Next
End Function
-----------
'
Sub sendmail(FileSelected)
objEmail.From = fromaddr
objEmail.To = toaddr
objEmail.Subject = objet
body = GetString(FileSelected)
objEmail.Textbody = body
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = smtpserv
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
End Sub
-----------
'Function GetString(str)
dim f
If fso.FileExists(str) Then
set f = fso.OpenTextFile(str,ForReading,true,-1)
GetString = f.ReadAll
f.Close
else
GetString=Replace(str,"\n",VBCRLF,1,-1,1)
End If
End Function-----------
'
Function WMIDateStringToDate (modifyDate)
WMIDateStringToDate = CDate(Mid(modifyDate, 7, 2) & "/" & Mid(modifyDate, 5, 2) & "/" & Left(modifyDate, 4) & " " & Mid (modifyDate, 9, 2) & ":" & Mid(modifyDate, 11, 2) & ":" & Mid(modifyDate, 13, 2))
End FunctionNicolas Perdrix

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |