博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Maintenance Plans in MS SQL 2005
阅读量:5154 次
发布时间:2019-06-13

本文共 3970 字,大约阅读时间需要 13 分钟。

Maintenance Plans in MS SQL 2005 are a powerful and easy way to manage and backup your databases. In this article, I’m going to walk through 4 basic tasks that we run weekly on a client’s database. You’ll learn how to reorganize indexes, create a full backup (*.bak), shrink your database (shrinks both data and log files), and cleanup the backup directory.

Creating a Maintenance Plan

In SQL Server Management Studio, expand the Management folder, right-click Maintenance Plans and select New Maintenance Plan…

Give the Maintenance Plan a name and click OK. The new empty Maintenance Plan will open in Design Mode. All of the available tasks are in the left hand column Toolbox under Maintenance Plan Tasks.

To add any task to the maintenance plan, simply drag the task from the Toolbox into the design frame. Once the task is in the design frame, double-click to edit.

Reorganize Index Task

The reorganize index task updates table and view indexes so the search order is more efficient. The task dialogue is pretty simple. Use the Database(s) drop down to select one or more databases. Then use the Object drop down to select whether Tables, Views, or Both should have their indexes reorganized. For this example, I’m going to reorganize both Tables and Views. When done, click OK.

Back Up Database Task

The Back Up Database Task creates a Full, Differential, or Transaction Log backup. In this example, I’m going to create a Full backup which will create a *.bak file.  This task dialogue is also pretty simple. Set the Backup type to Full and then select the Database(s) to backup. Jump down to the bottom third of the

Join the Reorganize Index Task to the Backup Database Task by dragging the green arrow between the two. Once the two tasks are joined, right-click the arrow and select Completion.

Shrink Database Task

The Shrink Database Task should come after the back up task because the shrink cannot be executed on a database until a Full backup has been created. In the task dialogue, select the Database(s) and just accept the defaults. When done, click OK. If you’ve noticed your log files getting out of hand, the shrink task will bring the file size down. In a recent test, my active log file went from over 2GB to just over 200MB.

Join the Back Up Database Task to the Shrink Database Task, and set the type to Completion.

Maintenance Cleanup Task

As the last task in the Maintenance Plan, I’m going to cleanup the backup directory by removing any *.bak files that are older than 2 weeks. If you’re doing this type of maintenance, you’ll want to make sure you’ve got some sort of server backup that keeps a longer history of your *.bak files off-server.

Open the task dialogue and skip down to the Search folder and delete files based on extension.  Navigate to the backup folder that was set in the Back Up Database Task. Then set the file extension to bak. Note the extension is simply bak. You don’t need to include a . (dot). Skip to the bottom of the dialogue and set the age of the deleted files to 2 weeks. When done, click OK.

Join the Shrink Database Task to the Maintenance Cleanup Task, and set the type to Success.

Execute the Maintenance Plan

Save the maintenance plan. From the Object Explorer, right click the new plan and select Execute to test it.  If everything runs without error, you can set the plan to run on a schedule.

On the design mode screen in the Subplan grid, click on the calendar icon and set the schedule for executing the plan. When done, click OK.

That’s it. The plan will now run as a scheduled task. Not only does the plan backup the database, but it’s also reorganizing the indexes, shrinking the database and cleaning up  the backup directory. Best of all, once it’s setup, the plan executes without your intervention and at a time that is best for your system.

 

reference:  http://www.webapper.com/blog/index.php/2009/09/10/ms-sql-maintenance-plans/

转载于:https://www.cnblogs.com/sandy_liao/archive/2010/10/12/1849258.html

你可能感兴趣的文章
暖暖的感动
查看>>
[转] C语言的谜题
查看>>
response对象的使用
查看>>
Java中的日期和时间
查看>>
禁用windows2000.2003启动时的CTRL+ALT+DEL
查看>>
Django基于admin的stark组件创建(一)
查看>>
快速幂 模板及应用
查看>>
CreateUserWizard控件的详细使用说明(4)
查看>>
养动物
查看>>
批处理/DOS命令删除文件夹下某类型的文件
查看>>
模板 - 数学 - 矩阵快速幂
查看>>
优秀的持久层框架Mybatis,连接数据库快人一步
查看>>
线段树 延迟更新
查看>>
CentOS的IP配置专题
查看>>
基于WCF大型分布式系统的架构设计
查看>>
性能测试 基于Python结合InfluxDB及Grafana图表实时采集Linux多主机性能数据
查看>>
Cisco & H3C 交换机 DHCP 中继
查看>>
人脸识别技术及应用,二次开发了解一下
查看>>
理解CSS中的BFC(块级可视化上下文)[译]
查看>>
身份证号码的合法性校验
查看>>