• Status: Solved
  • Priority: Medium
  • Security: Private
  • Views: 50
  • Last Modified:

Backup three SQL express databases, keep last 4 days. removing older backups

Hi Experts,

We have a server running MS Express SQL server, and databases are set with the simple recovery model and we are backing up three databases with a batch file script as follows:

SQlCmd -E -S SQLServerA -Q "BACKUP DATABASE [SSAdmin] TO DISK='C:\DB_Backups\SSAdmin.bak'"
SQlCmd -E -S SQLServerA -Q "BACKUP DATABASE [SST] TO DISK='C:\DB_Backups\SST.bak'"
SQlCmd -E -S SQLServerA -Q "BACKUP DATABASE [TAPlusRepository] TO DISK='C:\DB_Backups\Current\TAPlusRepository.bak'"

However we would like to keep 4 days worth of copies on disk of the databases (for all 3 DB's) and automatically remove the older backups. The intention is to set this up on a daily schedule in windows task manager. ideally appending the current date to each of the backup files names each time the script is run. Any recommendations on how this can be done?

Thanks
0
sherlock1
Asked:
sherlock1
  • 3
  • 2
  • 2
2 Solutions
 
Éric MoreauSenior .Net ConsultantCommented:
You should use already made scripts like https://ola.hallengren.com/sql-server-backup.html

And see the notes to schedule the tasks: https://ola.hallengren.com/frequently-asked-questions.html
0
 
sherlock1Author Commented:
Thanks for those weblinks which look useful, although I was hoping to make use of the existing script if possible?
0
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
Ola's scripts need SQL Server Agent to run the jobs and SQL Express doesn't have SQL Agent.
You can use Powershell to delete old files. Check this article. Just create a Windows Task to run the script and schedule it.
0
Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

 
Éric MoreauSenior .Net ConsultantCommented:
this is exactly why I have provided the link to the FAQ which one of the question is "How do I get started with the SQL Server Maintenance Solution on SQL Server Express?"
1
 
sherlock1Author Commented:
Thanks all for the feedback. ok so the Ol's scripts look good, however the powershell script looks like it could be a better  option in my case to delete the old files.
Is it possible to append the date to the file names in the current backup script? - if these needs to be a separate questions no worries i can create a new one
0
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
Yes, you can append the date and time to the file name. Check the GETDATE() function for that. You might need to format the output to give you the result that you expect.
0
 
sherlock1Author Commented:
Thanks a lot for your help with this.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now