Script powershell de sauvegarde Exchange 2007
// juillet 28th, 2009 // Exchange 2007
Ci dessous un script en PowerShell pour la sauvegarde d’un serveur Exchange 2007
function perform_backup ([string] $ServerName, [string] $BackupRootDrive) { ### Parametres ### $BackupScriptPath = $BackupRootDrive + "Backup-Exchange\Configuration-Backup-Exchange\" $BackupPath = $BackupRootDrive + "Backup-Exchange\" #Parametres Mail $EmailReportTo = "Votre_email@votre_domaine" $EmailReportFromAddress = "aotre_email@voter_domaine" $EmailSMTPServer = "serveur_smtp" $BackupLog = $BackupScriptPath + "ExchangeBackupLogs.log" #Creation du fichier de log - On remplace le fichier si il existe new-item $BackupLog -type file -force #Ajout des clés de registre pour augmenter la perf de ntbackup New-ItemProperty -Path:"HKCU:Software\Microsoft\Ntbackup\Backup Engine" -Name:"Logical Disk Buffer Size" -Value:"64" -PropertyType:"String" -Force New-ItemProperty -Path:"HKCU:Software\Microsoft\Ntbackup\Backup Engine" -Name:"Max Buffer Size" -Value:"1024" -PropertyType:"String" -Force New-ItemProperty -Path:"HKCU:Software\Microsoft\Ntbackup\Backup Engine" -Name:"Max Num Tape Buffers" -Value:"16" -PropertyType:"String" -Force Get-MailboxDatabase -Server:$ServerName | foreach{ #Creation du fichier JET pour NTBackup $JetBackupSyntax = "JET " + $_.ServerName + "\Microsoft Information Store\" + $_.StorageGroupName + "\" + $_.AdminDisplayName + "`n" $BksFileName = $BackupScriptPath + $_.ServerName + "" + $_.StorageGroupName + "" + $_.AdminDisplayName + ".bks" $JetBackupSyntax | out-file -filepath $BksFileName -encoding unicode #Lancement de NTBackup $BksDescriptiveName = $_.ServerName + "-" + $_.StorageGroupName.Replace(" ","_") + "-" + $_.AdminDisplayName.Replace(" ","_") &cmd /c "C:\WINDOWS\system32\ntbackup.exe backup `"@$BksFileName`" /n $BksDescriptiveName /d $BksDescriptiveName /v:no /r:no /rs:no /hc:off /m normal /fu /j `"$BksDescriptiveName`" /l:s /f $BackupPath$BksDescriptiveName.bkf" #Append database backup log to server backup log &type (get-childitem "$Home\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data\" | Sort -Property:LastWriteTime -Descending)[0].FullName >> $BackupLog } Get-PublicFolderDatabase -Server:$ServerName | foreach{ #Create the backup JET file for NTBackup $JetBackupSyntax = "JET " + $_.ServerName + "\Microsoft Information Store\" + $_.StorageGroupName + "\" + $_.AdminDisplayName + "`n" $BksFileName = $BackupScriptPath + $_.ServerName + "" + $_.StorageGroupName + "" + $_.AdminDisplayName + ".bks" $JetBackupSyntax | out-file -filepath $BksFileName -encoding unicode #Call NTBackup to backup the database $BksDescriptiveName = $_.ServerName + "-" + $_.StorageGroupName.Replace(" ","_") + "-" + $_.AdminDisplayName.Replace(" ","_") &cmd /c "C:\WINDOWS\system32\ntbackup.exe backup `"@$BksFileName`" /n $BksDescriptiveName /d $BksDescriptiveName /v:no /r:no /rs:no /hc:off /m normal /fu /j `"$BksDescriptiveName`" /l:s /f $BackupPath$BksDescriptiveName.bkf" #Append database backup log to server backup log &type (get-childitem "$Home\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data\" | Sort -Property:LastWriteTime -Descending)[0].FullName >> $BackupLog } #Add line breaks to format the backup log $BackupLogFormatted = "" Get-Content $BackupLog | foreach { $BackupLogFormatted += $_ + "`n" } #Email the backup log $smtp = New-Object Net.Mail.SmtpClient -arg $EmailSMTPServer $smtp.Send($EmailReportFromAddress,$EmailReportTo,"Exchange Backup Results for " + $ServerName + ": " + $(Get-Date).ToString('MM/dd/yyyy'),$BackupLogFormatted) } ### Start of backup script ### if (Test-Path D:\) { perform_backup "nom_su_serveur_exchange" "D:\" } else { write-host "--- Echec acces D: ---"; }
Leave a Reply
You must be logged in to post a comment.