Sql-server – Backup SQL server db issue: delete old backup files

sql server

I tried to use sqlmaint.exe tool to back up a database on a remote PC. Here is an example of backup:

sqlmaint.exe -S remoteSQLServer\SQLInstance -U username -P pwdxxx -D myDB 
   -BkUpMedia DISK -BkUpDB C:\MSSQL_Backups -DelBkUps 3days ...

Here I specified to delete backups older than 3 days. However, the job seems not deleting old bak files on the remote PC(where the SQL server sits). The remote PC has Windows 2008 Server. I also set the C:\MSQL_Backups as shared network drive for EnyOne as owner. My understanding is that the job will delete any bak files older than 3 days. Not sure what I missed?

By the way, the job runs at a box with SQL server 2005 installed.

Best Answer

I dont have experience with the sqlmaint.exe. especially on a windows server 2008. Install the newest MS SQL 2005 patches and try to run the command again. May be this helps.

Do you want to run the backup job regularly? You can create a maintenance plan with the sql management studio. In the Maintenance plan you can create a cleanup job which deletes the old backups.

the maintenance plans are a very good and stable way to create backups of your ms sql 2005 db's.

You also should set more restrictive access to the network share. else everyone can create a new database from your backups or just delete them for fun.

You could also take a look at the tool forfiles.exe. With this tool it's possible to search for files which meets some specified criteria and delete them (or do whatever you want).

Have a nice day.