Showing posts with label backup. Show all posts
Showing posts with label backup. Show all posts

Friday, March 23, 2012

Rename Database

I have a custom TFSBuild task that restores a backup of our database, runs some scripts against it, deletes the previous day's database, and the renames the new database to the same name as the one that was deleted. This has been working fine for weeks now, but started failing yesterday and also failed again today. The old database is deleted successfully, but the rename command fails.

The code that runs is:

Dim strRenameScript As String = String.Format("ALTER DATABASE {0} SET SINGLE_USER WITH ROLLBACK IMMEDIATE", _strTempDatabaseName) & Environment.NewLine & _
"GO" & Environment.NewLine & String.Format("ALTER DATABASE {0} MODIFY NAME={1}", _strTempDatabaseName, _strDatabaseName) & _
Environment.NewLine & "GO" & Environment.NewLine & String.Format("ALTER DATABASE {0} SET MULTI_USER", _strDatabaseName) & _
Environment.NewLine & "GO"

Executed using the Microsoft.SqlServer.Management.Smo classes, which is interpreted as:

ALTER DATABASE MyTempDatabase SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
ALTER DATABASE MyTempDatabase MODIFY NAME=MyLiveDatabase
GO
ALTER DATABASE MyLiveDatabase SET MULTI_USER
GO

This used to be fine, but now the batch fails after setting the database into single user mode, and the only error returned is:

An exception occurred while executing a Transact-SQL statement or batch

If I subsequently run the above script in SQLSMS it works fine. Does anyone know why this might have started failing all of a sudden?

Could you run the code below and post back the results?

Chris

SELECT *
FROM master.sys.databases
WHERE [name] IN ('MyTempDatabase', 'MyLiveDatabase')

|||

from which database context u r executing this statement... be sure that u r not connected to this particular database, in that case the connection is already broken by this statement

Madhu

|||

Madhu:
I'm connecting to the master database both when deleting the old database and when renaming the new database:

Dim cnTempDatabase As SqlConnection = New SqlConnection(String.Format(_strConnectionString, _strDatabaseServer, "Master"))
Dim sqlServer As Server = New Server(New ServerConnection(cnTempDatabase))

Chris:
I've manually renamed the database now so daily development can continue, but I get one result back for the 'live' database (what the temp one was renamed to).

I'll see if it fails again in the morning and if so I'll run the same query before doing anything and post back.

Would the error have logged any more details in the SQL Server log?

|||

OK, the statement failed again last night so I ran your query again. As expected, only the temp database (the one left in single user mode) is returned.

Would a more verbose error have been logged anywhere?

|||

if the error is not logged in SQL Server Event Log....most probably it means that the error is not occuring at the SQL Level but the Application level... capture the error from application or application log

Madhu

|||

There are lots of informational messages in the log about restoring the database, setting the old database to single user mode etc (although I note nothing about deleting it) and then the last entry is the about setting the temp database to single user mode (which happens just before the rename command):

2007-03-09 06:16:42.68 spid55 Setting database option SINGLE_USER to ON for database HighwayP2Temp20070309.

Then nothing. Yesterday (when the rename worked) there also wasn't any log entry about deleting the old database, so I guess that isn't an indicator.

Any ideas?

|||

Found more info:

If I use the full backup of our database (~70Gb) then the rename fails, unless I have restarted the SQL Server instance at some point in the day beforehand. If I use the shrunk version of our database (~1.5Gb) then the rename is always fine. Perhaps this is something to do with SQL Server memory usage? Is anyone aware of any existing issues regarding memory utilisation that may affect a rename action?

Rename Database

I have a custom TFSBuild task that restores a backup of our database, runs some scripts against it, deletes the previous day's database, and the renames the new database to the same name as the one that was deleted. This has been working fine for weeks now, but started failing yesterday and also failed again today. The old database is deleted successfully, but the rename command fails.

The code that runs is:

Dim strRenameScript AsString = String.Format("ALTER DATABASE {0} SET SINGLE_USER WITH ROLLBACK IMMEDIATE", _strTempDatabaseName) & Environment.NewLine & _
"GO" & Environment.NewLine & String.Format("ALTER DATABASE {0} MODIFY NAME={1}", _strTempDatabaseName, _strDatabaseName) & _
Environment.NewLine & "GO" & Environment.NewLine & String.Format("ALTER DATABASE {0} SET MULTI_USER", _strDatabaseName) & _
Environment.NewLine & "GO"

Executed using the Microsoft.SqlServer.Management.Smo classes, which is interpreted as:

ALTERDATABASE MyTempDatabase SET SINGLE_USER WITHROLLBACK IMMEDIATE
GO
ALTERDATABASE MyTempDatabase MODIFY NAME=MyLiveDatabase
GO
ALTERDATABASE MyLiveDatabase SET MULTI_USER
GO

This used to be fine, but now the batch fails after setting the database into single user mode, and the only error returned is:

An exception occurred while executing a Transact-SQL statement or batch

If I subsequently run the above script in SQLSMS it works fine. Does anyone know why this might have started failing all of a sudden?

Could you run the code below and post back the results?

Chris

SELECT *
FROM master.sys.databases
WHERE [name] IN ('MyTempDatabase', 'MyLiveDatabase')

|||

from which database context u r executing this statement... be sure that u r not connected to this particular database, in that case the connection is already broken by this statement

Madhu

|||

Madhu:
I'm connecting to the master database both when deleting the old database and when renaming the new database:

Dim cnTempDatabase As SqlConnection = New SqlConnection(String.Format(_strConnectionString, _strDatabaseServer, "Master"))
Dim sqlServer As Server = New Server(New ServerConnection(cnTempDatabase))

Chris:
I've manually renamed the database now so daily development can continue, but I get one result back for the 'live' database (what the temp one was renamed to).

I'll see if it fails again in the morning and if so I'll run the same query before doing anything and post back.

Would the error have logged any more details in the SQL Server log?

|||

OK, the statement failed again last night so I ran your query again. As expected, only the temp database (the one left in single user mode) is returned.

Would a more verbose error have been logged anywhere?

|||

if the error is not logged in SQL Server Event Log....most probably it means that the error is not occuring at the SQL Level but the Application level... capture the error from application or application log

Madhu

|||

There are lots of informational messages in the log about restoring the database, setting the old database to single user mode etc (although I note nothing about deleting it) and then the last entry is the about setting the temp database to single user mode (which happens just before the rename command):

2007-03-09 06:16:42.68 spid55 Setting database option SINGLE_USER to ON for database HighwayP2Temp20070309.

Then nothing. Yesterday (when the rename worked) there also wasn't any log entry about deleting the old database, so I guess that isn't an indicator.

Any ideas?

|||

Found more info:

If I use the full backup of our database (~70Gb) then the rename fails, unless I have restarted the SQL Server instance at some point in the day beforehand. If I use the shrunk version of our database (~1.5Gb) then the rename is always fine. Perhaps this is something to do with SQL Server memory usage? Is anyone aware of any existing issues regarding memory utilisation that may affect a rename action?

Tuesday, March 20, 2012

Removing un necessary log

In a production database I'm finding the log file is increasing rapidly and
after taking a backup I find the log file is still increasing fast. Since th
e database is running and highly in use in production evironment I can't use
trunc,log on chkpt option
on the database.
What should I do at this moment plz suggest me keeping in view the database
is running and production database.
Regards and thanks in advance,
Sunil DashIf the database is in Full Recovery mode, backing up the transaction log
will make space available for re-use..(But you must have done at least one
full database backup first.)
If you have long running transactions, that will prevent the transaction log
from truncating properly as well...
DBCC opentran ( in books on line) will show you the SPID of the longest
running open transaction... First find out if there is a long running
transaction and what it is..
I suggest you backup the t-log now...
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Sunil" <anonymous@.discussions.microsoft.com> wrote in message
news:C2E45928-E815-428E-836A-B13A4E080BF1@.microsoft.com...
> In a production database I'm finding the log file is increasing rapidly
and after taking a backup I find the log file is still increasing fast.
Since the database is running and highly in use in production evironment I
can't use trunc,log on chkpt option on the database.
>
> What should I do at this moment plz suggest me keeping in view the
database is running and production database.
>
> Regards and thanks in advance,
>
> Sunil Dash

Removing un necessary log

