August 10, 2016 at 3:05 am
Hi All,
I need a power-shell script to obtain the following information Name of the database , LastBackupDate of the database and this information should be sent via an email converting the results to HTML format using the powershell. Kindly help on this with, where to make the modifications.
Regards
NM
August 10, 2016 at 8:06 am
naren.ece2012 (8/10/2016)
Hi All,I need a power-shell script to obtain the following information Name of the database , LastBackupDate of the database and this information should be sent via an email converting the results to HTML format using the powershell. Kindly help on this with, where to make the modifications.
Regards
NM
My recommendation would be to NOT write PoSh scripts for this. It's an unnecessary complication. The script would have to hit on the MSDB tables to get the information anyway so why not write a simple stored procedure and send the email from there?
Better than that, why create a report at all? Whatever you're using to do your backups should send an email for any backup that failed when it fails.
Remember... if you can't write it, you might not be able to support it. 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
August 10, 2016 at 8:20 am
I agree with Jeff - no need for PowerShell. Write a view or stored procedure, and create a job to e-mail the results.
I don't share Jeff's doubt over whether a report is needed, though. If the backup doesn't run at all then you're not going to get a failure alert, so a regular report is a good thing - all the more so if it only shows those databases that haven't been backed up recently.
John
August 10, 2016 at 9:46 am
I've done this in T-SQL, as noted. I get the information and then build an HTML table that is emailed to users. It's easy to do and works well.
PoSh will work, and if you want the challenge, you can do it, but T-SQL is much easier.
August 14, 2016 at 11:26 am
John Mitchell-245523 (8/10/2016)
I agree with Jeff - no need for PowerShell. Write a view or stored procedure, and create a job to e-mail the results.I don't share Jeff's doubt over whether a report is needed, though. If the backup doesn't run at all then you're not going to get a failure alert, so a regular report is a good thing - all the more so if it only shows those databases that haven't been backed up recently.
John
I actually do get a regular report but it's not specific to backups. It provides me with the rolling 24 hour status of all jobs on the server (I don't have many servers so I created it to send me 1 email for each server). Of course, the backup job are included in that. My alerts also provide failure information for each database backup that failed while still letting the good ones through.
I just don't need a separate report for the backups because of the "Morning Jobs Report".
--Jeff Moden
Change is inevitable... Change for the better is not.
August 15, 2016 at 2:22 am
Jeff
Does your job highlight just jobs that failed, or does it include those that didn't run, perhaps because they were accidentally disabled, or because SQL Server Agent wasn't running?
I think backups are important enough to have their own report. Not only do I check that each database has been backed up, but also that the backup file exists in the location it was made.
I'm not saying this to claim that my way of doing things is better, but just to point out that different things work for different people and in different circumstances.
John
Edit - corrected typo
August 15, 2016 at 2:37 am
And how do you treat jobs that were cancelled part-way through?
Thomas Rushton
blog: https://thelonedba.wordpress.com
August 15, 2016 at 3:43 am
John Mitchell-245523 (8/15/2016)
JeffDoes your job highlight just jobs that failed, or does it include those that didn't run, perhaps because they were accidentally disabled, or because SQL Server Agent wasn't running?
I think backups are important enough to have their own report. Not only do I check that each database has been backed up, but also that the backup file exists in the location it was made.
I'm not saying this to claim that my way of doing things is better, but just to point out that different thinks work for different people and in different circumstances.
John
The report shows a whole lot even for a "summary". It shows whether the job is currently enabled or not. It shows whether it's scheduled or not or if it's a "One time" job that's run manually on occasion, all highlighted in different colors if out of the norm of enabled and scheduled. It shows the number of times the job ran, how many were successful, how many failed (color highlighted on failure, of course), and how many were cancelled. It shows the earliest run date/time in the 24 hour period, the latest run date/time 24 hour period be damned and, if that is more than a week old, highlights it in Yellow and Red if it hasn't run in a month. It shows the min and max run durations and it shows the last time the job was changed. If it changed anytime in the last week, that date is also colorized. Of course, the addition of a job is a change.
About the only thing not on the report is the median and mode of the run times and deleted jobs. And, like I said, I don't have a huge number of servers so each server generates it's own. It's an easy thing to push out to each server because I don't want all of the servers to stop reporting if the server that generates an enterprise wide report goes down..
That being said, a report for backups isn't a bad idea. I just don't need it for the way we're setup. If that changes, then you can bet I'll have a report on backups to go along with the alerts. You can also bet that it WON'T be a PoSh script that does it and that it'll get pushed to each server, like the jobs reports I have.
--Jeff Moden
Change is inevitable... Change for the better is not.
October 13, 2016 at 1:32 am
Thank you for the replies..
Can any one share the Posh scripts to my mail ID: naren.vgsqldba@gmail.com. Kindly do the needful.
Thanks
NM
October 13, 2016 at 11:13 am
naren.ece2012 (10/13/2016)
Thank you for the replies..Can any one share the Posh scripts to my mail ID: naren.vgsqldba@gmail.com. Kindly do the needful.
Thanks
NM
You can find many examples pretty easily if you just do a search on: powershell sql backup report
Sue
January 24, 2017 at 12:02 am
Sue_H - Thursday, October 13, 2016 11:13 AMnaren.ece2012 (10/13/2016)
Thank you for the replies..Can any one share the Posh scripts to my mail ID: naren.vgsqldba@gmail.com. Kindly do the needful.ThanksNMYou can find many examples pretty easily if you just do a search on: powershell sql backup reportSue
Thank You.
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply