sqlserver analysis serivce命令自动备份cube和tsql自动备份job执行日志

sqlserver analysis serivce命令自动备份cube和t-sql自动备份job执行日志

Analysis Services 执行 DDL 任务  自动备份cube

选中要备份的cube,右键 - 备份 :把路径什么的都填好,在这个对话框的左上角有一个“脚本”,点击后会生成如下下的xml格式的代码。
<Backup xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">
  <Object>
    <DatabaseID>HNA_CUBE_PRE_LINE</DatabaseID>
  </Object>
  <File>D:\文件名.abf</File>
  <AllowOverwrite>true</AllowOverwrite>
</Backup>


Analysis Services 执行 DDL 任务   自动恢复cube
<Restore xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">
  <File>路径\文件名.abf</File>
  <DatabaseName>库名</DatabaseName>
  <AllowOverwrite>true</AllowOverwrite>
</Restore>

导出(t-sql自动备份job执行日志)

在master的数据库下执行这段脚本。(方便,在job那边也有一个选数据库的下拉框,它默认是的master。)

下面的是查询当天的job执行日志记录。这个是在sql2008里面执行的。有date类型。

但在sql2005里面没得date类型。可以把文章中标黄的换成:convert(varchar(12) , getdate(), 23 )  即可。

它是用来标明查访数据是哪一天的。和日志表的run_date的数据做匹配。eg:2011-08-25

if OBJECT_ID(N'Tbl1',N'U') is not null drop table Tbl1
go
create table Tbl1( ErrorMessage nvarchar(max) )
go
declare
  @date varchar(50),
  @sql varchar(200),
  @IntPar int;
declare
  @table table (ErrorMessage nvarchar(max))
select @date=convert(varchar(10),getdate(),120),@IntPar=cast(replace(convert(date,getdate()),'-','') as int);
insert into Tbl1  
 select
'Step_Name:'+step_name ,
'Run_Date:'+(left(left(run_date,4)+'-'+right(run_date,4),7)+'-'+right(run_date,2)) as run_date,
'Run_Duration:'+(left(left(left('000000',6-len(run_duration))+ltrim(run_duration),2)+':'+right(left('000000',6-len(run_duration))+ltrim(run_duration),4),5)+':'+right(left('000000',6-len(run_duration))+ltrim(run_duration),2)) as Run_Duration,
'Run_States:'+(case  run_status
when 0 then '失败'
when 1 then '成功'
when 2 then '重试'
when 3 then '已取消'
when 4 then '正在进行中' end) as run_status,
'Message:'+a.message 
 from msdb.dbo.sysjobhistory a
 left join msdb.dbo.sysjobs b
 on a.job_id=b.job_id
--where b.name='pbcube9090Dim'
where b.name in
('pbcube9090Dim' ,'pbcube9090dimCustomer','pbcube9090dimCustomerRC','pgcube9090fVisit' )
and run_date= @IntPar
 set @sql='bcp Tbl1 out c:\'+@date+'.txt -c -S数据库实例名 -U用户 -P密码';
 print @sql
 EXEC master..xp_cmdshell @sql

 效果图:

sqlserver2008的cmdshell:打开sqlserver数据库,右键 - 方面(face) - 方面:外围应用配置器 - 属性 :xpcmdshellEnable 为true 即可。

sqlserver2005的cmdshell: 打开sqlserver外围应用配置器 - 功能的外围应用配置器 - datebase Engine - xp_cmdshell - 点击启用 即可。

我们用windows任务 也能做执行更新包的步骤:

新建一个execDtsx.bat的文件,用文本方式打开,编辑如下:

cd C:\Program Files\Microsoft SQL Server\90\DTS\Binn
dtexec /file "d:\Package.dtsx"> c:\testlog.log

然后在windows任务中新建一个任务。设置执行执行时间等等。

SQL Server 2008 数据库邮件,发送job日志 

原文地址:https://www.cnblogs.com/emmy/p/2132535.html