1. Trang chủ
  2. » Công Nghệ Thông Tin

SQL Server Backup and Restore pot

391 1,3K 1

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 391
Dung lượng 4,78 MB

Nội dung

ISBN: 978-1-906434-74-8 SQL Server Backup and Restore Shawn McGehee The Red Gate Guide SQL Server Backup and Restore By Shawn McGehee First published by Simple Talk Publishing April 2012 Copyright April 2012 ISBN 978-1-906434-85-4 The right of Shawn McGehee to be identified as the author of this work has been asserted by him in accordance with the Copyright, Designs and Patents Act 1988. All rights reserved. No part of this publication may be reproduced, stored or introduced into a retrieval system, or transmitted, in any form, or by any means (electronic, mechanical, photocopying, recording or otherwise) without the prior written consent of the publisher. Any person who does any unauthorized act in relation to this publication may be liable to criminal prosecution and civil claims for damages. This book is sold subject to the condition that it shall not, by way of trade or otherwise, be lent, re-sold, hired out, or otherwise circulated without the publisher's prior consent in any form other than that in which it is published and without a similar condition including this condition being imposed on the subsequent publisher. Technical Review by Eric Wisdahl Cover Image by Andy Martin Edited by Tony Davis Typeset & Designed by Peter Woodhouse & Gower Associates Table of Contents Introduction ___________________________________________12 Software Requirements and Code Examples ________________________________ 18 Chapter 1: Basics of Backup and Restore ___________________19 Components of a SQL Server Database ___________________________________ 20 Data files ________________________________________________________ 20 Filegroups _________________________________________________________22 Transaction log ____________________________________________________24 SQL Server Backup Categories and Types __________________________________28 SQL Server database backups _________________________________________29 SQL Server transaction log backups ____________________________________ 32 File backups _______________________________________________________36 Recovery Models ______________________________________________________39 Simple____________________________________________________________ 41 Full ______________________________________________________________43 Bulk Logged ______________________________________________________ 44 Restoring Databases ___________________________________________________ 46 Restoring system databases ___________________________________________47 Restoring single pages from backup ____________________________________48 Summary ___________________________________________________________ 49 Chapter 2: Planning, Storage and Documentation ___________50 Backup Storage ________________________________________________________50 Local disk (DAS or SAN) _____________________________________________ 52 Network device ____________________________________________________58 Tape _____________________________________________________________59 Backup Tools ________________________________________________________ 60 Maintenance plan backups ___________________________________________ 61 Custom backup scripts ______________________________________________62 Third-party tools ___________________________________________________63 Backup and Restore Planning ___________________________________________ 64 Backup requirements _______________________________________________65 Restore requirements ______________________________________________ 68 An SLA template __________________________________________________ 69 Example restore requirements and backup schemes _______________________ 71 Backup scheduling __________________________________________________ 73 Backup Verification and Test Restores _____________________________________ 75 Back up WITH CHECKSUM _________________________________________76 Verifying restores ___________________________________________________77 DBCC CHECKDB __________________________________________________77 Documenting Critical Backup Information _________________________________78 Summary ____________________________________________________________83 Chapter 3: Full Database Backups _______________________ 84 What is a Full Database Backup? _________________________________________ 84 Why Take Full Backups? ________________________________________________85 Full Backups in the Backup and Restore SLA _______________________________ 86 Preparing for Full Backups ______________________________________________87 Choosing the recovery model _________________________________________88 Database creation __________________________________________________88 Creating and populating the tables ____________________________________ 94 Taking Full Backups ___________________________________________________ 96 Native SSMS GUI method ____________________________________________97 Native T-SQL method ______________________________________________106 Native Backup Compression ____________________________________________ 111 Verifying Backups ____________________________________________________ 113 Building a Reusable and Schedulable Backup Script _________________________ 114 Summary ___________________________________________________________ 115 Chapter 4: Restoring From Full Backup ___________________ 116 Full Restores in the Backup and Restore SLA ______________________________ 116 Possible Issues with Full Database Restores ________________________________ 117 Large data volumes ________________________________________________ 118 Restoring databases containing sensitive data ___________________________ 118 Too much permission ______________________________________________ 120 Performing Full Restores _______________________________________________ 122 Native SSMS GUI full backup restore __________________________________ 122 Native T-SQL full restore ___________________________________________ 129 Forcing Restore Failures for Fun _________________________________________ 133 Considerations When Restoring to a Different Location _____________________ 136 Restoring System Databases ____________________________________________ 137 Restoring the msdb database ________________________________________ 138 Restoring the master database _______________________________________140 Summary ___________________________________________________________ 143 Chapter 5: Log Backups ________________________________144 A Brief Peek Inside a Transaction Log ____________________________________ 145 Three uses for transaction log backups ___________________________________ 148 Performing database restores ________________________________________ 149 Large database migrations ___________________________________________ 150 Log shipping _____________________________________________________ 151 Log Backups in the Backup and Restore SLA _______________________________ 152 Preparing for Log Backups _____________________________________________ 153 Choosing the recovery model ________________________________________ 154 Creating the database ______________________________________________ 155 Creating and populating tables _______________________________________ 157 Taking a base full database backup ____________________________________ 159 Taking Log Backups ___________________________________________________ 161 The GUI way: native SSMS log backups ________________________________ 161 T-SQL log backups _________________________________________________ 166 Forcing Log Backup Failures for Fun _____________________________________170 Troubleshooting Log Issues ____________________________________________ 172 Failure to take log backups __________________________________________ 173 Other factors preventing log truncation _______________________________ 174 Excessive logging activity ___________________________________________ 175 Handling the 9002 Transaction Log Full error __________________________ 176 Log fragmentation _________________________________________________ 177 Summary ___________________________________________________________ 181 Chapter 6: Log Restores ________________________________182 Log Restores in the SLA ________________________________________________ 182 Possible Issues with Log Restores ________________________________________ 183 Missing or corrupt log backup _______________________________________ 183 Missing or corrupt full backup _______________________________________ 184 Minimally logged operations_________________________________________ 184 Performing Log Restores _______________________________________________ 187 GUI-based log restore ______________________________________________ 188 T-SQL point-in-time restores ________________________________________ 194 Possible diculties with point-in-time restores __________________________ 198 Forcing Restore Failures for Fun ________________________________________ 200 Summary __________________________________________________________ 204 Chapter 7: Dierential Backup and Restore ______________ 205 Differential Backups, Overview ________________________________________ 206 Advantages of differential backups ____________________________________207 Differential backup strategies _______________________________________ 208 Possible issues with differential backups _______________________________ 212 Differentials in the backup and restore SLA _____________________________ 215 Preparing for Differential Backups _______________________________________ 216 Recovery model ___________________________________________________ 216 Sample database and tables plus initial data load _________________________ 217 Base backup ______________________________________________________ 218 Taking Differential Backups ____________________________________________ 218 Native GUI differential backup _______________________________________ 219 Native T-SQL differential backup _____________________________________ 221 Compressed differential backups _____________________________________ 223 Performing Differential Backup Restores __________________________________ 225 Native GUI differential restore _______________________________________ 225 Native T-SQL differential restore _____________________________________227 Restoring compressed differential backups _____________________________230 Forcing Failures for Fun ________________________________________________ 231 Missing the base __________________________________________________ 231 Running to the wrong base __________________________________________ 232 Recovered, already _________________________________________________ 235 Summary ___________________________________________________________ 237 Chapter 8: Database Backup and Restore with SQL Backup Pro 238 Preparing for Backups _________________________________________________ 238 Full Backups _________________________________________________________ 241 SQL Backup Pro full backup GUI method ______________________________ 241 SQL Backup Pro full backup using T-SQL ______________________________ 253 Log Backups _________________________________________________________ 256 Preparing for log backups ___________________________________________ 256 SQL Backup Pro log backups ________________________________________ 258 Differential Backups __________________________________________________ 261 Building a reusable and schedulable backup script __________________________ 263 Restoring Database Backups with SQL Backup Pro _________________________267 Preparing for restore _______________________________________________267 SQL Backup Pro GUI restore to the end of a log backup ___________________269 SQL Backup Pro T-SQL complete restore ______________________________ 277 SQL Backup Pro point-in-time restore to standby________________________279 Restore metrics: native vs. SQL Backup Pro _____________________________ 289 Verifying Backups ____________________________________________________ 291 Backup Optimization _________________________________________________292 Summary ___________________________________________________________294 Chapter 9: File and Filegroup Backup and Restore _________ 295 Advantages of File Backup and Restore __________________________________ 296 Common Filegroup Architectures _______________________________________298 File Backup __________________________________________________________ 303 Preparing for file backups ___________________________________________306 SSMS native full file backups ________________________________________309 Native T-SQL file differential backup __________________________________ 310 SQL Backup Pro file backups ________________________________________ 314 File Restore __________________________________________________________ 318 Performing a complete restore (native T-SQL) ___________________________ 321 Restoring to a point in time (native T-SQL) _____________________________ 326 Restoring after loss of a secondary data file _____________________________ 328 Quick recovery using online piecemeal restore __________________________ 335 Common Issues with File Backup and Restore _____________________________340 File Backup and Restore SLA ____________________________________________ 341 Forcing Failures for Fun ________________________________________________ 343 Summary ___________________________________________________________346 Chapter 10: Partial Backup and Restore _________________ 348 Why Partial Backups? _________________________________________________349 Performing Partial Database Backups _____________________________________ 350 Preparing for partial backups ________________________________________ 351 Partial database backup using T-SQL __________________________________ 354 Differential partial backup using T-SQL ________________________________ 355 Performing Partial Database Restores ____________________________________ 357 Restoring a full partial backup _______________________________________ 357 Restoring a differential partial backup _________________________________ 359 Special case partial backup restore ____________________________________360 SQL Backup Pro Partial Backup and Restore _______________________________ 362 Possible Issues with Partial Backup and Restore ____________________________364 Partial Backups and Restores in the SLA __________________________________ 365 Forcing Failures for Fun ________________________________________________366 Summary ___________________________________________________________ 367 Appendix A: SQL Backup Pro Installation and Configuration 368 SQL Backup Pro GUI Installation ________________________________________ 368 SQL Backup Pro Services Installation ____________________________________370 SQL Backup Pro Configuration _________________________________________376 File management __________________________________________________ 376 Email settings _____________________________________________________ 378 [...]... planning a backup and recovery strategy, from choosing and configuring hardware, gathering and documenting the requirements for each database, selecting the appropriate backup tool, scheduling considerations, running backup verification checks, and more Basic backup and restore – how to capture and restore all of the basic backup types, using SSMS and T -SQL • Chapters 3 and 4 cover how to take standard and. .. strategy Advanced backup and restore – how to capture and restore file and filegroup backups, and partial database backups • Chapter 9 – arguably the most advanced chapter in the book, explaining the filegroup architectures that enable file-based backup and restore, and the complex process of capturing the necessary file backups and transaction log backups, and using them in various restore operations... database backups, and restore them 16 Introduction • Chapters 5 and 6 cover how to take transaction log backups, and then use them in conjunction with a full database backup to restore a database to a particular point in time They also cover common transaction log problems and how to resolve them • Chapter 7 covers standard and compressed differential database backup and restore Basic backup and restore. .. this book were tested on SQL Server 2008 and SQL Server 2008 R2 Standard Edition, with the exception of the online piecemeal restore in Chapter 9, which requires Enterprise Edition Red Gate SQL Backup v.6.4.056 was used in all SQL Backup examples, in Chapters 8 and 9 of this book 18 Chapter 1: Basics of Backup and Restore Before we dive into the mechanisms for taking and restoring backups, we need to start... primary and secondary files and filegroups, plus log files • how SQL Server uses the transaction log – and its significance in regard to restore capabilities • possible types of SQL Server backup – full and differential database backups, transaction log backups and file backups • SQL Server database recovery models – the available recovery models and what they mean in terms of backups • restoring databases... restore with SQL Backup – how to capture and restore all basic backup types using Red Gate SQL Backup • Chapter 8 – third-party tools such as Red Gate SQL backup aren't free, but they do offer numerous advantages in terms of the ease with which all the basic backups can be captured, automated, and then restored Many organizations, including my own, rely on such tools for their overall backup and restore. .. to start planning a Backup and Restore SLA from scratch, even in a moderately-sized environment, and I hope this book helps you get a good start 15 Introduction How the book is structured In this book, you'll discover how to perform each of these backup and restore operations using SQL Server Management Studio (SSMS), basic T -SQL scripts and Red Gate's SQL Backup tool Capturing backups using SSMS or... can, and generally should, be backed up as part of your database backup and recovery strategy This includes both user and system databases There are three broad categories of backup that a DBA can perform: database backups, file backups and transaction log backups, and within these categories several different types of backup are available • Database backups – copy into a backup file the data and objects... prerequisite and basic sections will be a very worthwhile task Software Requirements and Code Examples Throughout this book are scripts demonstrating various ways to take and restore backups, using either native T -SQL or SQL Backup scripts All the code you need to try out the examples in this book can be obtained from the following URL: www.simple-talk.com/RedGateBooks/ShawnMcGehee/SQLServerBackupAndRestore_Code.zip... types of database restore, plus special restores, such as system database restores 19 Chapter 1: Basics of Backup and Restore Components of a SQL Server Database Ultimately, a relational database is simply a set of files that store data When we make backups of these files, we capture the objects and data within those files and store them in a backup file So, put simply, a database backup is just a copy . compressed differential database backup and restore. Basic backup and restore with SQL Backup – how to capture and restore all basic backup types using Red Gate SQL Backup. • Chapter 8 – third-party. running backup verification checks, and more. Basic backup and restore – how to capture and restore all of the basic backup types, using SSMS and T -SQL. • Chapters 3 and 4 cover how to take standard. such tools for their overall backup and restore strategy. Advanced backup and restore – how to capture and restore file and filegroup backups, and partial database backups. • Chapter 9 – arguably

Ngày đăng: 28/06/2014, 15:20

TỪ KHÓA LIÊN QUAN

w