In a production database I'm finding the log file is increasing rapidly and after taking a backup I find the log file is still increasing fast. Since the database is running and highly in use in production evironment I can't use trunc,log on chkpt option
on the database.
What should I do at this moment plz suggest me keeping in view the database is running and production database.
Regards and thanks in advance,
Sunil Dash
If the database is in Full Recovery mode, backing up the transaction log
will make space available for re-use..(But you must have done at least one
full database backup first.)
If you have long running transactions, that will prevent the transaction log
from truncating properly as well...
DBCC opentran ( in books on line) will show you the SPID of the longest
running open transaction... First find out if there is a long running
transaction and what it is..
I suggest you backup the t-log now...
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Sunil" <anonymous@.discussions.microsoft.com> wrote in message
news:C2E45928-E815-428E-836A-B13A4E080BF1@.microsoft.com...
> In a production database I'm finding the log file is increasing rapidly
and after taking a backup I find the log file is still increasing fast.
Since the database is running and highly in use in production evironment I
can't use trunc,log on chkpt option on the database.
>
> What should I do at this moment plz suggest me keeping in view the
database is running and production database.
>
> Regards and thanks in advance,
>
> Sunil Dash

Removing un necessary log

In a production database I'm finding the log file is increasing rapidly and after taking a backup I find the log file is still increasing fast. Since the database is running and highly in use in production evironment I can't use trunc,log on chkpt option on the database
What should I do at this moment plz suggest me keeping in view the database is running and production database
Regards and thanks in advance
Sunil DashIf the database is in Full Recovery mode, backing up the transaction log
will make space available for re-use..(But you must have done at least one
full database backup first.)
If you have long running transactions, that will prevent the transaction log
from truncating properly as well...
DBCC opentran ( in books on line) will show you the SPID of the longest
running open transaction... First find out if there is a long running
transaction and what it is..
I suggest you backup the t-log now...
--
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Sunil" <anonymous@.discussions.microsoft.com> wrote in message
news:C2E45928-E815-428E-836A-B13A4E080BF1@.microsoft.com...
> In a production database I'm finding the log file is increasing rapidly
and after taking a backup I find the log file is still increasing fast.
Since the database is running and highly in use in production evironment I
can't use trunc,log on chkpt option on the database.
>
> What should I do at this moment plz suggest me keeping in view the
database is running and production database.
>
> Regards and thanks in advance,
>
> Sunil Dash

Removing system replication tables.

Hi, i restored a backup from a database thas has replication configured.
When i restored it the system tables that the merge replication creates
are restored too. I was investigating on internet and I found that i can
delete it using this query:
sp_configure 'allow updates', 1
go
reconfigure with override
go
DROP TABLE aonflict_SiacDataEEC_security_info
...
sp_configure 'allow updates', 0
go
reconfigure with override
go
Do somebody know if i use this queries to delete this tables i can
damage the database or is correct to use it.
Thanks a lot for your help.
*** Sent via Developersdex http://www.codecomments.com ***
Maria,
most system metadata is removed by sp_removedbreplication, but this is an
exception and it is common practice to drop these tables manually as part of
a cleanup.
HTH,
Paul Ibison SQL Server MVP, www.replicationanswers.com
(recommended sql server 2000 replication book:
http://www.nwsu.com/0974973602p.html)
|||If the database is no longer replicating then it will not damage the
database to delete the old replication objects.
In fact, if you do not delete the replication triggers you will
probably encounter problems.
|||I agree. sp_MSdroparticletriggers is called from sp_removedbreplication but
has been known to not work in rare circumstances. I have a script which
removed redundant duplicate triggers that may be of interest in these cases:
http://www.replicationanswers.com/Script8.asp
HTH
Paul Ibison SQL Server MVP, www.replicationanswers.com
(recommended sql server 2000 replication book:
http://www.nwsu.com/0974973602p.html)

Removing system replication tables.

Hi, i restored a backup from a database thas has replication configured.
When i restored it the system tables that the merge replication creates
are restored too. I was investigating on internet and I found that i can
delete it using this query:

sp_configure 'allow updates', 1
go
reconfigure with override
go

DROP TABLE aonflict_SiacDataEEC_security_info
...

sp_configure 'allow updates', 0
go
reconfigure with override
go

Do somebody know if i use this queries to delete this tables i can
damage the database or is correct to use it.

Thanks a lot for your help.

*** Sent via Developersdex http://www.developersdex.com ***You might get a better response in
microsoft.public.sqlserver.replication

Simon

Friday, March 9, 2012

Removing Older Backups?

With SQL Server 2000 I created a backup disk file (and job) for full
database backups performed daily (which are appended), and a backup disk
file (and job) for log backups performed every hour (also appended). Because
of disk space constraints (on a dedicated server), I would like to remove
older backups from each of these backup files. For example, instead of
having seven (or 180) days of full backups and seven (or 180) days of log
backups on my local disk (the server is backed up to tape nightly), I would
like to automatically keep only the last three days of full backups and only
the transaction logs that came after the first of the three full backups.
I have not discovered a way to automatically create backups as separate
file, each labeled and time-stamped that I could periodically delete, if
there is not a way to do the above with single appended files.
So, how does one extract the older backups out of these single files with
appended backups? Is there a way to configure that with EM, or does it
require SQL scripting?
Thanks for any help.Hi,
Take a look into the maintenance plan in Enterprise manager. Maintenance
plan allow you to archive the backup files
based on te frequency you provide.
Thanks
Hari
SQL Server MVP
"Don Miller" <nospam@.nospam.com> wrote in message
news:utNmj6WyGHA.2392@.TK2MSFTNGP03.phx.gbl...
> With SQL Server 2000 I created a backup disk file (and job) for full
> database backups performed daily (which are appended), and a backup disk
> file (and job) for log backups performed every hour (also appended).
> Because
> of disk space constraints (on a dedicated server), I would like to remove
> older backups from each of these backup files. For example, instead of
> having seven (or 180) days of full backups and seven (or 180) days of log
> backups on my local disk (the server is backed up to tape nightly), I
> would
> like to automatically keep only the last three days of full backups and
> only
> the transaction logs that came after the first of the three full backups.
> I have not discovered a way to automatically create backups as separate
> file, each labeled and time-stamped that I could periodically delete, if
> there is not a way to do the above with single appended files.
> So, how does one extract the older backups out of these single files with
> appended backups? Is there a way to configure that with EM, or does it
> require SQL scripting?
> Thanks for any help.
>|||Don,
You can achieve this with the Maintenance Plan wizard although it has some
limitations and not very flexible. If you want to create your own jobs you
can use this sample as a start. It shows how to generate a new file name for
each backup and a sample on how to remove older backup files as well.
-- Do a backup and create a separate file for each day of the
eek --
DECLARE @.DBName NVARCHAR(50), @.Device NVARCHAR(100), @.Name NVARCHAR(100)
IF OBJECT_ID('tempdb..#DBs') IS NOT NULL
DROP TABLE #DBs
CREATE TABLE #DBs ([name] VARCHAR(50),[db_size] VARCHAR(20),
[Owner] VARCHAR(20),[DBID] INT, [Created] VARCHAR(14),
[Status] VARCHAR(1000), [Compatibility_Level] INT)
INSERT INTO #DBs EXEC sp_helpdb
DECLARE cur_DBs CURSOR STATIC LOCAL
FOR SELECT [Name]
FROM #DBs
WHERE [DBID] IN (5,6)
OPEN cur_DBs
FETCH NEXT FROM cur_DBs INTO @.DBName
WHILE @.@.FETCH_STATUS = 0
BEGIN
SET @.Device = N'C:\Backups\DD_' + @.DBName + '_Full_' +
CAST(DAY(GETDATE()) AS NVARCHAR(4)) +
CAST(MONTH(GETDATE()) AS NVARCHAR(4)) +
CAST(YEAR(GETDATE()) AS NVARCHAR(8)) + N'.BAK'
SET @.Name = @.DBName + N' Full Backup'
BACKUP DATABASE @.DBName TO DISK = @.Device WITH INIT , NOUNLOAD ,
NAME = @.Name, NOSKIP , STATS = 10, NOFORMAT
RESTORE VERIFYONLY FROM DISK = @.Device WITH FILE = 1
FETCH NEXT FROM cur_DBs INTO @.DBName
END
CLOSE cur_DBs
DEALLOCATE cur_DBs
----
-- Removing Older Backup Files --
DECLARE @.Error INT, @.D DATETIME
SET @.D = CAST('20020801 15:00:00' AS DATETIME)
EXEC @.Error = remove_old_log_files @.D
SELECT @.Error
----
-- *** Procedure to remove old backups **** --
CREATE PROCEDURE remove_old_log_files
@.DelDate DATETIME
AS
SET NOCOUNT ON
DECLARE @.SQL VARCHAR(500), @.FName VARCHAR(40), @.Error INT
DECLARE @.Delete VARCHAR(300), @.Msg VARCHAR(100), @.Return INT
SET DATEFORMAT MDY
IF OBJECT_ID('tempdb..#dirlist') IS NOT NULL
DROP TABLE #DirList
CREATE TABLE #dirlist (FName VARCHAR(1000))
CREATE TABLE #Errors (Results VARCHAR(1000))
-- Insert the results of the dir cmd into a table so we can scan it
INSERT INTO #dirlist (FName)
exec master..xp_cmdshell 'dir /OD C:\Backups\*.trn'
SET @.Error = @.@.ERROR
IF @.Error <> 0
BEGIN
SET @.Msg = 'Error while getting the filenames with DIR '
GOTO On_Error
END
--SELECT * FROM #dirList
-- Remove the garbage
DELETE #dirlist WHERE
SUBSTRING(FName,1,2) < '00' OR
SUBSTRING(FName,1,2) > '99' OR
FName IS NULL
-- Create a cursor and for each file name do the processing.
-- The files will be processed in date order.
DECLARE curDir CURSOR READ_ONLY LOCAL
FOR
SELECT SUBSTRING(FName,40,40) AS FName
FROM #dirlist
WHERE CAST(SUBSTRING(FName,1,20) AS DATETIME) < @.DelDate
AND SUBSTRING(FName,40,40) LIKE '%.TRN'
OPEN curDir
FETCH NEXT FROM curDir INTO @.Fname
WHILE (@.@.fetch_status = 0)
BEGIN
-- Delete the old backup files
SET @.Delete = 'DEL "C:\Backups\' + @.FName + '"'
INSERT INTO #Errors (Results)
exec master..xp_cmdshell @.Delete
IF @.@.RowCount > 1
BEGIN
SET @.Error = -1
SET @.Msg = 'Error while Deleting file ' + @.FName
GOTO On_Error
END
-- PRINT @.Delete
PRINT 'Deleted ' + @.FName + ' at ' +
CONVERT(VARCHAR(28),GETDATE(),113)
FETCH NEXT FROM curDir INTO @.Fname
END
CLOSE curDir
DEALLOCATE curDir
DROP TABLE #DirList
DROP TABLE #Errors
RETURN @.Error
On_Error:
BEGIN
IF @.Error <> 0
BEGIN
SELECT @.Msg + '. Error # ' + CAST(@.Error AS VARCHAR(10))
RAISERROR(@.Msg,12,1)
RETURN @.Error
END
END
GO
Andrew J. Kelly SQL MVP
"Don Miller" <nospam@.nospam.com> wrote in message
news:utNmj6WyGHA.2392@.TK2MSFTNGP03.phx.gbl...
> With SQL Server 2000 I created a backup disk file (and job) for full
> database backups performed daily (which are appended), and a backup disk
> file (and job) for log backups performed every hour (also appended).
> Because
> of disk space constraints (on a dedicated server), I would like to remove
> older backups from each of these backup files. For example, instead of
> having seven (or 180) days of full backups and seven (or 180) days of log
> backups on my local disk (the server is backed up to tape nightly), I
> would
> like to automatically keep only the last three days of full backups and
> only
> the transaction logs that came after the first of the three full backups.
> I have not discovered a way to automatically create backups as separate
> file, each labeled and time-stamped that I could periodically delete, if
> there is not a way to do the above with single appended files.
> So, how does one extract the older backups out of these single files with
> appended backups? Is there a way to configure that with EM, or does it
> require SQL scripting?
> Thanks for any help.
>|||Thanks for the script. I'll take a close look at it.
I did experiment with the Maintenance Plan wizard and instead of appending
the backups and logs to the same file, it creates those separate
time-stamped files. I'll probably go with this because I can more easily
deal (and understand) with many time-stamped files rather than one file with
the logs and such enclosed in some proprietary manner.
I'm also looking at SQL Sentry as you suggested. Thanks.
"Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
news:OSEqsLiyGHA.3440@.TK2MSFTNGP06.phx.gbl...
> Don,
> You can achieve this with the Maintenance Plan wizard although it has some
> limitations and not very flexible. If you want to create your own jobs you
> can use this sample as a start. It shows how to generate a new file name
for
> each backup and a sample on how to remove older backup files as well.
>
> -- Do a backup and create a separate file for each day of the
> eek --
> DECLARE @.DBName NVARCHAR(50), @.Device NVARCHAR(100), @.Name NVARCHAR(100)
> IF OBJECT_ID('tempdb..#DBs') IS NOT NULL
> DROP TABLE #DBs
> CREATE TABLE #DBs ([name] VARCHAR(50),[db_size] VARCHAR(20),
> [Owner] VARCHAR(20),[DBID] INT, [Created] VARCHAR(14),
> [Status] VARCHAR(1000), [Compatibility_Level] INT)
> INSERT INTO #DBs EXEC sp_helpdb
>
> DECLARE cur_DBs CURSOR STATIC LOCAL
> FOR SELECT [Name]
> FROM #DBs
> WHERE [DBID] IN (5,6)
> OPEN cur_DBs
> FETCH NEXT FROM cur_DBs INTO @.DBName
> WHILE @.@.FETCH_STATUS = 0
> BEGIN
> SET @.Device = N'C:\Backups\DD_' + @.DBName + '_Full_' +
> CAST(DAY(GETDATE()) AS NVARCHAR(4)) +
> CAST(MONTH(GETDATE()) AS NVARCHAR(4)) +
> CAST(YEAR(GETDATE()) AS NVARCHAR(8)) + N'.BAK'
> SET @.Name = @.DBName + N' Full Backup'
> BACKUP DATABASE @.DBName TO DISK = @.Device WITH INIT , NOUNLOAD ,
> NAME = @.Name, NOSKIP , STATS = 10, NOFORMAT
> RESTORE VERIFYONLY FROM DISK = @.Device WITH FILE = 1
> FETCH NEXT FROM cur_DBs INTO @.DBName
> END
> CLOSE cur_DBs
> DEALLOCATE cur_DBs
> ----
> -- Removing Older Backup Files --
> DECLARE @.Error INT, @.D DATETIME
> SET @.D = CAST('20020801 15:00:00' AS DATETIME)
> EXEC @.Error = remove_old_log_files @.D
> SELECT @.Error
> ----
> -- *** Procedure to remove old backups **** --
> CREATE PROCEDURE remove_old_log_files
> @.DelDate DATETIME
> AS
> SET NOCOUNT ON
> DECLARE @.SQL VARCHAR(500), @.FName VARCHAR(40), @.Error INT
> DECLARE @.Delete VARCHAR(300), @.Msg VARCHAR(100), @.Return INT
> SET DATEFORMAT MDY
>
> IF OBJECT_ID('tempdb..#dirlist') IS NOT NULL
> DROP TABLE #DirList
> CREATE TABLE #dirlist (FName VARCHAR(1000))
> CREATE TABLE #Errors (Results VARCHAR(1000))
> -- Insert the results of the dir cmd into a table so we can scan it
> INSERT INTO #dirlist (FName)
> exec master..xp_cmdshell 'dir /OD C:\Backups\*.trn'
> SET @.Error = @.@.ERROR
> IF @.Error <> 0
> BEGIN
> SET @.Msg = 'Error while getting the filenames with DIR '
> GOTO On_Error
> END
> --SELECT * FROM #dirList
> -- Remove the garbage
> DELETE #dirlist WHERE
> SUBSTRING(FName,1,2) < '00' OR
> SUBSTRING(FName,1,2) > '99' OR
> FName IS NULL
>
> -- Create a cursor and for each file name do the processing.
> -- The files will be processed in date order.
> DECLARE curDir CURSOR READ_ONLY LOCAL
> FOR
> SELECT SUBSTRING(FName,40,40) AS FName
> FROM #dirlist
> WHERE CAST(SUBSTRING(FName,1,20) AS DATETIME) < @.DelDate
> AND SUBSTRING(FName,40,40) LIKE '%.TRN'
> OPEN curDir
> FETCH NEXT FROM curDir INTO @.Fname
> WHILE (@.@.fetch_status = 0)
> BEGIN
>
> -- Delete the old backup files
> SET @.Delete = 'DEL "C:\Backups\' + @.FName + '"'
> INSERT INTO #Errors (Results)
> exec master..xp_cmdshell @.Delete
>
> IF @.@.RowCount > 1
> BEGIN
> SET @.Error = -1
> SET @.Msg = 'Error while Deleting file ' + @.FName
> GOTO On_Error
> END
>
> -- PRINT @.Delete
> PRINT 'Deleted ' + @.FName + ' at ' +
> CONVERT(VARCHAR(28),GETDATE(),113)
> FETCH NEXT FROM curDir INTO @.Fname
> END
> CLOSE curDir
> DEALLOCATE curDir
> DROP TABLE #DirList
> DROP TABLE #Errors
> RETURN @.Error
> On_Error:
> BEGIN
> IF @.Error <> 0
> BEGIN
> SELECT @.Msg + '. Error # ' + CAST(@.Error AS VARCHAR(10))
> RAISERROR(@.Msg,12,1)
> RETURN @.Error
> END
> END
> GO
>
> --
> Andrew J. Kelly SQL MVP
> "Don Miller" <nospam@.nospam.com> wrote in message
> news:utNmj6WyGHA.2392@.TK2MSFTNGP03.phx.gbl...
> > With SQL Server 2000 I created a backup disk file (and job) for full
> > database backups performed daily (which are appended), and a backup disk
> > file (and job) for log backups performed every hour (also appended).
> > Because
> > of disk space constraints (on a dedicated server), I would like to
remove
> > older backups from each of these backup files. For example, instead of
> > having seven (or 180) days of full backups and seven (or 180) days of
log
> > backups on my local disk (the server is backed up to tape nightly), I
> > would
> > like to automatically keep only the last three days of full backups and
> > only
> > the transaction logs that came after the first of the three full
backups.
> >
> > I have not discovered a way to automatically create backups as separate
> > file, each labeled and time-stamped that I could periodically delete, if
> > there is not a way to do the above with single appended files.
> >
> > So, how does one extract the older backups out of these single files
with
> > appended backups? Is there a way to configure that with EM, or does it
> > require SQL scripting?
> >
> > Thanks for any help.
> >
> >
>|||Don Miller wrote:
> With SQL Server 2000 I created a backup disk file (and job) for full
> database backups performed daily (which are appended), and a backup disk
> file (and job) for log backups performed every hour (also appended). Because
> of disk space constraints (on a dedicated server), I would like to remove
> older backups from each of these backup files. For example, instead of
> having seven (or 180) days of full backups and seven (or 180) days of log
> backups on my local disk (the server is backed up to tape nightly), I would
> like to automatically keep only the last three days of full backups and only
> the transaction logs that came after the first of the three full backups.
> I have not discovered a way to automatically create backups as separate
> file, each labeled and time-stamped that I could periodically delete, if
> there is not a way to do the above with single appended files.
> So, how does one extract the older backups out of these single files with
> appended backups? Is there a way to configure that with EM, or does it
> require SQL scripting?
> Thanks for any help.
>
Have a look at this script:
http://realsqlguy.com/serendipity/archives/11-Send-In-Backup!.html
Tracy McKibben
MCDBA
http://www.realsqlguy.com

Removing Older Backups?

With SQL Server 2000 I created a backup disk file (and job) for full
database backups performed daily (which are appended), and a backup disk
file (and job) for log backups performed every hour (also appended). Because
of disk space constraints (on a dedicated server), I would like to remove
older backups from each of these backup files. For example, instead of
having seven (or 180) days of full backups and seven (or 180) days of log
backups on my local disk (the server is backed up to tape nightly), I would
like to automatically keep only the last three days of full backups and only
the transaction logs that came after the first of the three full backups.
I have not discovered a way to automatically create backups as separate
file, each labeled and time-stamped that I could periodically delete, if
there is not a way to do the above with single appended files.
So, how does one extract the older backups out of these single files with
appended backups? Is there a way to configure that with EM, or does it
require SQL scripting?
Thanks for any help.Hi,
Take a look into the maintenance plan in Enterprise manager. Maintenance
plan allow you to archive the backup files
based on te frequency you provide.
Thanks
Hari
SQL Server MVP
"Don Miller" <nospam@.nospam.com> wrote in message
news:utNmj6WyGHA.2392@.TK2MSFTNGP03.phx.gbl...
> With SQL Server 2000 I created a backup disk file (and job) for full
> database backups performed daily (which are appended), and a backup disk
> file (and job) for log backups performed every hour (also appended).
> Because
> of disk space constraints (on a dedicated server), I would like to remove
> older backups from each of these backup files. For example, instead of
> having seven (or 180) days of full backups and seven (or 180) days of log
> backups on my local disk (the server is backed up to tape nightly), I
> would
> like to automatically keep only the last three days of full backups and
> only
> the transaction logs that came after the first of the three full backups.
> I have not discovered a way to automatically create backups as separate
> file, each labeled and time-stamped that I could periodically delete, if
> there is not a way to do the above with single appended files.
> So, how does one extract the older backups out of these single files with
> appended backups? Is there a way to configure that with EM, or does it
> require SQL scripting?
> Thanks for any help.
>|||Don,
You can achieve this with the Maintenance Plan wizard although it has some
limitations and not very flexible. If you want to create your own jobs you
can use this sample as a start. It shows how to generate a new file name for
each backup and a sample on how to remove older backup files as well.
-- Do a backup and create a separate file for each day of the
eek --
DECLARE @.DBName NVARCHAR(50), @.Device NVARCHAR(100), @.Name NVARCHAR(100)
IF OBJECT_ID('tempdb..#DBs') IS NOT NULL
DROP TABLE #DBs
CREATE TABLE #DBs ([name] VARCHAR(50),[db_size] VARCHAR(20),
[Owner] VARCHAR(20),[DBID] INT, [Created] VARCHAR(14),
[Status] VARCHAR(1000), [Compatibility_Level] INT)
INSERT INTO #DBs EXEC sp_helpdb
DECLARE cur_DBs CURSOR STATIC LOCAL
FOR SELECT [Name]
FROM #DBs
WHERE [DBID] IN (5,6)
OPEN cur_DBs
FETCH NEXT FROM cur_DBs INTO @.DBName
WHILE @.@.FETCH_STATUS = 0
BEGIN
SET @.Device = N'C:\Backups\DD_' + @.DBName + '_Full_' +
CAST(DAY(GETDATE()) AS NVARCHAR(4)) +
CAST(MONTH(GETDATE()) AS NVARCHAR(4)) +
CAST(YEAR(GETDATE()) AS NVARCHAR(8)) + N'.BAK'
SET @.Name = @.DBName + N' Full Backup'
BACKUP DATABASE @.DBName TO DISK = @.Device WITH INIT , NOUNLOAD ,
NAME = @.Name, NOSKIP , STATS = 10, NOFORMAT
RESTORE VERIFYONLY FROM DISK = @.Device WITH FILE = 1
FETCH NEXT FROM cur_DBs INTO @.DBName
END
CLOSE cur_DBs
DEALLOCATE cur_DBs
----
-- Removing Older Backup Files --
DECLARE @.Error INT, @.D DATETIME
SET @.D = CAST('20020801 15:00:00' AS DATETIME)
EXEC @.Error = remove_old_log_files @.D
SELECT @.Error
----
-- *** Procedure to remove old backups **** --
CREATE PROCEDURE remove_old_log_files
@.DelDate DATETIME
AS
SET NOCOUNT ON
DECLARE @.SQL VARCHAR(500), @.FName VARCHAR(40), @.Error INT
DECLARE @.Delete VARCHAR(300), @.Msg VARCHAR(100), @.Return INT
SET DATEFORMAT MDY
IF OBJECT_ID('tempdb..#dirlist') IS NOT NULL
DROP TABLE #DirList
CREATE TABLE #dirlist (FName VARCHAR(1000))
CREATE TABLE #Errors (Results VARCHAR(1000))
-- Insert the results of the dir cmd into a table so we can scan it
INSERT INTO #dirlist (FName)
exec master..xp_cmdshell 'dir /OD C:\Backups\*.trn'
SET @.Error = @.@.ERROR
IF @.Error <> 0
BEGIN
SET @.Msg = 'Error while getting the filenames with DIR '
GOTO On_Error
END
--SELECT * FROM #dirList
-- Remove the garbage
DELETE #dirlist WHERE
SUBSTRING(FName,1,2) < '00' OR
SUBSTRING(FName,1,2) > '99' OR
FName IS NULL
-- Create a cursor and for each file name do the processing.
-- The files will be processed in date order.
DECLARE curDir CURSOR READ_ONLY LOCAL
FOR
SELECT SUBSTRING(FName,40,40) AS FName
FROM #dirlist
WHERE CAST(SUBSTRING(FName,1,20) AS DATETIME) < @.DelDate
AND SUBSTRING(FName,40,40) LIKE '%.TRN'
OPEN curDir
FETCH NEXT FROM curDir INTO @.Fname
WHILE (@.@.fetch_status = 0)
BEGIN
-- Delete the old backup files
SET @.Delete = 'DEL "C:\Backups' + @.FName + '"'
INSERT INTO #Errors (Results)
exec master..xp_cmdshell @.Delete
IF @.@.RowCount > 1
BEGIN
SET @.Error = -1
SET @.Msg = 'Error while Deleting file ' + @.FName
GOTO On_Error
END
-- PRINT @.Delete
PRINT 'Deleted ' + @.FName + ' at ' +
CONVERT(VARCHAR(28),GETDATE(),113)
FETCH NEXT FROM curDir INTO @.Fname
END
CLOSE curDir
DEALLOCATE curDir
DROP TABLE #DirList
DROP TABLE #Errors
RETURN @.Error
On_Error:
BEGIN
IF @.Error <> 0
BEGIN
SELECT @.Msg + '. Error # ' + CAST(@.Error AS VARCHAR(10))
RAISERROR(@.Msg,12,1)
RETURN @.Error
END
END
GO
Andrew J. Kelly SQL MVP
"Don Miller" <nospam@.nospam.com> wrote in message
news:utNmj6WyGHA.2392@.TK2MSFTNGP03.phx.gbl...
> With SQL Server 2000 I created a backup disk file (and job) for full
> database backups performed daily (which are appended), and a backup disk
> file (and job) for log backups performed every hour (also appended).
> Because
> of disk space constraints (on a dedicated server), I would like to remove
> older backups from each of these backup files. For example, instead of
> having seven (or 180) days of full backups and seven (or 180) days of log
> backups on my local disk (the server is backed up to tape nightly), I
> would
> like to automatically keep only the last three days of full backups and
> only
> the transaction logs that came after the first of the three full backups.
> I have not discovered a way to automatically create backups as separate
> file, each labeled and time-stamped that I could periodically delete, if
> there is not a way to do the above with single appended files.
> So, how does one extract the older backups out of these single files with
> appended backups? Is there a way to configure that with EM, or does it
> require SQL scripting?
> Thanks for any help.
>|||Thanks for the script. I'll take a close look at it.
I did experiment with the Maintenance Plan wizard and instead of appending
the backups and logs to the same file, it creates those separate
time-stamped files. I'll probably go with this because I can more easily
deal (and understand) with many time-stamped files rather than one file with
the logs and such enclosed in some proprietary manner.
I'm also looking at SQL Sentry as you suggested. Thanks.
"Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
news:OSEqsLiyGHA.3440@.TK2MSFTNGP06.phx.gbl...
> Don,
> You can achieve this with the Maintenance Plan wizard although it has some
> limitations and not very flexible. If you want to create your own jobs you
> can use this sample as a start. It shows how to generate a new file name
for
> each backup and a sample on how to remove older backup files as well.
>
> -- Do a backup and create a separate file for each day of the
> eek --
> DECLARE @.DBName NVARCHAR(50), @.Device NVARCHAR(100), @.Name NVARCHAR(100)
> IF OBJECT_ID('tempdb..#DBs') IS NOT NULL
> DROP TABLE #DBs
> CREATE TABLE #DBs ([name] VARCHAR(50),[db_size] VARCHAR(20),
> [Owner] VARCHAR(20),[DBID] INT, [Created] VARC
HAR(14),
> [Status] VARCHAR(1000), [Compatibility_Level] INT)
> INSERT INTO #DBs EXEC sp_helpdb
>
> DECLARE cur_DBs CURSOR STATIC LOCAL
> FOR SELECT [Name]
> FROM #DBs
> WHERE [DBID] IN (5,6)
> OPEN cur_DBs
> FETCH NEXT FROM cur_DBs INTO @.DBName
> WHILE @.@.FETCH_STATUS = 0
> BEGIN
> SET @.Device = N'C:\Backups\DD_' + @.DBName + '_Full_' +
> CAST(DAY(GETDATE()) AS NVARCHAR(4)) +
> CAST(MONTH(GETDATE()) AS NVARCHAR(4)) +
> CAST(YEAR(GETDATE()) AS NVARCHAR(8)) + N'.BAK'
> SET @.Name = @.DBName + N' Full Backup'
> BACKUP DATABASE @.DBName TO DISK = @.Device WITH INIT , NOUNLOAD ,
> NAME = @.Name, NOSKIP , STATS = 10, NOFORMAT
> RESTORE VERIFYONLY FROM DISK = @.Device WITH FILE = 1
> FETCH NEXT FROM cur_DBs INTO @.DBName
> END
> CLOSE cur_DBs
> DEALLOCATE cur_DBs
> ----
> -- Removing Older Backup Files --
> DECLARE @.Error INT, @.D DATETIME
> SET @.D = CAST('20020801 15:00:00' AS DATETIME)
> EXEC @.Error = remove_old_log_files @.D
> SELECT @.Error
> ----
> -- *** Procedure to remove old backups **** --
> CREATE PROCEDURE remove_old_log_files
> @.DelDate DATETIME
> AS
> SET NOCOUNT ON
> DECLARE @.SQL VARCHAR(500), @.FName VARCHAR(40), @.Error INT
> DECLARE @.Delete VARCHAR(300), @.Msg VARCHAR(100), @.Return INT
> SET DATEFORMAT MDY
>
> IF OBJECT_ID('tempdb..#dirlist') IS NOT NULL
> DROP TABLE #DirList
> CREATE TABLE #dirlist (FName VARCHAR(1000))
> CREATE TABLE #Errors (Results VARCHAR(1000))
> -- Insert the results of the dir cmd into a table so we can scan it
> INSERT INTO #dirlist (FName)
> exec master..xp_cmdshell 'dir /OD C:\Backups\*.trn'
> SET @.Error = @.@.ERROR
> IF @.Error <> 0
> BEGIN
> SET @.Msg = 'Error while getting the filenames with DIR '
> GOTO On_Error
> END
> --SELECT * FROM #dirList
> -- Remove the garbage
> DELETE #dirlist WHERE
> SUBSTRING(FName,1,2) < '00' OR
> SUBSTRING(FName,1,2) > '99' OR
> FName IS NULL
>
> -- Create a cursor and for each file name do the processing.
> -- The files will be processed in date order.
> DECLARE curDir CURSOR READ_ONLY LOCAL
> FOR
> SELECT SUBSTRING(FName,40,40) AS FName
> FROM #dirlist
> WHERE CAST(SUBSTRING(FName,1,20) AS DATETIME) < @.DelDate
> AND SUBSTRING(FName,40,40) LIKE '%.TRN'
> OPEN curDir
> FETCH NEXT FROM curDir INTO @.Fname
> WHILE (@.@.fetch_status = 0)
> BEGIN
>
> -- Delete the old backup files
> SET @.Delete = 'DEL "C:\Backups' + @.FName + '"'
> INSERT INTO #Errors (Results)
> exec master..xp_cmdshell @.Delete
>
> IF @.@.RowCount > 1
> BEGIN
> SET @.Error = -1
> SET @.Msg = 'Error while Deleting file ' + @.FName
> GOTO On_Error
> END
>
> -- PRINT @.Delete
> PRINT 'Deleted ' + @.FName + ' at ' +
> CONVERT(VARCHAR(28),GETDATE(),113)
> FETCH NEXT FROM curDir INTO @.Fname
> END
> CLOSE curDir
> DEALLOCATE curDir
> DROP TABLE #DirList
> DROP TABLE #Errors
> RETURN @.Error
> On_Error:
> BEGIN
> IF @.Error <> 0
> BEGIN
> SELECT @.Msg + '. Error # ' + CAST(@.Error AS VARCHAR(10))
> RAISERROR(@.Msg,12,1)
> RETURN @.Error
> END
> END
> GO
>
> --
> Andrew J. Kelly SQL MVP
> "Don Miller" <nospam@.nospam.com> wrote in message
> news:utNmj6WyGHA.2392@.TK2MSFTNGP03.phx.gbl...
remove[vbcol=seagreen]
log[vbcol=seagreen]
backups.[vbcol=seagreen]
with[vbcol=seagreen]
>|||Don Miller wrote:
> With SQL Server 2000 I created a backup disk file (and job) for full
> database backups performed daily (which are appended), and a backup disk
> file (and job) for log backups performed every hour (also appended). Becau
se
> of disk space constraints (on a dedicated server), I would like to remove
> older backups from each of these backup files. For example, instead of
> having seven (or 180) days of full backups and seven (or 180) days of log
> backups on my local disk (the server is backed up to tape nightly), I woul
d
> like to automatically keep only the last three days of full backups and on
ly
> the transaction logs that came after the first of the three full backups.
> I have not discovered a way to automatically create backups as separate
> file, each labeled and time-stamped that I could periodically delete, if
> there is not a way to do the above with single appended files.
> So, how does one extract the older backups out of these single files with
> appended backups? Is there a way to configure that with EM, or does it
> require SQL scripting?
> Thanks for any help.
>
Have a look at this script:
http://realsqlguy.com/serendipity/a...-Send-In-Backup!.html
Tracy McKibben
MCDBA
http://www.realsqlguy.com

Removing old transaction log backup files

My organization is running SQL Server 2000 on a Windows 2000 server. We have
a maintenance plan set up to perform a daily backup of several database
files. The full database backup runs each day at 2:00 a.m. The transaction
log backup runs every four hours. It is setup in the maintenance plan that
the checkbox for both the data file and transaction log that says "Remove
files older than" is checked and set for 2 days. However, the old transaction
log backup files (*.TRN) are not being automatically removed. The regular
database files (*.BAK) are removed just fine. Any suggestions?
Hello
You should have some more information in the Maintenance Plan output file.
You can configure the Maint plan to produce output from the Maint Plan
properties window.
Thank you for using Microsoft newsgroups.
Sincerely
Pankaj Agarwal
Microsoft Corporation
This posting is provided AS IS with no warranties, and confers no rights.
|||Below KB might help:
http://support.microsoft.com/default...&Product=sql2k
Also, check out below great troubleshooting suggestions from Bill H at MS:
-- Log files don't delete --
This is likely to be either a permissions problem or a sharing violation
problem. The maintenance plan is run as a job, and jobs are run by the
SQLServerAgent service.
Permissions:
1. Determine the startup account for the SQLServerAgent service
(Start|Programs|Administrative tools|Services|SQLServerAgent|Startup). This
account is the security context for jobs, and thus the maintenance plan.
2. If SQLServerAgent is started using LocalSystem (as opposed to a domain
account) then skip step 3.
3. On that box, log onto NT as that account. Using Explorer, attempt to
delete an expired backup. If that succeeds then go to Sharing Violation
section.
4. Log onto NT with an account that is an administrator and use Explorer to
look at the Properties|Security of the folder (where the backups reside)
and ensure the SQLServerAgent startup account has Full Control. If the
SQLServerAgent startup account is LocalSystem, then the account to consider
is SYSTEM.
5. In NT, if an account is a member of an NT group, and if that group has
Access is Denied, then that account will have Access is Denied, even if
that account is also a member of the Administrators group. Thus you may
need to check group permissions (if the Startup Account is a member of a
group).
6. Keep in mind that permissions (by default) are inherited from a parent
folder. Thus, if the backups are stored in C:\bak, and if someone had
denied permission to the SQLServerAgent startup account for C:\, then
C:\bak will inherit access is denied.
Sharing violation:
This is likely to be rooted in a timing issue, with the most likely cause
being another scheduled process (such as NT Backup or Anti-Virus software)
having the backup file open at the time when the SQLServerAgent (i.e., the
maintenance plan job) tried to delete it.
1. Download filemon and handle from www.sysinternals.com.
2. I am not sure whether filemon can be scheduled, or you might be able to
use NT scheduling services to start filemon just before the maintenance
plan job is started, but the filemon log can become very large, so it would
be best to start it some short time before the maintenance plan starts.
3. Inspect the filemon log for another process that has that backup file
open (if your lucky enough to have started filemon before this other
process grabs the backup folder), and inspect the log for the results when
the SQLServerAgent agent attempts to open that same file.
4. Schedule the job or that other process to do their work at different
times.
5. You can use the handle utility if you are around at the time when the
job is scheduled to run.
If the backup files are going to a \\share or a mapped drive (as opposed to
local drive), then you will need to modify the above (with respect to where
the tests and utilities are run).
Finally, inspection of the maintenance plan's history report might be
useful.
Thanks,
Bill Hollinshead
Microsoft, SQL Server
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"AscentSQLAdmin" <AscentSQLAdmin@.discussions.microsoft.com> wrote in message
news:9A971D9F-D439-4F0F-B1E9-BAB6F42D73B3@.microsoft.com...
> My organization is running SQL Server 2000 on a Windows 2000 server. We have
> a maintenance plan set up to perform a daily backup of several database
> files. The full database backup runs each day at 2:00 a.m. The transaction
> log backup runs every four hours. It is setup in the maintenance plan that
> the checkbox for both the data file and transaction log that says "Remove
> files older than" is checked and set for 2 days. However, the old transaction
> log backup files (*.TRN) are not being automatically removed. The regular
> database files (*.BAK) are removed just fine. Any suggestions?

Removing old transaction log backup files

My organization is running SQL Server 2000 on a Windows 2000 server. We have
a maintenance plan set up to perform a daily backup of several database
files. The full database backup runs each day at 2:00 a.m. The transaction
log backup runs every four hours. It is setup in the maintenance plan that
the checkbox for both the data file and transaction log that says "Remove
files older than" is checked and set for 2 days. However, the old transactio
n
log backup files (*.TRN) are not being automatically removed. The regular
database files (*.BAK) are removed just fine. Any suggestions?Hello
You should have some more information in the Maintenance Plan output file.
You can configure the Maint plan to produce output from the Maint Plan
properties window.
Thank you for using Microsoft newsgroups.
Sincerely
Pankaj Agarwal
Microsoft Corporation
This posting is provided AS IS with no warranties, and confers no rights.|||Below KB might help:
http://support.microsoft.com/defaul...2&Product=sql2k
Also, check out below great troubleshooting suggestions from Bill H at MS:
-- Log files don't delete --
This is likely to be either a permissions problem or a sharing violation
problem. The maintenance plan is run as a job, and jobs are run by the
SQLServerAgent service.
Permissions:
1. Determine the startup account for the SQLServerAgent service
(Start|Programs|Administrative tools|Services|SQLServerAgent|Startup). This
account is the security context for jobs, and thus the maintenance plan.
2. If SQLServerAgent is started using LocalSystem (as opposed to a domain
account) then skip step 3.
3. On that box, log onto NT as that account. Using Explorer, attempt to
delete an expired backup. If that succeeds then go to Sharing Violation
section.
4. Log onto NT with an account that is an administrator and use Explorer to
look at the Properties|Security of the folder (where the backups reside)
and ensure the SQLServerAgent startup account has Full Control. If the
SQLServerAgent startup account is LocalSystem, then the account to consider
is SYSTEM.
5. In NT, if an account is a member of an NT group, and if that group has
Access is Denied, then that account will have Access is Denied, even if
that account is also a member of the Administrators group. Thus you may
need to check group permissions (if the Startup Account is a member of a
group).
6. Keep in mind that permissions (by default) are inherited from a parent
folder. Thus, if the backups are stored in C:\bak, and if someone had
denied permission to the SQLServerAgent startup account for C:\, then
C:\bak will inherit access is denied.
Sharing violation:
This is likely to be rooted in a timing issue, with the most likely cause
being another scheduled process (such as NT Backup or Anti-Virus software)
having the backup file open at the time when the SQLServerAgent (i.e., the
maintenance plan job) tried to delete it.
1. Download filemon and handle from www.sysinternals.com.
2. I am not sure whether filemon can be scheduled, or you might be able to
use NT scheduling services to start filemon just before the maintenance
plan job is started, but the filemon log can become very large, so it would
be best to start it some short time before the maintenance plan starts.
3. Inspect the filemon log for another process that has that backup file
open (if your lucky enough to have started filemon before this other
process grabs the backup folder), and inspect the log for the results when
the SQLServerAgent agent attempts to open that same file.
4. Schedule the job or that other process to do their work at different
times.
5. You can use the handle utility if you are around at the time when the
job is scheduled to run.
If the backup files are going to a \\share or a mapped drive (as opposed to
local drive), then you will need to modify the above (with respect to where
the tests and utilities are run).
Finally, inspection of the maintenance plan's history report might be
useful.
Thanks,
Bill Hollinshead
Microsoft, SQL Server
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"AscentSQLAdmin" <AscentSQLAdmin@.discussions.microsoft.com> wrote in message
news:9A971D9F-D439-4F0F-B1E9-BAB6F42D73B3@.microsoft.com...
> My organization is running SQL Server 2000 on a Windows 2000 server. We ha
ve
> a maintenance plan set up to perform a daily backup of several database
> files. The full database backup runs each day at 2:00 a.m. The transaction
> log backup runs every four hours. It is setup in the maintenance plan that
> the checkbox for both the data file and transaction log that says "Remove
> files older than" is checked and set for 2 days. However, the old transact
ion
> log backup files (*.TRN) are not being automatically removed. The regular
> database files (*.BAK) are removed just fine. Any suggestions?

