Create a database backup job using SQL Server Management Studio

Original: Creating Database Backup Jobs Using SQL Server Management Studio

A SQL Server job is nothing more than executing a specified script at a specified time. Here is how to create a job backup database with SSMS (SQL Sever 2008).

 

(0) Assume that the database you want to back up already exists before creating the job; secondly, you have already started the SQL Sever agent (usually closed)

 

(1) Create SQL Server Agent job

1 New job

 

(1.1) Create a new job and output general information

2 Job title

As shown above: Enter the job name (such as: BackupJobTest), where the owner and category are default, enter the description (just like writing code to write comments, benefit others and self)

 

(1.2) Setting job execution steps

3 New steps

 

Click the Step Properties tab in the "Select Page" on the left, and click the "New" button

3 Job Step Properties

 

In the job step properties window, select the type (T-SQL), select the database to be backed up, and paste the debugged SQL backup script. Since I am also writing it for the first time, an example is posted here, and readers can refer to and modify it by themselves:

--将SQL脚本赋值给变量
declare @SqlBackupDataBase as nvarchar(1000)
set @SqlBackupDataBase=N'BACKUP DATABASE YourDataBaseName TO DISK = ''E:\DBBackup\YourDataBaseName-'+
CONVERT(varchar(11),GETDATE(),112)+REPLACE(CONVERT(varchar(12),GETDATE(),108),':','') + ' .bak ''' 
-- backup file format: YourDataBaseName-20140626233410.bak 
print  @SqlBackupDataBase  -- print it out (for debugging convenience, it can be omitted) 
exec sp_executesql @SqlBackupDataBase  -- call system stored procedure and execute SQL

Note: The third parameter of the CONVERT() function is the time style ID; the colon in the time is replaced with the REPLACE() function (because the file name cannot contain this character in Windows)

Time format and ID comparison table reference: W3school

 

(1.3) Set the job execution plan

 

4. New plan

 

In the Schedules tab, click the New button to create a new schedule:

 

4. New plan 2

 

After the setting is completed, click the "OK" button, and the other three properties "Alarm", "Notification", "Target" can be set by yourself if necessary, and will not be described here.

 

After completing the plan settings, click the "OK" button of the superior, and the job is created.

 

(2) Manually verify the correctness of job execution

 

Right-click the job just created under the job node ("BackupJobTest" in the figure), select 'Job Start Step (T)'

 

5 Execute job 1

 

The execution result is as follows, indicating success:

 

5 Execute the job

 

Click "View History (V)" to view the log:

 

6

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325279457&siteId=291194637