SQL Server 2019 won´t delete

Wolfgang Lehr 1 Reputation point
2021-08-16T19:08:52.097+00:00

Hello Support,
I am using a Sql Server2019 (SQL Server 15.0.2080.9). Under Maintenance Plans, i created a task which should clean up und delete files older than three days. If i execute the task it says succes but nothing happened. No file withe the extension trn or bak is deleted in the directory.
What is the failure?
What can I do to solve this Problem,because up to now i have delete manually 1 time a week ohtherwise i get into problems withe the the disk space.

Greetings Wolfgang

Developer technologies | Transact-SQL
Developer technologies | Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
SQL Server | Other
{count} votes

12 answers

Sort by: Most helpful
  1. Tom Phillips 17,781 Reputation points
    2021-08-16T20:42:36.04+00:00

    The backup cleanup task does not delete based on the files, it deletes based on the backup log. If the log does not exist for the backup file, it does not delete it. If you moved the files from another location, it will never delete them.

    What happens if you run:
    EXECUTE master.dbo.xp_delete_file 0,N'{yourdirectory}',N'bak',N'{3daysago}'


  2. Wolfgang Lehr 1 Reputation point
    2021-08-16T21:30:11.423+00:00

    Hello,
    I do it as Maintenance Cleanup.
    EXECUTE master.dbo.xp_delete_file 0,N'D:\SQL Sicherung',N'bak',N'2021-08-13T23:29:57'

    0 comments No comments

  3. Wolfgang Lehr 1 Reputation point
    2021-08-16T21:31:56.253+00:00

    sorry forget one sign!
    EXECUTE master.dbo.xp_delete_file 0,N'D:\SQL Sicherung',N'bak',N'2021-08-13T23:31:31',1

    0 comments No comments

  4. CathyJi-MSFT 22,406 Reputation points Microsoft External Staff
    2021-08-17T09:03:26.02+00:00

    Hi @Wolfgang Lehr ,

    Please check below to resolve the issue;

    1.Use . for the file extension or bak without a dot, both of which I have found work if other issues are correct too.
    2.Make sure that the path is simply the path to where your backups are but with a backslash on the end.
    3.Please make sure the file location is correct.
    4.Did your agent service account has the modify permission for the files.

    123887-screenshot-2021-08-17-170008.jpg

    If it is not work, check other solutions from the similar thread SQL Maintenance Cleanup Task Working but Not Deleting.


    If the response is helpful, please click "Accept Answer" and upvote it, as this could help other community members looking for similar thread.


  5. Wolfgang Lehr 1 Reputation point
    2021-08-18T21:37:38.347+00:00

    The Basic settings are checked first. Nothing worked until now!

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.