Removing old .bak & .trn files

I've run into a problem I didn't expect with my backup program. It seems
that Windows admins are very lax about writing scripts to remove old backup
files after copying them to tape, even though they say its easy, they don't
do it for all database backups on all servers in the farm.
So, I'm wondering first, if I should do it from my backup program (based on
RealSQLGuy's) and second, how I should go about it.
My rough thought is to do an xm_cmdshell('dir') in the backup directory into
a table variable, parse the date from the filename into a datetime column,
select the old files and issue an xp_cmdshell('del <file>') command via
dynamic sql.
Thanks,
JayHello Jay!
In SQL Server 2005, you could use Maintenance Plan Wizard to create a
Maintenance Cleanup Task to delete old bak and trn files.
Ekrem Önsoy
"Jay" <spam@.nospam.org> wrote in message
news:eQNEUct9HHA.5404@.TK2MSFTNGP02.phx.gbl...
> I've run into a problem I didn't expect with my backup program. It seems
> that Windows admins are very lax about writing scripts to remove old
> backup files after copying them to tape, even though they say its easy,
> they don't do it for all database backups on all servers in the farm.
> So, I'm wondering first, if I should do it from my backup program (based
> on RealSQLGuy's) and second, how I should go about it.
> My rough thought is to do an xm_cmdshell('dir') in the backup directory
> into a table variable, parse the date from the filename into a datetime
> column, select the old files and issue an xp_cmdshell('del <file>')
> command via dynamic sql.
> Thanks,
> Jay
>
>|||Maintenance plan in 2005?
Besides, I do all my maintenance through SQLagent after writing the scripts
myself.
"Ekrem Önsoy" <ekrem@.btegitim.com> wrote in message
news:OOO8bft9HHA.5424@.TK2MSFTNGP02.phx.gbl...
> Hello Jay!
>
> In SQL Server 2005, you could use Maintenance Plan Wizard to create a
> Maintenance Cleanup Task to delete old bak and trn files.
>
> --
> Ekrem Önsoy
>
> "Jay" <spam@.nospam.org> wrote in message
> news:eQNEUct9HHA.5404@.TK2MSFTNGP02.phx.gbl...
>> I've run into a problem I didn't expect with my backup program. It seems
>> that Windows admins are very lax about writing scripts to remove old
>> backup files after copying them to tape, even though they say its easy,
>> they don't do it for all database backups on all servers in the farm.
>> So, I'm wondering first, if I should do it from my backup program (based
>> on RealSQLGuy's) and second, how I should go about it.
>> My rough thought is to do an xm_cmdshell('dir') in the backup directory
>> into a table variable, parse the date from the filename into a datetime
>> column, select the old files and issue an xp_cmdshell('del <file>')
>> command via dynamic sql.
>> Thanks,
>> Jay
>>
>|||This is just me but I would create a batch file to delete the files and give
it to the Windows group to execute it after they do the tape backup. Make
sure that the batch file execution step depends on the tape backup so that
you are not without your backups if the tape backup fails.
"Jay" wrote:
> Maintenance plan in 2005?
> Besides, I do all my maintenance through SQLagent after writing the scripts
> myself.
> "Ekrem Ã?nsoy" <ekrem@.btegitim.com> wrote in message
> news:OOO8bft9HHA.5424@.TK2MSFTNGP02.phx.gbl...
> > Hello Jay!
> >
> >
> > In SQL Server 2005, you could use Maintenance Plan Wizard to create a
> > Maintenance Cleanup Task to delete old bak and trn files.
> >
> >
> > --
> > Ekrem Ã?nsoy
> >
> >
> > "Jay" <spam@.nospam.org> wrote in message
> > news:eQNEUct9HHA.5404@.TK2MSFTNGP02.phx.gbl...
> >> I've run into a problem I didn't expect with my backup program. It seems
> >> that Windows admins are very lax about writing scripts to remove old
> >> backup files after copying them to tape, even though they say its easy,
> >> they don't do it for all database backups on all servers in the farm.
> >>
> >> So, I'm wondering first, if I should do it from my backup program (based
> >> on RealSQLGuy's) and second, how I should go about it.
> >>
> >> My rough thought is to do an xm_cmdshell('dir') in the backup directory
> >> into a table variable, parse the date from the filename into a datetime
> >> column, select the old files and issue an xp_cmdshell('del <file>')
> >> command via dynamic sql.
> >>
> >> Thanks,
> >> Jay
> >>
> >>
> >>
> >
>
>

Removing msrepl_trans columns from db

Hello,
Is there a way to remove the msrepl_tran columns from
tables that have been marked for replication?
I've a backup taken from a replicated system that I want
to remove all the replicated tables and columns from. I
can go through and delete the msrepl_tran columns and
constraint from the tables manually but it is very time
consuming to do 100 tables.
Can any one help?
Thanks in advance.
Enterprise Manager is your friend. Right click on your tables and remove
away.
You might also try to run a script like this.
select 'alter table '+ object_name(parent_obj) +' drop constraint '+name+
char(13)+' go'
From sysobjects where name like '%msrepl%' and type ='D' and
object_name(parent_obj)
<>'MSreplication_subscriptions'
GO
select 'alter table '+object_name(ID) +' drop column msrepl_tran_version '+
char(13) +'GO' from syscolumns where name like 'msrepl_tran_version%' and
object_name(ID) not like 'conflict%'
GO
Copy what appears in the results pane and then paste it in the execution
window and run it.
Hilary Cotter
Looking for a SQL Server replication book?
Now available for purchase at:
http://www.nwsu.com/0974973602.html
"Harvey" <anonymous@.discussions.microsoft.com> wrote in message
news:26d901c4dde2$9c58f700$a301280a@.phx.gbl...
> Hello,
> Is there a way to remove the msrepl_tran columns from
> tables that have been marked for replication?
> I've a backup taken from a replicated system that I want
> to remove all the replicated tables and columns from. I
> can go through and delete the msrepl_tran columns and
> constraint from the tables manually but it is very time
> consuming to do 100 tables.
> Can any one help?
> Thanks in advance.
|||Thanks for the replys. I have over 100 tables and
dropping one at a time would take way to long.
I'll use the cursor method and see how I get on. Thanks
again

>--Original Message--
>Enterprise Manager is your friend. Right click on your
tables and remove
>away.
>You might also try to run a script like this.
>select 'alter table '+ object_name(parent_obj) +' drop
constraint '+name+
>char(13)+' go'
>From sysobjects where name like '%msrepl%' and type ='D'
and
>object_name(parent_obj)
><>'MSreplication_subscriptions'
>GO
>select 'alter table '+object_name(ID) +' drop column
msrepl_tran_version '+
>char(13) +'GO' from syscolumns where name
like 'msrepl_tran_version%' and
>object_name(ID) not like 'conflict%'
>GO
>Copy what appears in the results pane and then paste it
in the execution
>window and run it.
>
>--
>Hilary Cotter
>Looking for a SQL Server replication book?
>Now available for purchase at:
>http://www.nwsu.com/0974973602.html
>"Harvey" <anonymous@.discussions.microsoft.com> wrote in
message[vbcol=seagreen]
>news:26d901c4dde2$9c58f700$a301280a@.phx.gbl...
want[vbcol=seagreen]
I
>
>.
>

