Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 517655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:51:23+00:00 2026-05-13T07:51:23+00:00

Using osql command, SSQL backup of a database is created. It is saved to

  • 0

Using osql command, SSQL backup of a database is created.
It is saved to Disk.
Then renamed to match the date of the day backup was taken.
All these files are saved in a single folder all the time.

for example:
Batch1.bat does the following
1) Created backup.bak
2) renamed to backup 12-13-2009.bak (this is done by the combination of % ~ – etc to get the date parameter)

This is now automated to take backup everyday by Task scheduler in Windows.

Can the batch file also be modified to delete backup files older than 7 days? if so, how ?

If it is not possible via batch file, other than manually deleting the files are there any other alternatives to automate the deleting job ?

Thanks in advance, Balaji S

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T07:51:24+00:00Added an answer on May 13, 2026 at 7:51 am

    I’m using the same technique to make a backup from database. I’ve created a stored procedure as follows.

    Create Procedure [dbo].[CreateBackup]
    As
    Begin
    
     Declare @path nvarchar(256),
                @filename nvarchar(256),
       @currentDateTime datetime
    
     Set @currentDateTime = GetDate()
     Set @path = 'C:\DBBackup\'
     Set @filename = @path + Cast(DatePart(month, @currentDateTime) As nvarchar) + Cast(DatePart(day, @currentDateTime) As nvarchar) + '.bak'
    
     Backup Database Foo To Disk = @filename
    
     Set @currentDateTime = DateAdd(day, -3, @currentDateTime)
     Set @filename = 'del ' + @path + Cast(DatePart(month, @currentDateTime) As nvarchar) + Cast(DatePart(day, @currentDateTime) As nvarchar) + '.bak'
    
     Exec xp_cmdshell @filename
    
    End
    

    To use the xp_cmdshell, you should enable it before.

    http://weblogs.sqlteam.com/tarad/archive/2006/09/14/12103.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using osql to run several sql scripts against a database and then I
Using the Redis info command, I am able to get all the stats of
Using import datetime in python, is it possible to take a formatted time/date string
I use sql server 2005 enterprise, windows server 2003. I try execute osql.exe command,
Is there a good tutorial for Creating a database using msbuild ? jean paul
Using Git Bash or MinGW Shell , if I put in a command with
Using SQL Server 2000 Table1 Id date --- ---------- 001 23/01/2012 002 25/01/2012 003
I am interested in using some kind of a command-line utility for SQL Server
I am currently using osql with nant by calling a batch file with arguments.
Using a rails console I create a Model record, then retrieve using a new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.