SQL Backups, Restores and Verification with SQL Sever

1,092 views

Published on

A presentation from SQL Southwest User Group about using PowerShell to automate SQL Server backups, restores and verifications, so DBAs can get on with the more fun things in life.

An accompanying set of scripts are available from my website http://stuart-moore.com

Published in: Technology
  • hey visit me : http://comtam.web10s.com/gioi-thieu-ve-com-tam-ngon-binh-duong/
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

SQL Backups, Restores and Verification with SQL Sever

  1. 1. Automating restores and verification to leave more time for the fun things in a DBA’s job
  2. 2.  Started with SQL Server 7 in 1998, 15 years later still working with it, but newer versions as well.  Worked as DBA and Developer in that period.  Also work with Oracle, MySQL and Linux  In spare time I’m most likely to be found studying a Mathematics degree with the OU, or sat on a bike saddle somewhere remote.  Email: stuart.moore@stuart-moore.co.uk  Blog: http://stuart-moore.com  Twitter: @napalmgram
  3. 3.  Started off as Monad back in 2005  Improved with each version, now on version 3  Lots of support for SQL Server: ◦ SMO – SQL Management Objects ◦ SQLPS – Official SQL Server Module, offers methods for the above ◦ SQLPSX – Unofficial SQL Server Module
  4. 4.  Essential part of the job  Easy to set up simple backup routines with maintenance plans, not so easy for complex setups
  5. 5.  Should be as essential as backups: ◦ Did the backup really complete properly? ◦ How long does a full restore take (how long should RTO be) ◦ How long do the transaction backups take to restore? ◦ Do you have whole backup chain ◦ If needed, can you prove it to Auditors?
  6. 6.  SQL Server doesn’t offer an easy means to automate restores.  Tend to need to build a job for each database ◦ Not easy with an instance with 100s of DB ◦ Differing file layouts also a problem
  7. 7.  Demos may not be the best examples of PowerShell. ◦ I’ve taken some liberties to make them easier to read ◦ Best practice is to write reusable functions, not lots of scripts.
  8. 8. 1. Basic Full backup of single db 2. Backup all DB on an instance 3. Catch new databases 4. Split Database backups
  9. 9. 1. Simple Restore 2. Include transaction backups 3. Check transaction log order 4. Restore with file relocation 5. Restore to Random point in Time
  10. 10.  So now we’ve restored the database is that it?  No, we need to check that it’s actually usable and structurally sound. ◦ Run DBCC checks against ◦ Run our own scripts to check integrity or business rules  Corrupted DBs courtesy of Paul Randal from here - http://bit.ly/1dEeklT
  11. 11.  Use Invoke-Sqlcmd ◦ Problems with query timeouts fixed in SQL Server 2012 ◦ Versions prior to that, look at Invoke-Sqlcmd from Chad Miller - http://bit.ly/16GOeL8
  12. 12.  Using DBCC
  13. 13.  Nothing other than SQL Server backup and restores. ◦ Not a faster method ◦ Not a slower method ◦ Can be monitored just like all other backups ◦ Blocked by exactly the same things
  14. 14.  Not the world’s most informative error messages: ◦ Plenty of error checking in production scripts ◦ Or get used to stepping through to find the problems

×