tag:blogger.com,1999:blog-729006988063752899.post1672145411000768310..comments2023-09-10T07:45:44.721-06:00Comments on Imperfect IT: Automate SharePoint 2010 Farm Backups with PowershellImperfect IThttp://www.blogger.com/profile/17712658943670769100noreply@blogger.comBlogger41125tag:blogger.com,1999:blog-729006988063752899.post-12065628330906309042014-01-07T11:27:31.882-07:002014-01-07T11:27:31.882-07:00Greetings.... Yesterday I posted a comment where b...Greetings.... Yesterday I posted a comment where by I discovered there was a bug in your script. Turns out that when comparing the date from the XML file (SPStartTime) it is doing a string compare and not a date compare. I've fixed the syntax to resolve this problem. The problem arose when crossing over into a new year. (less than 7 days into the new year). Because of the string compare the current backup was being purge along with the oldest. I corrected the script by changing this line:<br /><br />$old = $sp.SPBackupRestoreHistory.SPHistoryObject |<br />? { [DateTime]::Parse($_.SPStartTime) -lt ((get-date).adddays(-$days)) }<br /><br />I've tested this and it works. <br /><br />HNY<br />Kurt Zimmerman <br />Sr. DBA<br />Lefrak OrganizationAnonymoushttps://www.blogger.com/profile/00227294515338919554noreply@blogger.comtag:blogger.com,1999:blog-729006988063752899.post-73344627209280696442014-01-06T13:27:05.181-07:002014-01-06T13:27:05.181-07:00Good day... I found your PS scripts several months...Good day... I found your PS scripts several months ago and will honestly say all was working until the end of the year hit. What I'm finding is the backup works just fine however the purge process to maintain the 7 days of backups appears not to be working correctly. I have found that it is not only purging off the > 7 day old backups, it is also purging off the current backup. For now I have disabled the purge process until I can find a solution. I am wondering if anyone else has reported this problem.<br /><br />Kurt ZimmermanAnonymoushttps://www.blogger.com/profile/00227294515338919554noreply@blogger.comtag:blogger.com,1999:blog-729006988063752899.post-59472125025708583472013-06-27T06:32:44.660-06:002013-06-27T06:32:44.660-06:00I'm having a error when the task will run on t...I'm having a error when the task will run on the scheduled time. The issue it's about admin privilegies because when i run the task logged in everything works fine. Any help would be great!Dan@Desenvhttps://www.blogger.com/profile/16426452235017568281noreply@blogger.comtag:blogger.com,1999:blog-729006988063752899.post-74599227312078730582013-04-12T17:59:40.175-06:002013-04-12T17:59:40.175-06:00Anyone using this with SharePoint 2013? I suppose...Anyone using this with SharePoint 2013? I suppose I could pay for it, set it all up and try it, but it would be nice to know someone else had success with it first.<br /><br />Thanks!Carlnoreply@blogger.comtag:blogger.com,1999:blog-729006988063752899.post-25884521185853464742013-02-22T04:21:25.719-07:002013-02-22T04:21:25.719-07:00When i run the clean.bat, i get the following erro...When i run the clean.bat, i get the following error:<br />Get-Content : Access to the path 'd:\Backup\Farm' is denied.<br />At C:\Scripts\CleanFarmBackup.ps1:8 char:12<br />+ [xml]$sp = gc $spbrtoc<br />+ ~~~~~~~~~~~<br /> + CategoryInfo : PermissionDenied: (D:\Backup\Farm:String) [Get-Content], UnauthorizedAccessException<br /> + FullyQualifiedErrorId : GetContentReaderUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetContentCommand<br /><br />Any ideas how to solve this?<br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-729006988063752899.post-31249102870875050142013-02-05T15:44:56.803-07:002013-02-05T15:44:56.803-07:00Looks like the above script by BTC Solutions Devel...Looks like the above script by BTC Solutions Development Team works but he forgot a line to handle the return of Null items.<br /><br />if ($old -eq $Null) { write-host "No reports of backups older than $days days found in spbrtoc.xml.`nspbrtoc.xml isn't changed and no files are removed.`n" ; break}<br /><br />I found this info at this address:<br /><a href="http://stackoverflow.com/questions/4627391/how-to-correct-this-powershell-script-that-auto-deletes-sharepoint-backups" rel="nofollow">http://stackoverflow.com/questions/4627391/how-to-correct-this-powershell-script-that-auto-deletes-sharepoint-backups</a>Brian Fischerhttps://www.blogger.com/profile/16815292425237593229noreply@blogger.comtag:blogger.com,1999:blog-729006988063752899.post-20589172518123382422013-02-05T14:32:10.261-07:002013-02-05T14:32:10.261-07:00I'm having the same issue as Craig Liess above...I'm having the same issue as Craig Liess above. I think the problem stems from the script not differentiating the year? I had backups in Nov, Dec, and Jan. I told the script to delete anything beyond 75 days. The only backups it kept were the ones in late Nov and all of Dec (anything beyond 75 days were indeed deleted). However, the most recent Jan backups were deleted. I'm guessing the script screwed up on the year and thought that the recent Jan backups were from last year.<br /><br />I'm going to test and see if the script adjustment to the date compare that BTC Solutions Development Team posted here on Jan 24, 2011 will fix the issueBrian Fischerhttps://www.blogger.com/profile/16815292425237593229noreply@blogger.comtag:blogger.com,1999:blog-729006988063752899.post-41811229133047270492013-02-05T14:29:48.930-07:002013-02-05T14:29:48.930-07:00This comment has been removed by the author.Brian Fischerhttps://www.blogger.com/profile/16815292425237593229noreply@blogger.comtag:blogger.com,1999:blog-729006988063752899.post-1884818520289183702013-01-18T03:51:47.125-07:002013-01-18T03:51:47.125-07:00Hi
The backup is running perfectly but I'm ha...Hi <br />The backup is running perfectly but I'm having problems with the clean backup. I am using the latest version of the script but get the following errors.<br /><br /><br />Exception calling "RemoveChild" with "1" argument(s): "Object reference not set<br /> to an instance of an object."<br />At line:1 char:50<br />+ $old | % { $sp.SPBackupRestoreHistory.RemoveChild <<<< ($_) }<br /> + CategoryInfo : NotSpecified: (:) [], MethodInvocationException<br /> + FullyQualifiedErrorId : DotNetMethodException<br /><br />and<br /><br />Remove-Item : Cannot bind argument to parameter 'Path' because it is null.<br />At line:1 char:23<br />+ $old | % { Remove-Item <<<< $_.SPBackupDirectory -Recurse }<br /> + CategoryInfo : InvalidData: (:) [Remove-Item], ParameterBinding<br /> ValidationException<br /> + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,M<br /> icrosoft.PowerShell.Commands.RemoveItemCommand<br /><br />all help gratefully received.<br />NWBluehttps://www.blogger.com/profile/16763379470527170111noreply@blogger.comtag:blogger.com,1999:blog-729006988063752899.post-88633536340377825432013-01-09T14:35:08.134-07:002013-01-09T14:35:08.134-07:00Well I could make no rhyme or reason for it. Same...Well I could make no rhyme or reason for it. Same thing happened on my production and development farms. I simply deleted the spbrtoc.xml file and let it recreate with a new backup. That seems to have done the trick in both environments. Nothing I could come up with to why this happened other than the year change and me happening to notice it because of a larger than expected amount of free space on the drive.DubAhUnoreply@blogger.comtag:blogger.com,1999:blog-729006988063752899.post-12279346346695934312013-01-08T08:37:46.971-07:002013-01-08T08:37:46.971-07:00Having the same symptoms as Craig. I don't ha...Having the same symptoms as Craig. I don't have KB2506143 installed. Both the backup and cleanup scripts seem to run fine if I execute them myself. The madness seems to happen when the scheduled tasks run, which is when I'm not here. Overnight, the backup I manually created yesterday was deleted. When I just ran a backup and then the delete job, it functions normal (backup happened, delete job told me there were no backups older than 7 days). I'm going to schedule them to run now, and see what happens.DubAhUnoreply@blogger.comtag:blogger.com,1999:blog-729006988063752899.post-90210404628171404592013-01-07T10:09:39.696-07:002013-01-07T10:09:39.696-07:00The Backup itself is working like a champ for me, ...The Backup itself is working like a champ for me, but the cleanup for whatever reason, is not. Imperfect IT, any idea what may cause the cleanup to delete the entire contents of the backup folder? We're using the exact scripts above, and they've been working perfectly for months!Anonymoushttps://www.blogger.com/profile/14155467373485264633noreply@blogger.comtag:blogger.com,1999:blog-729006988063752899.post-8581882621453818902013-01-07T09:15:57.167-07:002013-01-07T09:15:57.167-07:00We recently noticed that installing KB2506143 (Win...We recently noticed that installing KB2506143 (Windows Management Framework 3.0) breaks the ability for SharePoint Powershell to run the backup. Uninstall it and the script should start working again.Imperfect IThttps://www.blogger.com/profile/17712658943670769100noreply@blogger.comtag:blogger.com,1999:blog-729006988063752899.post-22158877903508010102013-01-07T09:05:01.905-07:002013-01-07T09:05:01.905-07:00This has been working flawless for us for 6 months...This has been working flawless for us for 6 months.. and now that it's 2013, the backup script is deleting EVERYTHING in the folder and stripping virtually everything out of spbrtoc.xml except:<br /><br /><br /><br /><br /><br />Anyone else run into this?<br /><br />-CraigAnonymoushttps://www.blogger.com/profile/14155467373485264633noreply@blogger.comtag:blogger.com,1999:blog-729006988063752899.post-24785069679797092172012-08-02T09:01:42.032-06:002012-08-02T09:01:42.032-06:00I'm having problems with the $old variable alw...I'm having problems with the $old variable always being null. <br />I'm in Europe so my date formats are different.Carol Chisholmhttps://www.blogger.com/profile/03414299909957687344noreply@blogger.comtag:blogger.com,1999:blog-729006988063752899.post-76076861016312652532012-07-17T11:02:02.551-06:002012-07-17T11:02:02.551-06:00Thanks Imp!
Worked flawlessly first run!
VTQneto...Thanks Imp!<br /><br />Worked flawlessly first run!<br /><br />VTQnetops!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-729006988063752899.post-14285913400912831042012-01-25T10:36:55.297-07:002012-01-25T10:36:55.297-07:00Sounds like a problem with you script. Here's ...Sounds like a problem with you script. Here's a copy of one of the ones we're using right now:<br /><br /># Location of spbrtoc.xml<br />$spbrtoc = "\\networkshare\spbrtoc.xml" <br /><br /># Days of backup that will be remaining after backup cleanup.<br />$days = 3 <br /><br /># Import the Sharepoint backup report xml file<br />[xml]$sp = gc $spbrtoc <br /><br /># Find the old backups in spbrtoc.xml<br />$old = $sp.SPBackupRestoreHistory.SPHistoryObject |<br />? { $_.SPStartTime -lt ((get-date).adddays(-$days)) }<br />if ($old -eq $Null) { write-host "No reports of backups older than $days days found in spbrtoc.xml.`nspbrtoc.xml isn't changed and no files are removed.`n" ; break} <br /><br /># Delete the old backups from the Sharepoint backup report xml file<br />$old | % { $sp.SPBackupRestoreHistory.RemoveChild($_) } <br /><br /># Delete the physical folders in which the old backups were located<br />$old | % { Remove-Item $_.SPBackupDirectory -Recurse } <br /><br /># Save the new Sharepoint backup report xml file<br />$sp.Save($spbrtoc)<br />Write-host "Backup(s) entries older than $days days are removed from spbrtoc.xml and harddisc."Imperfect IThttps://www.blogger.com/profile/17712658943670769100noreply@blogger.comtag:blogger.com,1999:blog-729006988063752899.post-78145173332591826672012-01-20T06:40:41.749-07:002012-01-20T06:40:41.749-07:00First off I want to say thank you for posting this...First off I want to say thank you for posting this write up for this task, it is greatly appreciated for a beginner administrator like myself. <br /><br />So the back up portion is working with out flaw, however when I run the cleanup I am getting a error that I am not sure what to fix. I have copied and pasted the script from here and I have also retyped it char for char and I get the same error either way. <br /><br />Missing expression after unary operator '-'.<br />At line:1 char:2<br /><br />+ - <<<< noclue c:\sharepointbackup\scripts\sharepointcleanupscript.ps1<br />+CategoryInfo : ParserError: (-:Sting) [], ParentContainsErrorRecordException<br />+FullyQualifiedErrorId : MissingExpresionAfterOperator<br /><br />Any advice or guidance on this issue would be greatly appreciated.<br /><br />Thanks much<br />Chrischris.gumphttps://www.blogger.com/profile/07075737274229129587noreply@blogger.comtag:blogger.com,1999:blog-729006988063752899.post-74170895505808662962011-11-16T16:46:46.342-07:002011-11-16T16:46:46.342-07:00Just set up the backupsharepointfarm.ps1 on my new...Just set up the backupsharepointfarm.ps1 on my new server. The backup works fine. However the script does not exit, either when run within Powershell or from the backup.bat file created. I only modified the "Backup-SPFarm - Direcotory..." line.<br /><br />Any ideas?<br /><br />Thanks for the blog.<br /><br />Jeffrckymtnriderhttps://www.blogger.com/profile/05881401714980394070noreply@blogger.comtag:blogger.com,1999:blog-729006988063752899.post-53120001764744799202011-09-28T14:14:33.466-06:002011-09-28T14:14:33.466-06:00Worked as advertised. Thanks!Worked as advertised. Thanks!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-729006988063752899.post-61344509876524621622011-08-15T20:57:41.582-06:002011-08-15T20:57:41.582-06:00works perfectly, Thanks.
just one add, that be su...works perfectly, Thanks.<br /><br />just one add, that be sure that that user who will be running the task schedule can run powershell commands. for this just run the .bat script in shell manually and see if it gives errors or not.<br /><br />Thanks.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-729006988063752899.post-24191072224591751692011-07-12T09:55:00.263-06:002011-07-12T09:55:00.263-06:00Great and nice article, now any idea about catchin...Great and nice article, now any idea about catching an error and sending a mail if it occurs? should be easy with powershell :)Emmanuel ISSALYhttps://www.blogger.com/profile/03807630171735271446noreply@blogger.comtag:blogger.com,1999:blog-729006988063752899.post-38772703784057867632011-05-26T12:17:12.601-06:002011-05-26T12:17:12.601-06:00Thank you for the nice post. I combined the two sc...Thank you for the nice post. I combined the two scripts into one and added email notification on error.<br />#Clear the error object and set it to SilentlyContinue<br />$error.clear()<br />$erroractionpreference = "SilentlyContinue"<br /><br />#Add The SharePoint Powershell <br />Add-PsSnapin Microsoft.SharePoint.Powershell | Out-File -FilePath C:\Scripts\backupsharepointfarm.log -Append<br /><br />#Run the Backup farm command<br />Backup-SPFarm -Directory \\ServerName\Backups -BackupMethod full | Out-File -FilePath C:\Scripts\backupsharepointfarm.log -Append<br /><br /># Location of spbrtoc.xml<br />$spbrtoc = "\\ServerName\Backups\spbrtoc.xml"<br /><br /># Days of backup that will be remaining after backup cleanup.<br />$days = 3<br /><br /># Import the Sharepoint backup report xml file<br />[xml]$sp = gc $spbrtoc | Out-File -FilePath C:\Scripts\backupsharepointfarm.log -Append<br /><br /># Find the old backups in spbrtoc.xml<br />$old = $sp.SPBackupRestoreHistory.SPHistoryObject | ? { $_.SPStartTime -lt ((get-date).adddays(-$days)) } | Out-File -FilePath C:\Scripts\backupsharepointfarm.log -Append<br />if ($old -eq $Null) <br />{ <br /> Write-Output "No reports of backups older than $days days found in spbrtoc.xml.`nspbrtoc.xml isn't changed and no files are removed.`n" | Out-File -FilePath C:\Scripts\backupsharepointfarm.log -Append <br />}<br />else<br />{<br /> # Delete the old backups from the Sharepoint backup report xml file<br /> $old | % { $sp.SPBackupRestoreHistory.RemoveChild($_) } | Out-File -FilePath C:\Scripts\backupsharepointfarm.log -Append<br /><br /> # Delete the physical folders in which the old backups were located<br /> $old | % { Remove-Item $_.SPBackupDirectory -Recurse } | Out-File -FilePath C:\Scripts\backupsharepointfarm.log -Append<br /><br /> # Save the new Sharepoint backup report xml file<br /> $sp.Save($spbrtoc) | Out-File -FilePath C:\Scripts\backupsharepointfarm.log -Append<br /> Write-Output "Backup(s) entries older than $days days are removed from spbrtoc.xml and harddisc." | Out-File -FilePath C:\Scripts\backupsharepointfarm.log -Append<br />}<br /><br />#Check if any error has occured and send an alert email if it did.<br />if ($error[0])<br />{<br /> Write-Output "An error has occurred" | Out-File -FilePath C:\Scripts\backupsharepointfarm.log -Append;<br /> for ($i=0; $i -le $error.count; $i++) {Write-Output $error[$i] | Out-File -FilePath C:\Scripts\backupsharepointfarm.log -Append}<br /> <br /> ###First, the administrator must change the mail message values in this section<br /> $FromAddress = "SharepointBackup@yourcompany.com"<br /> $ToAddress = "alerts@yourcompany.com"<br /> $MessageSubject = "Sharepoint backup failed."<br /> $MessageBody = "The Sharepoint Server backup Failed. Please check."<br /> $SendingServer = "mail.yourcompany.com"<br /><br /> ###Create the mail message<br /> $SMTPMessage = New-Object System.Net.Mail.MailMessage $FromAddress, $ToAddress, $MessageSubject, $MessageBody<br /><br /> ###Send the message<br /> $SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer<br /> $SMTPClient.Send($SMTPMessage)<br /><br />}Vladimir Sotirovhttp://www.sqlserverguy.comnoreply@blogger.comtag:blogger.com,1999:blog-729006988063752899.post-43862453631824258202011-05-21T20:00:46.108-06:002011-05-21T20:00:46.108-06:00thanks for the great article , what if i need to d...thanks for the great article , what if i need to deploy full and then differential backup ? would you please guide me to do that ?<br /><br />regards,Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-729006988063752899.post-29686241902491185982011-04-27T16:00:35.437-06:002011-04-27T16:00:35.437-06:00Hi IIT.
Thx for the answer. Unfortunatelly, I don...Hi IIT.<br /><br />Thx for the answer. Unfortunatelly, I don't think it's a permission issue, cause I use the same account of the backup task and the backup works like a charm.<br /><br />I'm still stucked on that :-(. Any more ideas?<br /><br />Thanks again.-https://www.blogger.com/profile/12175824478701865514noreply@blogger.com