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: