Showing posts with label deleting. Show all posts
Showing posts with label deleting. Show all posts

Friday, February 24, 2012

backup Maintenance wizard

Will Trans. logs backup options be in the wizard in sp2?

At this point there are no options to backup trans. logs every 1hr and deleting files over x amount of days old without doing a TSQL command correct?

To clarify, in 2k enterprise, it's in the maintenance plan. I can specify that info and give it the trn extension and folder to backup into.

I am a network admin being given sql duties now, so If I may seem like a beginner, it's because I am.

I did to a search for this topic, so forgive me if there is one i did not find.

Also, I was trying to submit feedback as requested for sp2 about this, but i did not see a button on the bottom of the search through feedback as stated.

You can do transaction log backups along with differential backups in a maintenance plan. You have to add a Backup database task. Then you can configure the backup type within the task. (It's the third field from the top in the dialog.)|||Probably looking for a similar option ion SQL Server 2000. I had a hard time myself way back.|||

You can back up Transaction logs every hour if you want to, just set up a job to back them up as often as you wish, for example:

http://img.photobucket.com/albums/v472/Schmedrick/backuptranslog.gif

You can also delete backup files older than "x" days by adding a maintenance cleanup task to your maintenance plan after it has been created, this does require that SP1 has been installed, for example:

http://img.photobucket.com/albums/v472/Schmedrick/mainttask.gif

|||

Is there a way to run hourly transaction log backups while backing up the database once a day in ONE maintenance plan (like SQL2000)? Or do we have to create one maintenance plan for the full backup and another one for the transaction log backups.

|||

No. A maintenance plan is generated as a single monolithic SSIS package. That means the entire package has a single schedule. If you have multiple tasks in the maintenance plan, they will all run on the same schedule. So, in 2005, you have to create a separate maintenance plan for each group of tasks that need to have a distinct schedule. It is for this reason, that I do not recommend using maintenance plans at all and simply writing the code for this stuff yourself. I also don't like the fact that I have to enlist the SSIS engine, so now running my backups has a dependency on the SSIS engine as well as the security access of the SSIS engine. If something happens to SSIS, my backups no longer run. Can you tell that I absolutely hate the new maintenance plans in 2005? It takes something that was very simple and very straightforward and turned it into a mess than has to transit multiple subsystems in order to perform and VERY straightforward task.

Below is the set of code that I use for backing up databases along with a procedure to clean up the backup history and backup files. All T-SQL. Simple, straightforward, and it is smart enough to not try to issue a tran log backup against a database that is in simple recovery model. All you have to do is create the jobs to call the backup and clean-up based on the type of backup you want to run and the frequency you want it to run on.

CREATE TABLE [dbo].[backupfiles](

[DatabaseName] [varchar](255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

[BackupFileName] [varchar](255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

[CreationDate] [datetime] NULL

) ON [PRIMARY]

GO

CREATE procedure [dbo].[asp_backup]

@.dir varchar(50), @.type char(1)

as

/****************************************************************/

/* Stored Procedure: asp_backup */

/* Creation Date: 4/01/2006 */

/* Written by: Mike Hotek - MHS Enterprises, Inc. */

/* http://www.mssqlserver.com */

/* Copyright: 2006 MHS Enterprises, Inc. All Rights Reserved */

/* Code can be used in its entirety, free of charge. Code can*/

/* not be incorporated into other products that are for sale. */

/* This copyright notice must remain intact when used. */

/* Code is provided as-is, without warranties. It is the */

/* user's sole responsibility to test this code for */

/* suitability in their environment. */

/* */

/* Purpose: Executes full, differential, and tran log backups */

/* */

/* Input Parameters: */

/* @.dir directory for the backup */

/* @.type backup type */

/* */

/* Output Parameters: None */

/* */

/* Return Status: 0 success */

/* -1 failure */

/* */

/* Usage: exec asp_backup 'c:\data','T' */

/* Executes a transaction log backup against each */

/* database that is in full recovery model and drops the */

/* backups in the directory c:\data */

/* */

/* Local Variables: */

/* */

/* Called By: SQL Server Agent job */

/* */

/* Calls: None */

/* */

/* Data Modifications: */

/* Inserts into the blockedprocess table */

/* */

/* Updates: */

/* Date Author Purpose */

/* 4/01/06 Mike Hotek Created */

/****************************************************************/

declare @.filename varchar(255),

@.database varchar(255),

@.recovery int,

@.command nvarchar(1000)

--Error checking

if @.dir is null

begin

print 'You must specify a directory path'

return

end

if @.type not in ('F','D','T')

begin

print 'Valid backup types are F, D, and T'

return

end

--Format directory path

if right(@.dir,1) != '\'

set @.dir = @.dir + '\'

set @.command = null

declare curdb cursor for

select name, status from master.dbo.sysdatabases where name not in ('tempdb','model')

for read only

open curdb

fetch curdb into @.database, @.recovery

while @.@.fetch_status = 0

begin

--Format filename. Functions needed to work around single digit month, day, minute, etc.

set @.filename = @.dir + @.database + '_' + cast(datepart(yyyy,getdate()) as char(4)) +

right('0' + rtrim(cast(datepart(mm,getdate()) as char(2))),2) +

right('0' + rtrim(cast(datepart(dd,getdate()) as char(2))),2) +

right('0' + rtrim(cast(datepart(hh,getdate()) as char(2))),2) +

right('0' + rtrim(cast(datepart(mi,getdate()) as char(2))),2) +

right('0' + rtrim(cast(datepart(ss,getdate()) as char(2))),2)

set @.filename = @.filename + case when @.type = 'F' then '_full.bak'

when @.type = 'D' then '_diff.bak'

else '.trn' end

--Format backup command

if @.type = 'F'

begin

set @.command = 'backup database [' + @.database + '] to disk = ''' + @.filename + ''' with init'

end

else if @.type = 'D' and @.database != 'master'

begin

set @.command = 'backup database [' + @.database + '] to disk = ''' + @.filename + ''' with differential, init'

end

else if @.type = 'T' and DATABASEPROPERTYEX(@.database, N'RECOVERY') = 'Full'

begin

set @.command = 'backup log [' + @.database + '] to disk = ''' + @.filename + ''' with init'

end

--Execute backup

if @.command is not null

begin

print @.command

exec sp_executesql @.command

end

insert into dbo.backupfiles

(DatabaseName, BackupFileName, CreationDate)

values(@.database, @.filename, getdate())

set @.command = null

fetch curdb into @.database, @.recovery

end

close curdb

deallocate curdb

GO

CREATE procedure [dbo].[asp_bakfilecleanup] @.backupretention int,

@.historyretention int

as

/****************************************************************/

/* Stored Procedure: asp_bakfilecleanup */

/* Creation Date: 4/01/2006 */

/* Written by: Mike Hotek - MHS Enterprises, Inc. */

/* http://www.mssqlserver.com */

/* Copyright: 2006 MHS Enterprises, Inc. All Rights Reserved */

/* Code can be used in its entirety, free of charge. Code can*/

/* not be incorporated into other products that are for sale. */

/* This copyright notice must remain intact when used. */

/* Code is provided as-is, without warranties. It is the */

/* user's sole responsibility to test this code for */

/* suitability in their environment. */

/* */

/* Purpose: Removes old backup files from the file system. */

/* */

/* Input Parameters: */

/* @.backupretention Number of days to retain backup files */

/* @.historyretention Number of days to retain backup history*/

/* */

/* Output Parameters: None */

/* */

/* Return Status: 0 success */

/* -1 failure */

/* */

/* Usage: exec asp_bakfilecleanup 3,15 */

/* Deletes any backup files older than 3 days and any */

/* backup history older than 15 days */

/* */

/* Local Variables: */

/* */

/* Called By: SQL Server Agent job */

/* */

/* Calls: None */

/* */

/* Data Modifications: */

/* Deletes rows from the backupfiles table */

/* */

/* Updates: */

/* Date Author Purpose */

/* 5/10/06 Mike Hotek Created */

/****************************************************************/

--This is wired to a logging table simply to avoid messy code in

--parsing file names or pulling fiel attributes to figure out which

--files to purge

declare @.file varchar(255),

@.command varchar(1000)

if @.backupretention is null

begin

print 'You must specify a retention interval'

return

end

if @.historyretention is null

begin

print 'You must specify a retention interval'

return

end

--Pull the list of files that are older than the retention

-- Construct a del command for each file and execute it.

declare curfile cursor for select BackupFileName from dbo.backupfiles

where CreationDate < dateadd(dd,-@.backupretention,getdate())

for read only

open curfile

fetch curfile into @.file

while @.@.fetch_status = 0

begin

set @.command = 'exec master.dbo.xp_cmdshell ''del ' + @.file + ''''

exec(@.command)

fetch curfile into @.file

end

--Clean up objects that were created

close curfile

deallocate curfile

delete from backupfiles

where CreationDate < dateadd(dd,-@.historyretention,getdate())

GO

Friday, February 10, 2012

backup files not deleting

Hello:
I have a few ideas about what to do on this. But, I still would like to
solicit some opinions, if you don't mind.
We have a SQL Server 2000 client who has a maintenance plan that conducts a
backup of its databases. And, each database is using the Full Recovery Mode
l.
The backup of the databases itself is working perfectly. But, the backup
files (bak files) are not being removed. You see, the maintenance plan
specifies that backup files are to be removed every 2 days. That's not
happening?
Why would that be? I mean, why would part of the maintenance plan (the
backing up of the databases) work but another part of the plan (the removal
of the database files) not work?
Thanks!
childofthe1980sHere is a very good overview as to why this may not work some times fro Bill
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
Thanks
Hari
"childofthe1980s" wrote:

> Hello:
> I have a few ideas about what to do on this. But, I still would like to
> solicit some opinions, if you don't mind.
> We have a SQL Server 2000 client who has a maintenance plan that conducts
a
> backup of its databases. And, each database is using the Full Recovery Mo
del.
> The backup of the databases itself is working perfectly. But, the backup
> files (bak files) are not being removed. You see, the maintenance plan
> specifies that backup files are to be removed every 2 days. That's not
> happening?
> Why would that be? I mean, why would part of the maintenance plan (the
> backing up of the databases) work but another part of the plan (the remova
l
> of the database files) not work?
> Thanks!
> childofthe1980s

backup files not deleting

Hello:
I have a few ideas about what to do on this. But, I still would like to
solicit some opinions, if you don't mind.
We have a SQL Server 2000 client who has a maintenance plan that conducts a
backup of its databases. And, each database is using the Full Recovery Model.
The backup of the databases itself is working perfectly. But, the backup
files (bak files) are not being removed. You see, the maintenance plan
specifies that backup files are to be removed every 2 days. That's not
happening?
Why would that be? I mean, why would part of the maintenance plan (the
backing up of the databases) work but another part of the plan (the removal
of the database files) not work?
Thanks!
childofthe1980sHere is a very good overview as to why this may not work some times fro Bill
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
Thanks
Hari
"childofthe1980s" wrote:
> Hello:
> I have a few ideas about what to do on this. But, I still would like to
> solicit some opinions, if you don't mind.
> We have a SQL Server 2000 client who has a maintenance plan that conducts a
> backup of its databases. And, each database is using the Full Recovery Model.
> The backup of the databases itself is working perfectly. But, the backup
> files (bak files) are not being removed. You see, the maintenance plan
> specifies that backup files are to be removed every 2 days. That's not
> happening?
> Why would that be? I mean, why would part of the maintenance plan (the
> backing up of the databases) work but another part of the plan (the removal
> of the database files) not work?
> Thanks!
> childofthe1980s