简体   繁体   English

在 SQL Server 2014 中备份维护计划或作业

[英]Backup a maintenance plan or job in SQL Server 2014

I have some maintenance plans in SQL Server 2014 that they do some tasks on my databases.我在 SQL Server 2014 中有一些维护计划,它们在我的数据库上执行一些任务。 I want to back up my plans to use them on different servers.我想支持我在不同服务器上使用它们的计划。

How can I back up or deploy them?如何备份或部署它们?

Jobs and maintenance plans are stored in the MSDB system database.作业和维护计划存储在 MSDB 系统数据库中。 You can backup and restore jobs and plans by backing up and restoring this database.您可以通过备份和恢复此数据库来备份和恢复作业和计划。

To deploy jobs, you generate the appropriate script and run it on the target server.要部署作业,您需要生成适当的脚本并在目标服务器上运行它。 You can generate an existing job's script by right clicking on it and selecting Script Job as > Create from the context menu.您可以通过右键单击现有作业的脚本并从上下文菜单中选择Script Job as > Create来生成该脚本。

Maintenance plans can't be scripted that easily.维护计划不能那么容易地编写脚本。 Essentially they are SSIS packages stored in MSDB.本质上,它们是存储在 MSDB 中的 SSIS 包。 You can create your own SSIS packages with the maintenance tasks you want and deploy them to a server.您可以使用所需的维护任务创建自己的 SSIS 包,并将它们部署到服务器。

Most DBAs though prefer jobs because they have the same capabilities as a maintenance plan and are far easier to script and deploy.尽管大多数 DBA 更喜欢作业,因为它们具有与维护计划相同的功能,并且更容易编写脚本和部署。

Ola Hallengren's scripts are frequently used to perform maintenance tasks like backing up multiple databases or rebuilding/reorganizing indexes automatically, using a single command. Ola Hallengren 的脚本经常用于执行维护任务,例如使用单个命令自动备份多个数据库或重建/重组索引。 For example,例如,

EXECUTE dbo.DatabaseBackup @Databases = 'USER_DATABASES',
         @Directory = 'C:\Backup',
         @BackupType = 'FULL',
         @Compress = 'Y',
         @Verify = 'Y'

Will take a full backup of all user databases with compression while将使用压缩对所有用户数据库进行完整备份,同时

EXECUTE dbo.IndexOptimize @Databases = 'USER_DATABASES',
@FragmentationLow = NULL,
@FragmentationMedium = 'INDEX_REORGANIZE,INDEX_REBUILD_ONLINE,INDEX_REBUILD_OFFLINE',
@FragmentationHigh = 'INDEX_REBUILD_ONLINE,INDEX_REBUILD_OFFLINE',
@FragmentationLevel1 = 5,
@FragmentationLevel2 = 30

Will check all indexes and decide to rebuild or reorganize indexes based on the fragmentation level将检查所有索引并根据碎片级别决定重建或重组索引

All these maintenance plans are created by developers or administrators by using below steps所有这些维护计划都是由开发人员或管理员使用以下步骤创建的

Under Management -> Maintenance Plan wizard or Maintenance Plan在管理 -> 维护计划向导或维护计划下

在此处输入图片说明

After selecting Maintenance plans by running wizard you can select what are all maintenance plans you can select as below:通过运行向导选择维护计划后,您可以选择您可以选择的所有维护计划,如下所示:

在此处输入图片说明

By selecting respective plans if you generate it will generate SQL Jobs, You can script these SQL Jobs to take the backup also you can enable and disable these jobs based on requirement.通过选择相应的计划,如果生成它将生成 SQL 作业,您可以编写这些 SQL 作业的脚本来进行备份,也可以根据需要启用和禁用这些作业。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM