There are a lot of databases on my client's SQL server. These databases are under development, so developers can design, refactor, do data modifications and so on. There are some databases that change rarely. My client has to keep all of them safe (backed up) and spend some time managing the environment. (There is no DB administrator position at the company.) After lengthy discussion, the client has decided to use a daily full backup strategy, due to the ease of restoring.
So here is the summary of the situation:
- Number of databases can vary every day.
- Databases that were changed (meaning data and/or structure have been changed) shall be backed up.
- Databases that were not changed shall NOT be backed up.
- Solution shall not impact database structure (it's not restricted requirement)
- This "backup engine" shall work automatically.
The main problem: how to detect that a database has been changed. The first part of the problem (DDL changes) can be resolved by using DDL triggers. But the data changes (DML changes) are a problem. It is impossible to apply DML triggers to all tables of all databases to track changes (performance, management of extended objects...). The backup engine has to track all changes to mark each database as ready to backup.
Change Data Capture is a solution but it seems too heavy (it requires SQL Server Enterprise Edition as well).
Another way is to track database file changes (size or last change time), but it does not work correctly: A database can change its size when it exceeds all reserved free space and sp_spaceused is not a solution.
Tracing is a solution but it causes performance issues and requires additional management.
Are there any solutions to calculate the actual database usage size without impact on other database management objects (like statistics..)? Granted that a change to a table's data that doesn't change the table's size would not trigger (I think), but it's better than nothing. Really I am looking for a direct or indirect solution for SQL Server 2008.
Thank you for any comments, solutions, and thoughts.
Here is the solution (thanks to Marian):
Select NextLSN = MAX(fn.[Current LSN]) ,Databasename = DB_NAME() from fn_dblog(NULL, NULL) fn LEFT JOIN sys.allocation_units au ON fn.AllocUnitId = au.allocation_unit_id LEFT JOIN sys.partitions p ON p.partition_id = au.container_id LEFT JOIN sys.objects so ON so.object_id = p.object_id WHERE ( (Operation IN ('LOP_INSERT_ROWS','LOP_MODIFY_ROW', 'LOP_DELETE_ROWS','LOP_BEGIN_XACT','LOP_COMMIT_XACT') AND so.is_ms_shipped = 0) OR ([Lock Information] like '%ACQUIRE_LOCK_SCH_M OBJECT%') )