Skip to content

Posts from the ‘Database Backup’ Category

Query to find database backup time – Netezza

You can use below query to find database backup time in Netezza environment. This query will provide the database backup time (Full / Differential / User backup) for each database along with the backup start and finish time. Query will not display any data for failed database backup attempts.
Here we will query system view _v_backup_history in system database.

select DBName, OPTYPE, starttime, lastupdate, (lastupdate-starttime)/60 as DurationInMinutes from _v_backup_history
where status='COMPLETED' and DBNAME is NOT NULL
and StartTime>'2012-10-01 00:00:00'
order by DBName, starttime 

Unfortunately, we cannot retrieve the backup location as it is not stored in any system table/view in Netezza. For that we have to look into the backup log file.

Master database backup failed – Error: “ResultSet” property not set correctly

Error

Backup of master database is failing with error message: -

Executing the query "BACKUP DATABASE [master] TO DISK = N'e:\\MSSQL10.M..." failed with the following error: "Read on "e:\\MSSQL10.MSSQLSERVER\\MSSQL\\DATA\\master.mdf" failed: 1117(failed to retrieve text for this error. Reason: 1815)
BACKUP DATABASE is terminating abnormally.
10 percent processed.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.

Try to run DBCC checkdb on master DB. You will find consistency errors like: -

DBCC results for 'sys.sysprufiles'.
Msg 2533, Level 16, State 1, Line 1
Table error: page (1:73) allocated to object ID 24, index ID 1, partition ID 281474978283520, alloc unit ID 281474978283520 (type In-row data) was not seen. The page may be invalid or may have an incorrect alloc unit ID in its header.
Msg 8980, Level 16, State 1, Line 1
Table error: Object ID 24, index ID 1, partition ID 281474978283520, alloc unit ID 281474978283520 (type In-row data). Index node page (0:0), slot 0 refers to child page (1:73) and previous child (0:0), but they were not encountered.
There are 0 rows in 0 pages for object "sys.sysprufiles".
CHECKDB found 0 allocation errors and 2 consistency errors in table 'sys.sysprufiles' (object ID 24).

Resolution

Master is very rarely changed except for logins, new databases, startup stored procedures, system configuration settings, ect.

If you have a recent backup of master database then prefer restoring master databse from good backup, assuming there haven’t been any or many changes there, it will be easier to restore master.

If you see the DBCC output in details and see tha the corruption is in index id of 1 which is a clustered index which means the chances of being able to repair it with a repair_rebuild will be very small. But you can try doing this as a second option (if you don’t have backup a recent backup or many cahges were made after that backup).

Database Backups

Mapping database backup with the backup location:-

select BS.database_name,BS.backup_finish_date BackupDateTime, BS.backup_size/1024/1024 SizeInMB, BMF.physical_device_name

from dbo.backupset BS, dbo.backupmediafamily BMF

where BS.media_set_id=BMF.media_set_id and BS.type=’D’

–BS.type= D means full backup

order by BS.database_name, BS.backup_finish_date

We can use the above script for multiple purpose, like:-

1) It can be used to check backup details foe full backup, incremental backup, transaction backup, etc. Just use the appropriate backup type. Just replace BS.type with -

D = Database

I = Differential database

L = Log

F = File or filegroup

G =Differential file

P = Partial

Q = Differential partial

2) It can be helpful, when we are not able to apply t-log backup during recovery, because some one took additional t-log backup at some other location.

3) If we do not maintain database growth then we can get the backup size of the database in history and can calculate the approximate database growth.

4) We can get lots of information regarding database backups by querying dbo.backupmediafamily and dbo.backupset tables in msdb database.

Check if Backup file still exists on disk

Some time back we started getting to many sapace issues on our database servers. On analysis we found that there are multiple copies of database backup files stored in the server at different locations (most of these backups were taken as a special request or before making any changes) and no one bothered to check back if these backup files still exists or we can remove these backup files. Since, these backup files were kept at path different from where we take backup using our maintenance plan jobs, the Maintenance plan cleanup job was not able to delete these files.

To make sure this will not happen again, we have written a script which will check if any database backup file older than 7-days exists on the server. We will get a list of backup file location, associated database name and the backup time as output.

NOTE:-

1) In this script we are making use of extended stored procedure xp_fileexist which can check if file exist or not.

exec master..xp_fileexist ‘D:\sqlserver.txt’

Output is:-

File Exists     File is a Directory       Parent Directory Exists

———–       ——————-           ———————–

0                      0                                    1

(1 row(s) affected)

If “File Exists” result is 1 that mean file exists else it does not exist.

2) We will be quering to dbo.backupset and dbo.backupmediafamily system tables in MSDB database.

Script:-

 set nocount on

create table #DoFileExist (

      FileExist smallint,

      FileIsADir smallint,

      ParentDirExist smallint);

create table #FilesExists (BackupFileName varchar(1000));

declare @BackupPath varchar(1000)

declare @CheckIfFileExist varchar(1500)

declare @TheseFileExists varchar(1500)

declare @BackupFiles cursor

set @BackupFiles = cursor for

select BMF.physical_device_name from dbo.backupset BS, dbo.backupmediafamily BMF

where BS.media_set_id=BMF.media_set_id

and BS.backup_start_date < (getdate()-7)

– above condition to check backup files older than 7 days

open @BackupFiles

fetch next from @BackupFiles into @BackupPath

while @@FETCH_STATUS = 0

begin

set @CheckIfFileExist= ‘Insert into #DoFileExist exec master..xp_fileexist “‘ + @BackupPath + ‘”‘

–print @CheckIfFileExist

exec (@CheckIfFileExist)

–select * from #DoFileExist

If exists (select FileExist from #DoFileExist where FileExist = 1)

begin

set @TheseFileExists = ‘Insert into #FilesExists (BackupFileName) values (‘ + ”” + @BackupPath + ”” +’)’

–print @TheseFileExists

Exec (@TheseFileExists)

–truncate table #DoFileExist

end

–Else Begin

–truncate table #DoFileExist

–End

truncate table #DoFileExist

fetch next from @BackupFiles into @BackupPath

end

close @BackupFiles

deallocate @BackupFiles

–select * from #FilesExists

select BS.database_name, FE.BackupFileName, BS.backup_finish_date BackupDateTime from dbo.backupset BS, dbo.backupmediafamily BMF,  #FilesExists FE

where BS.media_set_id=BMF.media_set_id and BMF.physical_device_name=FE.BackupFileName

drop table #DoFileExist

drop table #FilesExists

Output will be like:-

database_name            BackupFileName                           BackupDateTime

———————-   —————–                        ——————

AdventureWorksDW2008R2   E:\New Folder\AdventureWorksDW2008R2.bak 2011-07-22 10:38:27.000