You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SQL Server Express editions do not offer a way to schedule either jobs or maintenance plans because the SQL Server Agent component is not included in these [editions](/sql/sql-server/editions-and-components-of-sql-server-version-15). Therefore, you have to take a different approach to back up your databases when you use these editions.
18
+
SQL Server Express editions don't offer a way to schedule either jobs or maintenance plans because the SQL Server Agent component isn't included in these [editions](/sql/sql-server/editions-and-components-of-sql-server-version-15). Therefore, you have to take a different approach to back up your databases when you use these editions.
18
19
19
20
Currently SQL Server Express users can back up their databases by using one of the following methods:
20
21
@@ -35,15 +36,15 @@ This article describes how to use a Transact-SQL script together with Task Sched
35
36
36
37
You have to follow these four steps to back up your SQL Server databases by using Windows Task Scheduler:
37
38
38
-
### Step 1: Create stored procedure to Back up your databases
39
+
### Step 1: Create stored procedure to back up your databases
39
40
40
41
Connect to your SQL express instance and create sp_BackupDatabases stored procedure in your master database using the script at the following location:
The`sqlcmd`utility lets you enter Transact-SQL statements, system procedures, and script files. In SQL Server 2014 and lower versions, the utility is shipped as part of the product. Starting with SQL Server 2016, `sqlcmd`utility is offered as a separate download. For more information, review [sqlcmd Utility](/sql/tools/sqlcmd-utility).
47
+
The`sqlcmd`utility lets you enter Transact-SQL statements, system procedures, and script files. In SQL Server 2014 and lower versions, the utility is shipped as part of the product. Starting with SQL Server 2016, `sqlcmd`utility is offered as a separate download. For more information, review [sqlcmd Utility](/sql/tools/sqlcmd-utility).
47
48
48
49
### Step 3: Create a batch file using a text editor
49
50
@@ -54,77 +55,79 @@ In a text editor, create a batch file that is named *Sqlbackup.bat*, and then co
54
55
- If you are using SQL authentication, ensure that access to the folder is restricted to authorized users as the passwords are stored in clear text.
55
56
56
57
> [!NOTE]
57
-
> The folder for the `SQLCMD` executable is generally in the Path variables for the server after SQL Server is installed or after you install it as stand-alone tool. But if the Path variable does not list this folder, you can either add its location to the Path variable or specify the complete path to the utility.
58
+
> The folder for the `SQLCMD` executable is generally in the Path variables for the server after SQL Server is installed or after you install it as stand-alone tool. But if the Path variable doesn't list this folder, you can either add its location to the Path variable or specify the complete path to the utility.
58
59
59
-
#### Example 1: Full backups of all databases in the local named instance of SQLEXPRESS by using Windows Authentication.
60
+
#### Example 1: Full backups of all databases in the local named instance of SQLEXPRESS by using Windows Authentication
Similarly, you can make a differential Backup of USERDB by pasting in 'D' for the **@backupType** parameter and a log Backup of USERDB by pasting in 'L' for the **@backupType** parameter.
91
92
92
-
### Step 4: Schedule a job by using Windows Task Scheduler to execute the batch file that you created in step 2
93
+
### Step 4: Schedule a job by using Windows Task Scheduler to execute the batch file that you created in step 2
93
94
94
95
Follow these steps:
95
96
96
-
1. On the computer that is running SQL Server Express, click**Start**, then in the text box type *task Scheduler*.
97
+
1. On the computer that is running SQL Server Express, select**Start** and type **Task Scheduler**in the text box.
97
98
98
-
:::image type="content" source="media/schedule-automate-backup-database/task-scheduler.png" alt-text="Screenshot of the Task Scheduler Desktop app option in the search bar of Start menu." border="false":::
99
-
1. Under **Best match**, click **Task Scheduler** to launch it.
100
-
1. In Task Scheduler, right-click on **Task Schedule Library** and click on **Create Basic task…**.
101
-
1. Enter the name for the new task (for example: SQLBackup) and click **Next**.
102
-
1. Select **Daily** for the Task Trigger and click **Next**.
103
-
1. Set the recurrence to one day and click **Next**.
104
-
1. Select **Start a program** as the action and click **Next**.
105
-
1. Click **Browse**, click the batch file that you created in Step C, and then click **Open**.
106
-
1. Check the box Open the Properties dialog for this task when I click **Finish**.
107
-
1. In the General tab,
108
-
- Review the Security options and ensure the following for the user account running the task (listed under When running the task, user the following user account:)
99
+
:::image type="content" source="media/schedule-automate-backup-database/task-scheduler.png" alt-text="Screenshot of the Task Scheduler Desktop app option in the search bar of Start menu." border="false":::
109
100
110
-
The account should have at least Read and Execute permissions to launch sqlcmd utility. Additionally,
101
+
1. Under **Best match**, select **Task Scheduler** to launch it.
102
+
1. In **Task Scheduler**, right-click on **Task Scheduler (Local)** and select **Create Basic task…**.
103
+
1. Enter the name for the new task (for example: **SQLBackup**) and select **Next**.
104
+
1. Select **Daily** for the Task Trigger and select **Next**.
105
+
1. Set the recurrence to one day and select **Next**.
106
+
1. Select **Start a program** as the action and select **Next**.
107
+
1. select **Browse**, select the batch file that you created in [Step 3](#step-3-create-a-batch-file-using-a-text-editor), and then select **Open**.
108
+
1. Check the box **Open the Properties dialog for this task when I click Finish**.
109
+
1. In the **General** tab,
111
110
112
-
- If using Windows authentication in the batch file, ensure the owner of the task permissions to do SQL Backups.
111
+
- Review the **Security options** and ensure the following for the user account running the task (listed under **When running the task, user the following user account:**)
113
112
114
-
- If using SQL authentication in the batch file, the SQL user should have the necessary permissions to do SQL Backups.
113
+
The account should have at least Read and Execute permissions to launch sqlcmd utility. Additionally,
115
114
116
-
- Adjust other settings according to your requirements.
115
+
- If using Windows authentication in the batch file, ensure the owner of the task permissions to do SQL Backups.
116
+
117
+
- If using SQL authentication in the batch file, the SQL user should have the necessary permissions to do SQL Backups.
118
+
119
+
- Adjust other settings according to your requirements.
117
120
118
121
> [!TIP]
119
-
> As a test, run the batch file from Step C from a command prompt that is started with the same user account that owns the task.
122
+
> As a test, run the batch file from [Step 3](#step-3-create-a-batch-file-using-a-text-editor) from a command prompt that is started with the same user account that owns the task.
120
123
121
124
### Requirements
122
125
123
126
Be aware of the following requirements when you use the procedure that is documented in this article:
124
127
125
-
- The Task Scheduler service must be running at the time that the job is scheduled to run. We recommend that you set the startup type for this service as**Automatic**. This makes sure that the service will be running even on a restart.
128
+
- The Task Scheduler service must be running at the time that the job is scheduled to run. We recommend that you set the startup type for this service as**Automatic**. This makes sure that the service will be running even on a restart.
126
129
127
-
- You must create sufficient amount of space on the drive where the backups are written. We recommend that you clean old files in the Backup folderregularly to make sure that you do not run out of disk space. The script doesn't contain the logic to clean up old files.
130
+
- You must create sufficient amount of space on the drive where the backups are written. We recommend that you clean old files in the Backup folderregularly to make sure that you don't run out of disk space. The script doesn't contain the logic to clean up old files.
0 commit comments