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
sherlock1Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

É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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Powerful Yet Easy-to-Use Network Monitoring

Identify excessive bandwidth utilization or unexpected application traffic with SolarWinds Bandwidth Analyzer Pack.

É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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.