Skip to main content

SQL Server database backup using a Batch file

SQL Server database backup using a Batch file


Using the code


Test.bat file
SET curr_dir=%cd%
cd /D E:
IF EXIST TEST ( 
cd TEST
mkdir ScriptTEST DataTEST
cd ScriptTEST
) ELSE ( 
mkdir TEST
cd TEST
mkdir ScriptTEST DataTEST
cd ScriptTEST
)
SET SRC="%~dp0TestBackUpSQL.sql"
SET DEST="TestBackUpSQL.sql"
if not exist %DEST% copy /V %SRC% %DEST%
sqlcmd -i "E:\TEST\ScriptTEST\TestBackUpSQL.sql"

2. In here you need to enter the database name and the back up set will be generated with name+date+time of server.
    TestBackUpSQL.sql file

DECLARE 
@pathName NVARCHAR(512),
@databaseName NVARCHAR(512) 
SET @databaseName = 'Enter Your DataBase Name Here' 
SET @pathName = 'E:\TEST\DataTEST\Enter Your DB Back Up Name Here_' + 
    Convert(varchar(8), GETDATE(), 112) + '_' + 
    Replace((Convert(varchar(8), GETDATE(), 108)),':','-')+ '.bak' 
BACKUP DATABASE @databaseName TO  DISK = @pathName WITH NOFORMAT, 
    NOINIT,  NAME = N'', SKIP, NOREWIND, NOUNLOAD,  STATS = 10
GO












Comments

Popular posts from this blog

Problem: Date Formatting cannot be Changed in Microsoft Excel

In this article, we will learn how to change the date formatting. We will use “Text to Column” wizard to resolve the problem of change the date formatting in Microsoft Excel. Let’s understand the functions: - Text to Column:  “Text to Column” is used for separating the cell content which is depending on the way your data is arranged. You can divide the data on the basis of content in the cell such as space, comma, period, semicolon, etc. Let’s take an example and understand how we can convert the date into Text. We have dates, foramatted as text in column A. Now, we want to convert it into date format.     If we want to convert the formatting into numbers, then we need to follow below given steps:- Select the range A2:A11. Go to Data tab, and click on Text to Columns from the Data tools group.     Covert Text to Columns Wizard – Step1 of 3 dialog box will appear. Select fixed width, and click on Next button.     Skip step-2, and...

The world of work is changing. Artificial intelligence, machine learning, and robots

The world of work is changing. Artificial intelligence, machine learning, and robots well disrupt the job market. How's it going to affect your business and your industry? How can you leverage the digital transformation to improve your success? The five most common skills among the occupations with the greatest prospect of growing in the future are: 📍Judgment and decision making: Considering the relative costs and benefits of potential actions to choose the most appropriate one. 📍Fluency of ideas: The ability to come up with a number of ideas about a topic (the number of ideas is important, not their quality, correctness, or creativity). 📍Active learning: Learning strategies—selecting and using training/instructional methods and procedures appropriate for the situation when learning or teaching new things. 📍Learning strategies: Understanding the implications of new information for both current and future problem-solving and decision-making. 📍Originality: The ability...