I’m writing this tip to explain a simple way to make a SQL Database Backup Batch File. I already posted 2 articles to do SQL Server Database backups by using Batch file. But I could encountered a few difficulties. Therefore, now I’m coming up with a new solution. And also, this is a simple solution too.
My Previous Articles
My last 2 articles (check the URLs of the instructions) are a little bit complex and sometimes, they won’t work well (they have dependencies). Therefore I came up with a new solution.
Using the Code
Before you wish to use my database backup batch file, please run (double click on) Date_Time.bat file. This batch file will help you to look into your computer (Server computer of the database) date and time formats. This is a very important thing, therefore please check your date and time format and keep a note about its’ formats.
Please check Figure 01, you can see Date and Time Formats there. Please note it, because these formats are using by SQL Database Backup Script Batch File.
Let’s go to the SQL Database Backup Batch Script.
In Figure 02, the code segment I’m trying to create TestDB_Data_Backup folder is in E:\ drive of the computer. You can change the drive.
Set Date Format:
Let’s refer to Figure 03, you can set Date format of the backup file name.
Now look at Figure 04.
Please check your Date Format and change the code if it has a different format.
Set Time Format:
Let’s refer to Figure 05, you can set the Time format of the backup file name.
Now look at Figure 06. Time format is “HH:MM:SS.milsec”
Please check your Time Format and change the code if it has a different format.
In Figure 07, I set backup file folder path.
I already commented everything in the code. Therefore, I have nothing to explain here.
I hope this tip will help you to do a simple backup process.