Click here to Skip to main content
12,698,012 members (26,291 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


5 bookmarked

SQL Server Database Backup by using Batch File (Updated Version)

, 15 Feb 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
This tip briefly explains how to use batch file to do SQL data backups.


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.

Figure 01

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.

Figure 02

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:

Figure 03

Let’s refer to Figure 03, you can set Date format of the backup file name.

Figure 04

Now look at Figure 04.

Please check your Date Format and change the code if it has a different format.

Set Time Format:

Figure 05

Let’s refer to Figure 05, you can set the Time format of the backup file name.

Figure 06

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.

Coding again!!!

Figure 07 

In Figure 07, I set backup file folder path.

Figure 08

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.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Charitha Athukroala
Systems / Hardware Administrator
Sri Lanka Sri Lanka
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionOr simpli use DOFF.EXE for getting formatted datetime Pin
Member 399871318-Feb-14 6:25
memberMember 399871318-Feb-14 6:25 
AnswerRe: Or simpli use DOFF.EXE for getting formatted datetime Pin
Charitha Athukroala18-Feb-14 19:03
memberCharitha Athukroala18-Feb-14 19:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170118.1 | Last Updated 15 Feb 2014
Article Copyright 2014 by Charitha Athukroala
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid