Need procedure to delete .bak

  • Hi ,

    I had scheduled backups in Express edition 2008 using cmd and taskmanager. But I wantedto have an automated process to delete the .bak files rather doing manually. Please suggest me some steps or procedure.

  • You could try using xp_cmdshell 😉

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • I did but failed on it... Can you please clarify me on what steps to be involved...

  • xp_delete_file is an undocumented extended procedure. Google it for parameters and usage.

    Please fully understand the risk involved when using undocumented procedures before implementing them in any environment.

    ______________________________________________________________________________________________
    Forum posting etiquette.[/url] Get your answers faster.

  • Check for something like this. If you have problems, it might be a permissions problem.

    EXEC xp_cmdshell 'DEL "C:\My\Full\Path.bak" /Q';

    GO

    I wouldn't advice to use undocumented procedures on a production environment, but it's up to you.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Hi,

    I found the below link which describes useful undocumented stored procedures. Does it mean to be good to use

    EXECUTE xp_delete_file 0|1, 'file_name'

  • stillconfused (7/23/2013)


    Hi,

    I found the below link which describes useful undocumented stored procedures. Does it mean to be good to use

    EXECUTE xp_delete_file 0|1, 'file_name'

    Which link?

    As I said, there are some risks involved in using undocumented stored procedures. These procedures might be helpful but might be removed or changed without prior advice. Is up to you.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Worth checking this link - contains a part about file cleanup;

    http://ola.hallengren.com/sql-server-backup.html

    Cheers

    Vultar

  • Another option if you don't want to mess around with undocumented SQL commands, would be to look into using the DOS command FORFILES. At my previous job, I had batch files (same as your cmd) that would fire a backup using SQLCMD, then clean up old BAKs and TRNs with FORFILES.

    Jason

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply