SQL Server - Differential backup problem

Asked By JJ
07-Mar-07 09:09 AM
SQL Server 2005 express.

To automate the backup process, I am using SQLCMD along with windows
schedulers to do log/differential/full backup.  At 12:00 AM, I do full
backup, differential backup at every 4 hours (excluding 12:00 am when I do
full backup), and log backup every 30 minutes.

Everything works fine (both full and log backup) but the problem is that
when differential backup happens (say 12:00 pm), I am getting the error

Msg 3035, Level 16, State 1, Line 1
Cannot perform a differential backup for database "testdatabase", because a
current database backup does not exist. Perform a full database backup by
reissuing BACKUP DATABASE, omitting the WITH DIFFERENTIAL option.
Msg 3013, Level 16, State 1, Line 1
BACKUP DATABASE is terminating abnormally

I think the database is thinking that I am doing the differential backup
without doing the full backup first.  However, full backup was succeeded at
12:00 am.....
If I manually do the full backup, say 2:00 pm, then the scheduled
differential backup succeeds at 4:00 pm, 8:00 pm, but fails 4:00 am onward.

What is the problem?  Any help would be appreciated.
Thanks
Backup
(1)
SQL Server
(1)
CREATE PROCEDURE
(1)
Database
(1)
Smalldatetime
(1)
Every
(1)
Operation
(1)
Databases
(1)
  AlejandroMes replied...
07-Mar-07 09:42 AM
JJ,

Can you post the scripts being used?


Thanks,

AMB
  Uri Dimant replied...
07-Mar-07 09:44 AM
JJ
What if you add a second step to the job which does FULL backup database to
do DIFFERENTIAL database backup.
  JJ replied...
07-Mar-07 09:57 AM
SQLCMD uses the following script

USE BackupDatabase

DECLARE @Hour INT
DECLARE @Minute INT
DECLARE @Date SMALLDATETIME
SET @Date = GETDATE()
SET @Hour = DATEPART (HOUR , @Date)
SET @Minute = DATEPART (MINUTE , @Date)

-- We need to either do FULL or DIFFERENTIAL Backups
IF (@Hour % 4) = 0 AND @Minute = 0
BEGIN
-- IF 12:00 AM, then we do full backup
IF @Hour = 0
BEGIN
-- FULL BACKUP
EXEC dbo.usp_BackupDatabase 'test', 1
EXEC dbo.usp_BackupDatabase 'test2', 1
EXEC dbo.usp_BackupDatabase 'master', 1
EXEC dbo.usp_BackupDatabase 'BackupDatabase', 1
END
ELSE
BEGIN
-- DIFFERENTIAL BACKUP
EXEC dbo.usp_BackupDatabase 'test', 2
EXEC dbo.usp_BackupDatabase 'test2', 2
END
END
ELSE
BEGIN
-- LOG BACKUP
EXEC dbo.usp_BackupDatabase 'test, 3
EXEC dbo.usp_BackupDatabase 'test2', 3
END


and the stored procedures

CREATE PROCEDURE [dbo].[usp_BackupDatabase]
(

@DatabaseName VARCHAR(50),

@BackupMode TINYINT -- 1 FULL, 2 Differential 3 Log

)

AS

BEGIN

SET NOCOUNT ON;

DECLARE @BackupCommand AS NVARCHAR(1000)

DECLARE @FileName AS NVARCHAR(100)

IF @BackupMode = 1

BEGIN

SET @FileName = '''C:\SQL2005Backups\'+ @DatabaseName + '\Full'+
LEFT(REPLACE(CONVERT(VARCHAR(25), GETDATE(),108), ':', ''), 4) + '.BAK'''

SET @BackupCommand = 'BACKUP DATABASE ' + @DatabaseName + ' TO DISK = ' +
@FileName + ' WITH INIT, NOSKIP'

END

IF @BackupMode = 2

BEGIN

SET @FileName = '''C:\SQL2005Backups\'+ @DatabaseName + '\Differential'+
LEFT(REPLACE(CONVERT(VARCHAR(25), GETDATE(),108), ':', ''), 4) + '.BAK'''

SET @BackupCommand = 'BACKUP DATABASE ' + @DatabaseName + ' TO DISK = ' +
@FileName + ' WITH DIFFERENTIAL, INIT, NOSKIP'

END

IF @BackupMode = 3

BEGIN

SET @FileName = '''C:\SQL2005Backups\'+ @DatabaseName + '\Log'+
LEFT(REPLACE(CONVERT(VARCHAR(25), GETDATE(),108), ':', ''), 4) + '.BAK'''

SET @BackupCommand = 'BACKUP LOG ' + @DatabaseName + ' TO DISK = ' +
@FileName + ' WITH INIT, NOSKIP'

END


--PRINT @BackupCommand

EXECUTE sp_executesql @BackupCommand

END
  JJ replied...
07-Mar-07 11:45 AM
If that is the case, then what is the point of doing the differential
backup?
Thanks
  AlejandroMes replied...
07-Mar-07 12:34 PM
JJ,

Be sure that the full backup is being created. You are casting datetime data
type to smalldatetime when assigning GETDATE() to your smalldatetime
variable. If that assignment occurs beyond '??:00:29.998', @Minute will be 1
and you can miss the full or the differential backup.

