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

Brad’s Sure Guide to SQL Server Maintenance Plans- P36 doc

5 134 0

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

THÔNG TIN TÀI LIỆU

Nội dung

Chapter 15: Maintenance Cleanup Task 176 SQL Server instances as often as transaction log backups are made. This way, should your server have a complete disk failure, you will have a full backup, along with the most recent transaction log backups, ready to be restored to a new server. The Maintenance Cleanup task within the Maintenance Plan Wizard is designed to remove older files that have been safely copied to a separate offsite location, and which you no longer need to store locally. However, the task doesn't work quite as you might hope or expect. While it has the ability to delete older report text files (files with a TXT extension), full and differential backups files (files with a BAK extension), and transaction log backup files (files with a TRN extension), this task can only delete one of these file types at a time, from within a single Maintenance Plan created with the Maintenance Plan Wizard. Again, this limitation arises because the Wizard is unable to create multiple tasks within the same Maintenance Plan. So, while ideally you'd like to clean up all these older files at once as part of a single Maintenance Plan, you can't, so you will need to find alternative ways to deal with this problem. While there are several different options you can choose, here's what I recommend. First, within your central Maintenance Plan, use the Maintenance Cleanup task to delete the older report text files. Then, in order to remove the older BAK and TRN files, you have the options below. • Create two additional Maintenance Plans using the Maintenance Plan Wizard, with one plan used exclusively for deleting older BAK files, and another plan used exclusively for deleting older TRN files. This requires you to create two additional Maintenance Plans, but it works well, especially if you are not familiar with T-SQL. • Use the Maintenance Plan Designer to devise a single Maintenance Plan that will remove all three types of older files in one go. I explain how to do this, starting in Chapter 16. • Script a job to delete the older BAK and TRN files, using some other tool, such as T-SQL, PowerShell, Command Prompt commands (like delete), or third-party programs that can be used to manage files on a file system. How to do this is beyond the scope of this book, but there are a lot of alternative ways of automatically deleting files from disk. When you run the Maintenance Cleanup task, using its default settings, to delete Maintenance Plan report text files, it executes the following T-SQL code: EXECUTE master.dbo.xp_delete_file 1,N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\Log',N'txt',N'2009-07- 23T12:55:05' Chapter 15: Maintenance Cleanup Task 177 As you can see, the T-SQL executes the xp_delete_file system stored procedure with a variety of parameters. The xp_delete_file system stored procedure… … can only delete Maintenance Plan report text files and native backup BAK and TRN files. If you want to delete other files, you will have to look for another option. Learn more about this system stored procedure in Books Online. The text report for this task looks as follows: Microsoft(R) Server Maintenance Utility (Unicode) Version 10.0.2531 Report was generated on "HAWAII." Maintenance Plan: User Databases Maintenance Plan Duration: 00:00:00 Status: Succeeded. Details: Maintenance Cleanup Task (HAWAII) Maintenance Cleanup on Local server connection Cleanup Maintenance Plan report files Age: Older than 4 Weeks Task start: 2009-08-20T12:57:32. Task end: 2009-08-20T12:57:32. Success Command: EXECUTE master.dbo.xp_delete_file 1,N''C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\ Log'',N''txt'',N''2009-07-23T12:57:32'' GO It is a very simple report and is never longer than what you see here, because it can only delete one type of file at a time. Chapter 15: Maintenance Cleanup Task 178 When and How Often to Clean Up Your Backup and Report Files The Maintenance Cleanup job is generally quite lightweight, requiring few server resources, so you can schedule it to run most any time you want. The more important decision to be made concerns how long you want to keep copies of these files on the local server, and so what constitutes "old." If you create backups on a local drive, and then immediately copy them off onto another server or to tape, then you may not need to keep backups stored on the local server for very long. Generally, I like to keep one to three days of backups locally, but how many you can keep will depend on your available disk space. If you are using report text files for maintenance job troubleshooting, they probably aren't very useful after a week, as new ones are being created all the time that are more current, and probably more useful when it comes to troubleshooting problems. As the DBA, you will need to determine how long you should keep these files available on your SQL Server before deleting them. Configuring the Maintenance Cleanup Task Now that we have a better understanding of what the Maintenance Cleanup Task can and cannot do, let's take a look at the Define Maintenance Cleanup Task screen, shown in Figure 15.1. Some options on this screen are a little misleading, so I need to walk you through it, one step at a time. Chapter 15: Maintenance Cleanup Task 179 Figure 15.1: You can only delete one type of file at a time using the Maintenance Cleanup Task. Chapter 15: Maintenance Cleanup Task 180 Specifying the type of file to delete The first decision you have to make is which type of file to delete, as shown in Figure 15.2. Figure 15.2: The names used here can be somewhat deceptive. With the Delete files of the following type option, you have two choices. • Backup files: This choice has a very deceptive name. It gives the impression that, if you select this option, you can delete both BAK and TRN files at the same time. Or at least, that is the impression I get from it. But this is not the case. What it really means is that, if you select this option, you can delete either BAK or TRN files, but not both. More on this in a moment. • Maintenance Plan text reports: This option is more straightforward. If you select it, then you can delete Maintenance Plan text reports. If this option were better designed, it would allow us to choose multiple options here, specifying either BAK files, TRN files, or TXT files in a single step but, unfortunately, that is not the way it is designed. Specifying File Location The next step is to specify the location of the file or, more commonly, files that you wish to remove, as shown in Figure 15.3. Under File location you have two more choices. The first is to Delete specific file. This option allows you to select a single, specific file on disk, using the browse button to point to its location. I am not sure why you would choose this option, as virtually every BAK, TRN, and TXT file has a different name, so this option would only be useful if you wanted to delete the exact same filename each time this task runs. This would be a rare thing to want to do, but the option is available. . settings, to delete Maintenance Plan report text files, it executes the following T -SQL code: EXECUTE master.dbo.xp_delete_file 1,N'C:Program FilesMicrosoft SQL Server MSSQL10.MSSQLSERVERMSSQLLog',N'txt',N'2009-07- 23T12:55:05' Chapter. log backups, ready to be restored to a new server. The Maintenance Cleanup task within the Maintenance Plan Wizard is designed to remove older files that have been safely copied to a separate offsite. immediately copy them off onto another server or to tape, then you may not need to keep backups stored on the local server for very long. Generally, I like to keep one to three days of backups

Ngày đăng: 04/07/2014, 23:20

TỪ KHÓA LIÊN QUAN