首页 > 数据库 >SQLServer备份信息查看

SQLServer备份信息查看

时间:2022-10-31 11:01:55浏览次数:53  
标签:查看 dbo 备份 backupset SQLServer msdb date backup name

查看数据文件和日志文件的备份记录

SELECT [filegroup_name]
      ,[backed_up_page_count]
      ,[file_type]
      ,[file_size]
      ,[logical_name]
      ,[physical_name]
      ,[State]
      ,[state_desc]
      ,[backup_size]
      ,[differential_base_lsn]
 FROM [msdb].[dbo].[backupfile];

其中:
filegroup_name:日志文件没有文件组,故日志文件备份信息中,该列为null
file_type:D表示数据文件;L表示日志文件;F表示full-text catalog;S表示内存优化文件
State:0表示online;1表示restoring;2表示recovering;3表示recover pending;4表示suspect;6表示offline;7表示defunct;8表示dropped


备份后查看备份的逻辑和物理设备名称

select logical_device_name ,physical_device_name,device_type  FROM [msdb].[dbo].[backupmediafamily]; 

其中:
device_type:2表示磁盘;5表示磁带;7表示虚拟设备;9表示azure存储;105表示A permanent backup SQL database device

 

查看每个数据库的备份信息

select name,user_name,first_lsn,last_lsn,database_backup_lsn,backup_start_date,backup_finish_date,type,database_name,server_name,machine_name 
FROM [msdb].[dbo].[backupset];


查看最近的全备信息

SELECT  
   CONVERT(CHAR(100), SERVERPROPERTY('Servername')) AS Server, 
   msdb.dbo.backupset.database_name,  
   MAX(msdb.dbo.backupset.backup_finish_date) AS last_db_backup_date 
FROM   msdb.dbo.backupmediafamily  
   INNER JOIN msdb.dbo.backupset ON msdb.dbo.backupmediafamily.media_set_id = msdb.dbo.backupset.media_set_id  
WHERE  msdb..backupset.type = 'D' 
GROUP BY 
   msdb.dbo.backupset.database_name;

  

查看数据库的历史备份信息

SELECT 
CONVERT(CHAR(100), SERVERPROPERTY('Servername')) AS Server, 
msdb.dbo.backupset.database_name, 
msdb.dbo.backupset.backup_start_date, 
msdb.dbo.backupset.backup_finish_date, 
CASE msdb..backupset.type 
WHEN 'D' THEN 'Database' 
WHEN 'L' THEN 'Log' 
When 'I' THEN 'Differential database'
END AS backup_type, 
msdb.dbo.backupset.backup_size, 
msdb.dbo.backupmediafamily.physical_device_name, 
msdb.dbo.backupset.name AS backupset_name
FROM msdb.dbo.backupmediafamily 
INNER JOIN msdb.dbo.backupset ON msdb.dbo.backupmediafamily.media_set_id = msdb.dbo.backupset.media_set_id 
-- WHERE (CONVERT(datetime, msdb.dbo.backupset.backup_start_date, 102) >= GETDATE()-1 ) 
ORDER BY 
msdb.dbo.backupset.backup_finish_date desc

 

查看哪些数据库没有做备份

SELECT      
      S.NAME AS database_name,  
      'Nobackups' AS [Backup Age (Hours)]  
FROM 
   master.dbo.sysdatabases S LEFT JOIN msdb.dbo.backupset B
       ON S.name  = B.database_name 
WHERE B.database_name IS NULL AND S.name <> 'tempdb'
ORDER BY  
   B.database_name;


其他

SELECT  
   A.[Server],   
   A.database_name,  
   A.last_db_backup_date,  
   B.backup_start_date,    
   B.backup_finish_date, 
   B.expiration_date, 
   B.backup_size,  
   B.logical_device_name,  
   B.physical_device_name,   
   B.backupset_name, 
   B.description 
