I've been researching about how to delete a specific backup file through an SQL query, but I only find results about "deleting backups older than a date". That is not what I want. I want to keep old backups, but I want to be able to delete a specific backup by its ID.
I can easily remove the entries from the msdb tables and its restore history for a given backup, but I would like to be able to delete the files as well through an SQL query (I know their full path, as it is stored in the database), so that they don't keep wasting space in the disk.
The procedure "xp_delete_file" doesn't seem to allow to delete a specific file.
I assume that if there is a procedure to delete old files, there should be some way to delete a specific file. Please don't worry about security here.
You are free to delete . bak files as you please. They are not involved the actual running of SQL Server itself and wont prevent it starting up. I would suggest you create and schedule a maintenace plan in SQL Server Management Studio.
To remove one or more rows in a table: First, you specify the table name where you want to remove data in the DELETE FROM clause. Second, you put a condition in the WHERE clause to specify which rows to remove. If you omit the WHERE clause, the statement will remove all rows in the table.
The Delete command in SQL is a part of the Data Manipulation Language, a sub-language of SQL that allows modification of data in databases. This command is used to delete existing records from a table. Using this, you can either delete specific records based on a condition or all the records from a table.
May be old but might help someone. xp_delete_file can be used to delete specific backup file. Try the code below:
EXECUTE master.dbo.xp_delete_file 0,N'c:\backup\backup1.bak'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With