Backing up related scripts

Source: Internet
Author: User

Original: Backing up related scripts

--View backup information within one week:

SELECT     CONVERT (CHAR (+), 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, Case    msdb. Backupset.type when '         D ' and ' the Database ' when         ' L ' Then ' Log '     END as Backup_type,     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 joins 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 ()-7)  ORDER     by Msdb.dbo.backupset.database_name,    msdb.dbo.backupset.backup_finish_date

--recent backup of each library:

---------------------------------------------------------------------------------------------most recent Database Backup for each database--------------------------------------------------------------------------------- ----------SELECT     CONVERT (CHAR (+), 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  ORDER by     Msdb.dbo.backupset.database_ Name

--Details of each library's most recent backup:

---------------------------------------------------------------------------------------------most recent Database Backup for each database-detailed------------------------------------------------------------------------ -------------------SELECT A.[server], a.last_db_backup_date, B.backup_start_date, B.expiration_date, B    . Backup_size, B.logical_device_name, B.physical_device_name, B.backupset_name, b.description from (         SELECT CONVERT (CHAR (+), 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 J OIN 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 (+), serverproperty (' Servername '))As Server, Msdb.dbo.backupset.database_name, Msdb.dbo.backupset.backup_start_date, Msdb.dbo.backupset.backup_fi Nish_date, Msdb.dbo.backupset.expiration_date, Msdb.dbo.backupset.backup_size, Msdb.dbo.backupmediafamily.logica L_device_name, Msdb.dbo.backupmediafamily.physical_device_name, msdb.dbo.backupset.name as Backupset_name, MSD B.dbo.backupset.description from msdb.dbo.backupmediafamily INNER joins Msdb.dbo.backupset on Msdb.dbo.backupmediafam ily.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_back Up_date] = b.[backup_finish_date] ORDER by A.database_name

--a database that has not been fully backed up in the last 24 hours:

---------------------------------------------------------------------------------------------Databases Missing A Data (aka Full) back-up within past Hours------------------------------------------------------------------------- --------------------Databases with data backup over hours old SELECT CONVERT (CHAR (+), serverproperty (' Servername '    )) as Server, Msdb.dbo.backupset.database_name, MAX (msdb.dbo.backupset.backup_finish_date) as Last_db_backup_date, DATEDIFF (hh, MAX (msdb.dbo.backupset.backup_finish_date), GETDATE ()) As [Backup Age (Hours)] from Msdb.dbo.backupset W Here Msdb.dbo.backupset.type = ' D ' GROUP by Msdb.dbo.backupset.database_name have (MAX (msdb.dbo.backupset.back Up_finish_date) < DATEADD (hh,-GETDATE ())) UNION--databases without any backup history SELECT CONVERT (C HAR (+), serverproperty (' Servername ')) as Server, Master.dbo.sysdatabases.NAME as database_name, NULL as [last Da Ta backup Date], 9999 as [Backup Age (Hours)] from master.dbo.sysdatabases left JOIN msdb.dbo.backupset on master.dbo.sysdatabases.name = msdb . Dbo.backupset.database_name WHERE Msdb.dbo.backupset.database_name is NULL and Master.dbo.sysdatabases.name <> ' tempdb ' ORDER by msdb.dbo.backupset.database_name


Backing up related scripts

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.