SqlServer obtains the latest full backup time of the database, and sqlserver obtains

Source: Internet
Author: User

SqlServer obtains the latest full backup time of the database, and sqlserver obtains

In application scenarios, SqlServer Incremental backup is performed on the basis of full backup. If you need to recover, you also need to restore the full backup Before restoring the corresponding Incremental backup file.

For example, if you back up database A in full to generate the 1. bak file, then perform Incremental backup to generate the 2. diff file.

If 1.bakis restored and 2.diff is restored, the original data can be restored normally.

However, if another full backup is performed in this process, the restoration will fail if you want to use 1.bak + 2. diff.

Because Incremental backup is incremental for the latest full backup, we need to determine whether the time for generating the 1. bak full backup is consistent with the latest full backup time in SqlServer.

If they are inconsistent, the subsequent Incremental backup is not based on 1. bak full backup.


The command obtained is as follows:

Osql can be used for SqlServer2003 and later versions, and osql or sqlcmd can be used for SqlServer2005 and later versions (replace the $ username, $ password, $ dbname parameter in the statement by yourself)

Osql.exe/sqlcmd.exe-U $ username-P $ password-d master-Q "select max (Backup_finish_date) AS 'latest Backup date' FROM msdb .. backupset where type = 'D' and database_name = '$ dbname' group by database_name"


The returned results are as follows:



Related Article

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.