declare @Date smalldatetime

set @Date = '2007-03-07T00:00:29.999'

select
DATEPART (HOUR , @Date) as [Hour],
DATEPART (MINUTE , @Date) as [Minute]
go


AMB
  AlejandroMes replied...
07-Mar-07 12:34 PM
JJ,

So, based in this script, at 12:00 pm the differential backup for databases
[test] and [test2] would fail, correct?

When you got the error, did you check the existence of the full backupset
using "restore headeronly" on the related backup file?


AMB
  Uri Dimant replied...
08-Mar-07 02:32 AM
JJ
http://vyaskn.tripod.com/sql_server_administration_best_practices.htm#Step1
--administaiting best practices
  alex vi replied...
12-Nov-08 11:40 PM
JJ, I'm having exactly the same problem. The full backup is definitely present on the device, it still can be seen after those buggy errors. After some point SQL Server 2005 Std edition just stops adding differential backups to the backup device, the "media content" of the backup device shows it and all subsequent differential backups that it was able to add to the device. However when SQL Server 2005 aborts the operation (when telling you that the full database doesn't exist), it for some buggy reason appends to msdb.dbo.backupset table (Backup history) a record telling it that it had made an [unsuccessfull] full (type='D') backup of the database, size 8KB, is_snapshot=1 (???), flags=514 which probably makes it believing that there was no last successfull full database backup, according to the backup history. While, specifically repeating this for Americans, there IS a full database backup on the same media.



No idea why it's doing this.










SQL Server 2005 express.



To automate the backup process, I am using SQLCMD along with windows

schedulers to do log/differential/full backup.  At 12:00 AM, I do full

backup, differential backup at every 4 hours (excluding 12:00 am when I do

full backup), and log backup every 30 minutes.



Everything works fine (both full and log backup) but the problem is that

when differential backup happens (say 12:00 pm), I am getting the error



Msg 3035, Level 16, State 1, Line 1

Cannot perform a differential backup for database "testdatabase", because a

current database backup does not exist. Perform a full database backup by

reissuing BACKUP DATABASE, omitting the WITH DIFFERENTIAL option.

Msg 3013, Level 16, State 1, Line 1

BACKUP DATABASE is terminating abnormally
  Tibor Karaszi replied...
13-Nov-08 02:50 AM
Stop the SQL Server VSS writer service. (If I understood your
problems...)

--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
  Vanessa Wang replied to JJ
18-Aug-11 05:44 AM
Hey.

I just find a news about differential backup for SQL and exchange: http://www.todo-backup.com/company/news/2011-08-0811-001.htm

Any help?
  Andrew Morton replied to Vanessa Wang
18-Aug-11 06:19 AM
That might have been helpful *four years ago*.

--
Andrew
  rpresser replied to Andrew Morton
19-Aug-11 03:05 PM
it is a rather naive spammer, trying to drum up noise about their backup product by posting on an old thread about backup. Your scorn on their lack of timeliness is wasted.
help
Cannot restart SQL Server service SQL Server I recently installed SQL Server 2008 Express Edition with Advanced Tools. This is the version information from SQL Server Management Studio Microsoft SQL Server Management Studio 10.0.1600.22 ((SQL_PreRelease).080709- 1414 ) Microsoft
MSDE on Windows 2003 R2 box, new DL385G6 - Install Fails during SQL Services SQL Server I have been finding that I am having trouble with the Crystal Reports Server XI installation failing when it is dealing with SQL. So, as a thought and in case there was something wrong with my SQL portion of the isntall. I thought ok, I will try installing the actual MSDE application direct from Microsoft. So, I downloaded the MSDE for SQL 2000 (which is msde2000a.exe), set my switches and off to the races. It quit seconds left to the installation and bombed with the same errors as the Crystal Reports Server install. The error is the same whether I try to install MSDE by itself or
sql server stop working SQL Server my sql2000sp4 on winsbs2k3 stoped working due to error access is denied (error 5). It worked well during two years until yesterday. any ideas? sql service manager starts with domain / administrator. SQL Server Discussions SQL Server 2000 (1) Stored procedure (1) Errorlog (1) Backup (1) Class (1) Lock (1) Date
Requesting Backup / Restore Theory Explanation SQL Server MSSQL backups are odd in that the data and transaction logs are two different backup operations it seems. Normally, when a backup is performed, the data and log file can be archived at exactly the same time as the archived one except there are no transactions in the transaction log. If a database must be restored, the transaction file in the live area or its mirror is exported to an SQL file, and the previous backup data and transaction file is moved to the live area, and the SQL file is
Why am I getting this error in my stored procedure SQL Server Why am I getting the "Implicit conversion from data type sql_variant to int is not not when executed from the SSMS query window. Here are some facts about the stored procedure In SSMS 1.) I parses and will create 2.) It's execution statement works in the query window In SQL Server Business Intelligence Development Studio 3.) It fails in the Report Wizard after it attempts to data type nvarchar to int. - - Additional Information: - - Error converting data type nvarchar to int. (Microsoft SQL Server, Error: 8114) SQL Server will not, nor will the development environment , tell me where