Read without ads and support Scribd by becoming a Scribd Premium Reader.
1
Backup MS SQL Server data
Summary
This article explains how to backup MS SQL Server data with Backup4all
using a scheduled task.
On this page:

How to create a batch file that stops the MS SQL Server
How to create a batch file that restarts the MS SQL Server
How to configure a backup for the MS SQL Server data using Backup4all

Details

The database files are locked by the MS SQL Server. In order to backup
these files and avoid data corruption, it is necessary to perform these
actions:

1. Stop the MS SQL Server.
2. Perform the backup.
3. Restart the MS SQL Server.

To automate the process described above, a backup needs to be configured
in Backup4all that will automatically stop the MS SQL Server, perform the
backup and restart the MS SQL Server. The MS SQL Server will be
stopped/restarted using some commands from a batch file loaded by
Backup4all before/after the backup.

How to create a batch file that stops the MS SQL Server

MS SQL Server can be stopped using the sc.exe command line program. It is recommended to stop the MS SQL Server during off-hours or in week-ends. Here is the syntax for calling sc.exe:

Syntax
sc[ServerName] stop [ServiceName] [ServiceArguments]
Parameters
ServerName: Specifies the name of the remote server on which the
service is located. The name must use the Universal Naming
Convention (UNC) format ("\\myserver"). To run SC.exe locally,
Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
2
ignore this parameter.
ServiceName: Specifies the service name to be stopped.

To automate the startup sequence of MS SQL Server a batch file that calls
sc.exe needs to be created and added as a “before action” in the backup job
scheduled in Backup4all. Below is an example of commands that can be used
to stop the MSSQLServer and SQLServerAgent services on a local computer
(code also contains a sequence that sets a delay between each commands,
to ensure the services were stopped):

sc stop sqlserveragent

@ECHO OFF
SET NUM=1
:LOOP
IF %NUM% == 6000 GOTO END1
SET /A NUM=NUM+1
GOTO LOOP
:END1
@ECHO ON

sc stop mssqlserver

@ECHO OFF
SET NUM=1
:LOOP2
IF %NUM% == 6000 GOTO END2
SET /A NUM=NUM+1
GOTO LOOP2
:END2
@ECHO ON

These commands will be saved in a batch file (stop_sql.bat) that will be
executed by Backup4all before starting the backup.
To create the batch file:

1. Go toS t a r t->Run type notepad and pressO k. In the window that
opens selectF i le->Save as and name the files t o p _ s q l .b a t

2. Add the commands needed to stop the MS SQL service following the
example above (if is a local computer simply copy/paste the code
above).

When the scheduled backup will start, the commands from the batch file will
be executed, stopping the MS SQL Server. Only after that, the backup
process will start. When the backup process has finished, the MS SQL Server
must be restarted. You can set a second batch file to be automatically
executed after the backup in order to restart the MS SQL Server.

Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
3
How to create a batch file that restarts the MS SQL Server
MS SQL Server can be restarted using the sc.exe command line program.
Here is the syntax for calling sc.exe:
Syntax
sc[ServerName] start[ServiceName]
Parameters
ServerName: Specifies the name of the remote server on which the

service is located. The name must use the Universal Naming
Convention (UNC) format ("\\myserver"). To run sc.exe locally,
ignore this parameter.

ServiceName: Specifies the service name to be started.
ServiceArguments: Specifies service arguments to pass to the
service to be stopped. Note that this option is not used when
the command “stop” is issued.

To automate the restart sequence of MS SQL Server, a batch file that calls
sc.exe needs to be created and added as an “after action” in the scheduled
backup job in Backup4all. Below is an example of commands that can be
used to restart the MSSQLServer and SQLServerAgent on a local computer:

sc.exe start mssqlserver

@ECHO OFF
SET NUM=1
:LOOP
IF %NUM% == 6000 GOTO END
SET /A NUM=NUM+1
GOTO LOOP
:END
@ECHO ON

sc.exe start sqlserveragent

These commands will be saved in a batch file (start_sql.bat) that will be
executed by Backup4all after the backup process.
To create the batch file:

1. Go toS t a r t->Run type notepad and pressO k. In the window that
opens selectF i le->Save as and name the files t a r t _ s q l .b a t

2. Add the commands needed to start the MS SQL service following the
example above (if is a local computer simply copy/paste the code
above).

If the backup is finished without errors, the MS SQL Server will be restarted.
Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
Search History:
Searching...
Result 00 of 00
00 results for result for
  • p.
  • Notes
    Load more