FROM 
   ( 
   SELECT   
      CONVERT(CHAR(100), SERVERPROPERTY('Servername')) AS Server, 
      msdb.dbo.backupset.database_name,  
      MAX(msdb.dbo.backupset.backup_finish_date) AS last_db_backup_date 
   FROM 
      msdb.dbo.backupmediafamily  
      INNER JOIN msdb.dbo.backupset ON msdb.dbo.backupmediafamily.media_set_id = msdb.dbo.backupset.media_set_id  
   WHERE 
      msdb..backupset.type = 'D' 
   GROUP BY 
      msdb.dbo.backupset.database_name  
   ) AS A 
   LEFT JOIN  
   ( 
   SELECT   
      CONVERT(CHAR(100), SERVERPROPERTY('Servername')) AS Server, 
      msdb.dbo.backupset.database_name,  
      msdb.dbo.backupset.backup_start_date,  
      msdb.dbo.backupset.backup_finish_date, 
      msdb.dbo.backupset.expiration_date, 
      msdb.dbo.backupset.backup_size,  
      msdb.dbo.backupmediafamily.logical_device_name,  
      msdb.dbo.backupmediafamily.physical_device_name,   
      msdb.dbo.backupset.name AS backupset_name, 
      msdb.dbo.backupset.description 
   FROM 
      msdb.dbo.backupmediafamily  
      INNER JOIN msdb.dbo.backupset ON msdb.dbo.backupmediafamily.media_set_id = msdb.dbo.backupset.media_set_id  
   WHERE 
      msdb..backupset.type = 'D' 
   ) AS B 
   ON A.[server] = B.[server] AND A.[database_name] = B.[database_name] AND A.[last_db_backup_date] = B.[backup_finish_date] 
ORDER BY  
   A.database_name 

  

 

 

 

标签:查看,dbo,备份,backupset,SQLServer,msdb,date,backup,name
From: https://www.cnblogs.com/abclife/p/16843582.html

相关文章

  • Window查看端口是否被占用
    Windowscmd命令行窗口下类似命令netstat-aon|findstr“端口号”netstat-aon|findstr"8080"或tasklist|findstr“端口号”taskkill/m/f“应用程序名”–杀掉......
  • git 查看项目成员代码提交行数和次数统计
    在实际开发中,常常会想查看自己对于某个项目的贡献,管理者会查看项目下各成员的贡献,就需要使用到git的命令进行代码提交的统计。查看个人提交的代码行数统计gitlog--au......
  • 6.查看我的动态
    查看我的动态一、MovementsController/***查看我的动态:*请求路径:/movements/all*请求方式:get*请求参数:page,当前页码;pagesize,每页显示数;use......
  • 查看 MySQL 数据库文件储存位置
    #1.登录MySQLmysql-uroot-pEnterpassword:***#2.输入下面命令mysql>showglobalvariableslike"%datadir%";+---------------+------------------------......
  • 备份rdb脚本
    #!/bin/bash#BACKUP=/data/redis-rdbDIR=/apps/redis/dump/FILE=dump.rdb#PASS=123456color(){RES_COL=60MOVE_TO_COL="echo-en\\033[${RES_COL}G"SETCOLOR......
  • 快读《ASP.NET Core技术内幕与项目实战》EFCore2.7:杂项(查看SQL、查询筛选器、原生SQL
    本节内容,涉及4.5(P96-P97)、5.2(P131-P141)。主要NuGet包:如前章节所述 一、查看SQL语句,调试LINQ语句//在DbContext类的OnConfiguring方式中,增加显示SQL的配置。即可在控制......
  • git查看当前分支是基于哪个分支拉取
    命令:gitreflogshow--date=local|grep当前分支名举例:比如当前分支为develop,那么命令如下:gitreflogshow--date=local|grepdevelop查询结果如下:在最后一条记录,可......
  • SqlServer 查询数据重复
    SQLServer查询数据重复1、查询单列重复select*fromtestwherenamein(selectnamefromtestgroupbynamehavingcount(name)>1)2、查询多列重复SELECT......
  • 查看python中安装包的一些信息
    1.piplist  #列出当前环境中的所有安装包2. pipindexversionsxxx  #展示包的所有版本信息3. pipshowxxx  #展示包的当前版本的详细信息 4.pipin......
  • Docker 安装SqlServer、Mysql、MariaDB
    Docker安装SqlServer说明1.拉取镜像dockerpullmcr.microsoft.com/mssql/server:2019-latest2.运行dockerrun--namemssqlserver2019-d--restartunless-st......