Lumension® KnowledgeBase

Article Number:
627

Date Created:
04/28/2011

Last Updated:
01/18/2017

Article Type:
How-To Procedures

Performing database backups for SQL Express using Windows Task Scheduler

Description

Product:

General Information

Versions:

Lumension Endpoint Management and Security Suite (LEMSS)
Lumension Scan
Lumension Endpoint Security (LES) Device and Application Control

Summary:

This article details the procedure to automate database backups for SQL Express using Windows Task Scheduler.

Details

PROCEDURE

  1. Obtain SQL Management Studio Express from Microsoft. Free download is here.
  2. Login using Administrator credentials (Administrator has system admin over the SQL2005 server by default)
  3. Expand Databases from the Object Explorer, select the desired databases
  4. Right-click and select Tasks then Back Up…
  5. Select the appropriate database backup options from the dialogue
  6. Press 'Ctrl+Shift+F' to save the script options to a file, and save it to a known location, preferably on the local server.
  7. Edit the script file to reflect the following:
    BACKUP DATABASE [DatabasetoBackup] TO DISK = N'C:\backup\sql\DatabasetoBackup.bak' WITH NOFORMAT, NOINIT, NAME = N'Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10
    GO

    ...where 'DatabaseToBackup' is the name of the desired database, listed above in Step 7. You may also want to add the database name to the 'NAME' statement in the command, eg PLUS-Database-Backup. Also note that the machine user that SQL Express is running under (Usually NETWORK SERVICE by default) needs write/modify permissions to the directory your database backup file will be located. C:\backup\sql\ in the example above.
  8. Test this script by logging into SQL Management Studio as the backup service account, and run the script. Any problems or permissions errors will show up here and you can ensure your scheduled backups will run successfully in the future.
  9. Open Windows Task Scheduler (Control Panel then Scheduled Tasks) and create a new Scheduled Task.
  10. Browse to C:\Program Files\Microsoft SQL Server\90\Tools\Binn\ and select SQLCMD.exe
  11. Name the job and select the schedule (Daily, Weekly, monthly, etc)
  12. Edit the Start Time and desired days of the week (for a Weekly schedule) or desired start time (for Daily schedule)
  13. Enter a username and password to execute the scheduled task. This must be a Windows local or domain user, not a SQL user.
  14. Check the Advanced Permissions checkbox.
  15. In the Run dialog, append the existing SQLCMD command with the following:
    "-S [SERVER] -U dbbackup -P [PASSWORD] -i C:\PathToScript\NameOfBackupScript.sql"

    Your final command will look like this:
    "C:\Program Files\Microsoft SQL Server\90\Tools\Binn\SQLCMD.EXE" -S [SERVER] -E -i C:\backup\sql\SQLExpressBackup.sql
     
    • Note the location of the quote marks surrounding the command path. They should not include the command arguments.
    • The '-E' switch implies Trusted Authentication, which can only be used by the local Administrator account, which is automatically a member of the sysadmins group in SQL. You can also add another Windows account to the sysadmins group and use it as the backup user.
    • For a local database server, use –S localhost
  16. Adjust Security permissions for the job so only trusted users have access, since the SQL backup users' password is stored in plaintext.

You can verify the backup job runs successfully by right-clicking on the Job in the Scheduled Tasks folder and click Run. Note: If the job is set to run as the locally logged on user, you will see a command prompt pop-up window during the job process.

12345678910
Current rating: 4