Why re-inventing the wheel, use Ola Hallengren's backup script; most DBA do that.
https://ola.hallengren.com/sql-server-backup.html
SQL Database Automatic Backups
I want to configure a maintenance plan to back up about 20 databases each week. This I did already but as the databases are backed up weekly the files in the backup location will become numerous and hard to find the backup I want to use. I found and modified a script that will create a folder with the current date/time on the backup drive. The problem I am having is getting the backups to automatically save into the folder created with the current date as that folder name will be different each week. I have tried to create separate agent jobs for each task (folder creation, database backup) but it always fails on the backup job. I saw one answer online that suggestion a T-SQL query can't be used to do this but I would have to create a procedure but that has not been successful for me yet. Looking for ideas, solutions, or to draw on community experience.
2 answers
Sort by: Most helpful
-
Olaf Helper 44,136 Reputation points
2021-11-18T14:40:09.16+00:00 -
Tom Phillips 17,731 Reputation points
2021-11-18T18:03:03.457+00:00 As Olaf said, forget maintenance plans and use Ola's scripts. You will be much happier in the end.