question

chitrarekhasaha avatar image
chitrarekhasaha asked

Delete backup files after running the task scheduler

Installed Ola Hallengren's script and created the following tasks

When I run individual task manually backup and cleanup files are created simultaneously

but when execute task scheduler backup files are not deleted after 48 hrs. The script is as following:

sqlcmd -E -S devwinsql6 -d master -Q "EXECUTE dbo.DatabaseBackup @Databases = 'USER_DATABASES', @Directory = N'D:\Backup\', @BackupType = 'DIFF'"

Do we need the cleanup type parameter in the above script? Cleanup parameter is required in both

dbo.DatabaseBackup as well as task scheduler?

sqlcmd -E -S devwinsql6 -d master -Q "EXECUTE dbo.DatabaseBackup @Databases = 'USER_DATABASES', @CleanupTime = '48', @Directory = N'D:\Backup\', @BackupType = 'DIFF'"

sql-server-2012
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

As you noted about `@CleanupTime` in your original question, "If no time is specified, then no backup files are deleted"

You always need to specify `@CleanupTime` if you want the job to delete old files, regardless of where the job is running (task scheduler, sqlcmd, SQL Agent, interactively in SSMS, etc).

0 Likes 0 ·

0 Answers

·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.