Saturday, February 25, 2012

Removing differential backup

I set up a differential backup on my SQL server and have
decided I would rather not have it. However, I can't seem
to get rid of it. Any suggestions?
Hello John
How did you setup the differential backups? Was it setup as a SQLAgent
scheduled job?
If it is setup as a scheduled SQLAgent job, I'm not sure what is preventing
you from disabling/removing the job that performs SQL differential backups.
Could you please elaborate more on what you experience when you try to
disable or delete the job from SQLAgent job list in Enterprise Manager?
Thank you for using Microsoft newsgroups.
Sincerely
Pankaj Agarwal
Microsoft Corporation
This posting is provided AS IS with no warranties, and confers no rights.
|||It was set up through Enterprise Manager by selecting the
database then selecting "all tasks:, I then chose Backup
database then selected Differential Backup. I chose a time
of 3:00 AM.
>--Original Message--
>Hello John
>How did you setup the differential backups? Was it setup
as a SQLAgent
>scheduled job?
>If it is setup as a scheduled SQLAgent job, I'm not sure
what is preventing
>you from disabling/removing the job that performs SQL
differential backups.
>Could you please elaborate more on what you experience
when you try to
>disable or delete the job from SQLAgent job list in
Enterprise Manager?
>Thank you for using Microsoft newsgroups.
>Sincerely
>Pankaj Agarwal
>Microsoft Corporation
>This posting is provided AS IS with no warranties, and
confers no rights.
>.
>
|||If you scheduled it there would be a scheduled job that issues the Diff
backup. Simply delete the job. If you didn't schedule a time it would have
been a one shot deal and there is nothing to worry about.
Andrew J. Kelly SQL MVP
"John Schuster" <schuster@.llnl.gov> wrote in message
news:043c01c4a0e2$306adfa0$a301280a@.phx.gbl...[vbcol=seagreen]
> It was set up through Enterprise Manager by selecting the
> database then selecting "all tasks:, I then chose Backup
> database then selected Differential Backup. I chose a time
> of 3:00 AM.
> as a SQLAgent
> what is preventing
> differential backups.
> when you try to
> Enterprise Manager?
> confers no rights.

Removing differential backup

I set up a differential backup on my SQL server and have
decided I would rather not have it. However, I can't seem
to get rid of it. Any suggestions?Hello John
How did you setup the differential backups? Was it setup as a SQLAgent
scheduled job?
If it is setup as a scheduled SQLAgent job, I'm not sure what is preventing
you from disabling/removing the job that performs SQL differential backups.
Could you please elaborate more on what you experience when you try to
disable or delete the job from SQLAgent job list in Enterprise Manager?
Thank you for using Microsoft newsgroups.
Sincerely
Pankaj Agarwal
Microsoft Corporation
This posting is provided AS IS with no warranties, and confers no rights.|||It was set up through Enterprise Manager by selecting the
database then selecting "all tasks:, I then chose Backup
database then selected Differential Backup. I chose a time
of 3:00 AM.
>--Original Message--
>Hello John
>How did you setup the differential backups? Was it setup
as a SQLAgent
>scheduled job?
>If it is setup as a scheduled SQLAgent job, I'm not sure
what is preventing
>you from disabling/removing the job that performs SQL
differential backups.
>Could you please elaborate more on what you experience
when you try to
>disable or delete the job from SQLAgent job list in
Enterprise Manager?
>Thank you for using Microsoft newsgroups.
>Sincerely
>Pankaj Agarwal
>Microsoft Corporation
>This posting is provided AS IS with no warranties, and
confers no rights.
>.
>|||If you scheduled it there would be a scheduled job that issues the Diff
backup. Simply delete the job. If you didn't schedule a time it would have
been a one shot deal and there is nothing to worry about.
--
Andrew J. Kelly SQL MVP
"John Schuster" <schuster@.llnl.gov> wrote in message
news:043c01c4a0e2$306adfa0$a301280a@.phx.gbl...
> It was set up through Enterprise Manager by selecting the
> database then selecting "all tasks:, I then chose Backup
> database then selected Differential Backup. I chose a time
> of 3:00 AM.
> >--Original Message--
> >Hello John
> >
> >How did you setup the differential backups? Was it setup
> as a SQLAgent
> >scheduled job?
> >If it is setup as a scheduled SQLAgent job, I'm not sure
> what is preventing
> >you from disabling/removing the job that performs SQL
> differential backups.
> >Could you please elaborate more on what you experience
> when you try to
> >disable or delete the job from SQLAgent job list in
> Enterprise Manager?
> >
> >Thank you for using Microsoft newsgroups.
> >
> >Sincerely
> >
> >Pankaj Agarwal
> >Microsoft Corporation
> >
> >This posting is provided AS IS with no warranties, and
> confers no rights.
> >
> >.
> >

Monday, February 20, 2012

Removing a SQL server backup

In SQL Enterprise Manager, an employee right-clicked the 'Database' object
and created a scheduled backup. Then they expanded the 'Database' object,
found the target database 'XYZdatabase', right-clicked that too and
scheduled a second backup to a different drive.
How do I delete the backup job(s) because I have two running right now?
If I remove the file location where it backs up to, it tells me I must
select a file name / location. There is no way to remove the databse in the
SQL Server backup window, only an option from the dropdown to select
different databases.
Thanks in advance.
r042wal schrieb:
> In SQL Enterprise Manager, an employee right-clicked the 'Database'
> object and created a scheduled backup. Then they expanded the
> 'Database' object, found the target database 'XYZdatabase',
> right-clicked that too and scheduled a second backup to a different drive.
> How do I delete the backup job(s) because I have two running right now?
look at the SQL Agent Jobs. There you find the scheduled jobs and can
delete one.

> If I remove the file location where it backs up to, it tells me I must
> select a file name / location. There is no way to remove the databse in
> the SQL Server backup window, only an option from the dropdown to select
> different databases.
> Thanks in advance.
hth
Gregor Stefka

Removing a SQL server backup

In SQL Enterprise Manager, an employee right-clicked the 'Database' object
and created a scheduled backup. Then they expanded the 'Database' object,
found the target database 'XYZdatabase', right-clicked that too and
scheduled a second backup to a different drive.
How do I delete the backup job(s) because I have two running right now?
If I remove the file location where it backs up to, it tells me I must
select a file name / location. There is no way to remove the databse in the
SQL Server backup window, only an option from the dropdown to select
different databases.
Thanks in advance.r042wal schrieb:
> In SQL Enterprise Manager, an employee right-clicked the 'Database'
> object and created a scheduled backup. Then they expanded the
> 'Database' object, found the target database 'XYZdatabase',
> right-clicked that too and scheduled a second backup to a different drive.
> How do I delete the backup job(s) because I have two running right now?
look at the SQL Agent Jobs. There you find the scheduled jobs and can
delete one.
> If I remove the file location where it backs up to, it tells me I must
> select a file name / location. There is no way to remove the databse in
> the SQL Server backup window, only an option from the dropdown to select
> different databases.
> Thanks in advance.
hth
Gregor Stefka

Removing a SQL server backup

In SQL Enterprise Manager, an employee right-clicked the 'Database' object
and created a scheduled backup. Then they expanded the 'Database' object,
found the target database 'XYZdatabase', right-clicked that too and
scheduled a second backup to a different drive.
How do I delete the backup job(s) because I have two running right now?
If I remove the file location where it backs up to, it tells me I must
select a file name / location. There is no way to remove the databse in the
SQL Server backup window, only an option from the dropdown to select
different databases.
Thanks in advance.r042wal schrieb:
> In SQL Enterprise Manager, an employee right-clicked the 'Database'
> object and created a scheduled backup. Then they expanded the
> 'Database' object, found the target database 'XYZdatabase',
> right-clicked that too and scheduled a second backup to a different drive.
> How do I delete the backup job(s) because I have two running right now?
look at the SQL Agent Jobs. There you find the scheduled jobs and can
delete one.

> If I remove the file location where it backs up to, it tells me I must
> select a file name / location. There is no way to remove the databse in
> the SQL Server backup window, only an option from the dropdown to select
> different databases.
> Thanks in advance.
hth
Gregor Stefka