0% found this document useful (0 votes)
13 views

Scheduling a daily backup and maintenance for SQL Server Express

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Scheduling a daily backup and maintenance for SQL Server Express

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

TECHNICAL DOCUMENT

PDM STANDARD DATABASE BACKUPS AND MAINTENANCE


Modern Server’s tend to have a great deal of resilience built in to them to reduce the risk of data loss.
However in the unlikely event of database corruption or complete hardware failure, it is your responsibility to
ensure that you have a disaster recovery plan in place should you need to restore your Vault and recreate it
from a backup onto replacement hardware.

PDM Standard comprises two key components. The Vault Database, which contains the vault definition,
metadata, references and the history of all files, and the Archive, which contains all the files managed by
PDM (and their previous versions).

When considering a Disaster recovery plan you should be backing up the Database, the Archives and
Archive Server settings. Unless you have a specific SQL Agent for your Backup solution it is likely you will
need to manually create the SQL Backups locally then back up externally along with the Archive folders /
settings also being backed up at the same time.

PDM Standard uses SQL 2014 Express Edition, which does not support “Maintenance Plans” nor the SQL
Server Agent service that we would use to automate these within SQL Server Standard Edition or above.
What this means for you is that it is not possible to automatically schedule backups and maintenance tasks
directly within the Management Studio via said Maintenance Plan.

One possible solution to this is documented below. This is based on two parts that create a backup solution
for your PDM Standard Database but also allows for the creation of other tasks relating to the health of your
Database.

Instead of the maintenance plans:


 Download and install the stored procedure, “expressmaint” into the Master Database

Instead of the SQL Server Agent:


 Create individual SQL Scripts for each task ( Backup, Re-index, Re-organise etc)
 Use Windows Task Scheduler from your SQL Server to run the maintenance tasks at specified
intervals

In this document we explain how to use these two parts to create your database backup and maintenance
solution.

PLEASE NOTE: The ‘expressmaint’ stored procedure was not written by, nor validated by, Solid
Solutions or SOLIDWORKS. Although all tests indicate that this is a valid, widely used and safe
toolset we can accept no responsibility for any data loss or corruption resulting from its
implementation. I would advise creating a dummy vault / vault database to test these tools in your
own environment before implementing into your live Vault Database.

Page 1 of 15
TECHNICAL DOCUMENT

NOTE: In order to allow scripts to be ran via a Scheduled Task the following changes need to be
made in the SQL Management Studio.
 Right Click over the Server name and click Facets

 Under ‘Surface Area Configuration’

o Set OleAutomationEnabled to True


o Set XPCmdShellEnabled values to True
o Click OK

Page 2 of 15
TECHNICAL DOCUMENT

Further changes may also be required based on the success / failure of the Scheduled Task to execute. This
step is discussed later as a troubleshooting exercise.

Installing the stored procedure


 Launch the SQL Management Studio and connect to your PDM Standard Instance using the System
Administrator (sa) User account.
 Under System Databases, right click over Master and select ‘New Query’

 Open the sql_express_Maintenance.sql file into a text editor.


 Select all the text (Ctrl + A) and copy / paste into the Query window.
 Click ‘Execute’ (F5)

Page 3 of 15
TECHNICAL DOCUMENT

 Verify that the Stored Procedure has been added to the Master Database by expanding
Master/Programmability/Stored Procedures

THE STORED PROCEDURE PROVIDES THE FOLLOWING FEATURES:


 Full Database Backup
 Differential Database Backup
 Log Backup
 Housekeeping of backup files
 Database Integrity Checks
 Database Index Rebuilds
 Database index Reorganization
 Report Creation

A complete set of parameters for each feature is included at the rear of this document.

With PDM Standard Databases set to ‘Simple’ Recovery mode by default, we are not concerned about the
Differential Database Backup or Log Backups so will focus on the three scenarios typical to maintaining the
health of a PDM Standard Database: Backup, Re-index and Re-organise

Before starting you should create a Folder on your SQL Server to


contain the Scripts, the Backups and the Report files.

Do not retain the backups on the PDM Server however. Ensure


that your preferred Backup solution is taking these files offline to an
external backup device / media as part of your standard backup
procedures.

Page 4 of 15
TECHNICAL DOCUMENT

Configuration steps: recurring daily full database backup


To configuring a full database backup for you PDM Standard database in SQL Server 2014 Express Edition:

NOTE: You will need to know the name of your Vault Database prior to starting. If you do not know this then
open the PDM Administration tool. Right Click over your Vault Name and choose Properties (You may be
prompted to log in at this stage)

Page 5 of 15
TECHNICAL DOCUMENT

Step 1 Create the Script: Open a text editor and copy the following code into it. Change the Database name
and the paths for the Backup and Report to the folder you just created, then save it to (e.g.)
D:\Backups\EXPRESS scripts\Daily_Full_Backup.sql.

When executed, this will create a full database backup of a database called SWPDM_PDMSeminar to
D:\Backups\Backup, verify the backup and write a report to D:\Backups\Reports. Backups are retained in this
location for 4 days and reports for 1 week:

exec master.dbo.expressmaint
@database = 'SWPDM_PDMSeminar',
@optype = 'DB',
@backupfldr = 'D:\Backups\Backup',
@reportfldr = 'D:\Backups\Reports',
@verify = 1,
@dbretainunit = 'days',
@dbretainval = 4,
@rptretainunit = 'weeks',
@rptretainval = 1,
@report = 1

Step 2 On the Server, locate and open the Task Scheduler by clicking on Start menu and typing ‘Schedule
Tasks’

Step 3 Click Create Basic Task to start the Scheduled Task Wizard.

Page 6 of 15
TECHNICAL DOCUMENT

Step 4 Type a name for the task.

Step 5 Choose Daily from the scheduling options.

Page 7 of 15
TECHNICAL DOCUMENT

Step 6 Click Next, specify the information about the time to run the task. Set Start time to an appropriate
value when the load on the PDM database is low, set the Recur every option to 1 day, and then click Next.

Step 7 Choose Start a program from the task to perform list, and then click Next.

Page 8 of 15
TECHNICAL DOCUMENT

Step 8 Click Browse, browse to SQLCMD.exe (for SQL Express 2014 you can find it here - C:\Program
Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\SQLCMD.EXE)

Step 9 Type the following content to the Add arguments text box (changing script path to what you created
earlier and including your SQL Instance name (e.g PDMServer\PDMSTD), then click Next:

-S <SERVERNAME\INSTANCE> -i "D:\Backups\EXPRESS Scripts\Daily_Full_Backup.sql"

Step 10 Select the checkbox to Open the Advanced Properties for this task and then click Finish.

Page 9 of 15
TECHNICAL DOCUMENT

Step 11 Verify that he user account linked to the task is a Windows User account that is a SysAdmin for your
Database. This should be the User who installed PDM / SQL Express as they will have been added as a
SysAdmin automatically.

Step 12 Click OK. If prompted, supply the password for the account again.

Step 13 Test the created task by right-click on it and select Run. A command prompt windows named
SQLCMD has to be opened while the task is running. Check the created backup file and the log files.

Page 10 of 15
TECHNICAL DOCUMENT

If the task fails, try to run the task command manually in a command prompt window. If you see a message
like this

Msg 15281, Level 16, State 1, Server CERBERUS, Procedure sp_OACreate, Line 1
SQL Server blocked access to procedure 'sys.sp_OACreate' of component 'Ole Autom
ation Procedures' because this component is turned off as part of the security c
onfiguration for this server. A system administrator can enable the use of 'Ole
Automation Procedures' by using sp_configure. For more information about enablin
g 'Ole Automation Procedures', search for 'Ole Automation Procedures' in SQL Ser
ver Books Online.
Msg 50000, Level 16, State 1, Server CERBERUS, Procedure expressmaint, Line 113
Database SWPDM_PDMSeminar is invalid or database status is not ONLINE
Msg 15281, Level 16, State 1, Server CERBERUS, Procedure sp_OADestroy, Line 1
SQL Server blocked access to procedure 'sys.sp_OADestroy' of component 'Ole Auto
mation Procedures' because this component is turned off as part of the security
configuration for this server. A system administrator can enable the use of 'Ole
Automation Procedures' by using sp_configure. For more information about enabli
ng 'Ole Automation Procedures', search for 'Ole Automation Procedures' in SQL Se
rver Books Online.

Then you will need use the SQL Management Studio to enable ‘Ole Automation Procedures’ using the
following query
USE master
GO
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'Ole Automation Procedures', 1;
GO
RECONFIGURE WITH OVERRIDE
GO
EXEC sp_configure 'xp_cmdshell', 1
GO
RECONFIGURE WITH OVERRIDE
GO
EXEC sp_configure 'show advanced options', 0
GO
RECONFIGURE;
GO

Page 11 of 15
TECHNICAL DOCUMENT

Additional Maintenance tasks.

Many tables in the file SOLIDWORKS® PDM file vault database contain indexes – to ensure data is found
efficiently when lookups are done by various database operations. Microsoft® SQL server automatically
maintains these indexes whenever insert, update, or delete operations are made to the underlying data.
Over time as you perform a lot of file operations in the vault - for example after an upgrade where a lot of
records may have been modified, or performed a migration where many new records were added - the
various database table indexes becomes scattered. This is similar to how a hard drive can become
fragmented. Using variations of the Backup script we can schedule tasks to rebuild or reorganize the
indexes. If the indexes are very fragmented, this operation may improve general performance with
searching, browsing etc. in the file vault.

SOLIDWORKS recommends rebuilding the file vault database indexes at least once a month to improve
overall performance. In cases of larger databases and more activity - more frequent rebuilds such as once
per week may prove beneficial.

Rebuilding the indexes is a bit more database intensive (compared to reorganize) and could take longer to
complete so it should not run as frequently. It’s difficult to give an exact recommendation how often you
should reorganize or rebuild the indexes because it depends on the vault usage, if a lot of data is added
frequently, then you should reorganize more often. We will schedule the re-organise to be a weekly task with
the Re-indexing done monthly.

Note that the time it takes to complete the operations depend on the size of the database and how
fragmented the indexes currently are. It is possible to run it while the vault is in use, but the overall
performance might be affected while the maintenance plan is running. You may wish to schedule the
operation to run later in the day when less activity is done in the vault.

Page 12 of 15
TECHNICAL DOCUMENT

Configuration steps: recurring Weekly Re-Organise

Step 1 Create the Script: Open a text editor and copy the following code into it then save it to e.g.
D:\Backups\EXPRESS scripts\REORGANISE_Indexes.sql and, as before, changing the Database name to
match your own.

exec master.dbo.expressmaint
@database = 'SWPDM_PDMSeminar',
@optype = 'REORG',
@reportfldr = 'D:\Backups\Reports',
@rptretainunit = 'weeks',
@rptretainval = 1,
@report = 1

This will run the reorg task and create a log file in the Reports directory which will be retained for one week.

Step 2 Create Scheduled Task as before, selecting this script instead and setting the schedule to be Weekly
at a day / time of your preference. (I have selected midnight on a Saturday)

Page 13 of 15
TECHNICAL DOCUMENT

Configuration steps: recurring Monthly Re-Index

Step 1 Create the Script: Open a text editor and copy the following code into it then save it to e.g.
D:\Backups\EXPRESS scripts\REINDEX_Indexes.sql and, as before, changing the Database name to match
your own.

exec master.dbo.expressmaint
@database = 'SWPDM_PDMSeminar',
@optype = 'REINDEX',
@reportfldr = 'D:\Backups\Reports',
@rptretainunit = 'weeks',
@rptretainval = 1,
@report = 1

This will run the reindex task and create a log file in the Reports directory which will be retained for one
week.

Step 2 Create Scheduled Task as before, selecting this script instead and setting the schedule to be Weekly
at a day / time of your preference. (I have selected every month on the last day of the month)

Page 14 of 15
TECHNICAL DOCUMENT

STORED PROCEDURE COMPLETE PARAMETERS

Parameter Required Default Description

@database Yes None The target database for the maintenance operation. Valid values are a single
database name, ALL_USER which will process all user databases and
ALL_SYSTEM which will process all system databases

@optype Yes None The type of maintenance operation to be performed. Valid values are:
 DB - Full Database Backup
 DIFF - Differential Database Backup
 LOG - Log Backup
 CHECKDB - Database Integrity Check
 REINDEX - Rebuild all indexes
 REORG - Reorganize all indexes

@backupwith No Null Specify additional backup options as documented in BOL for the BACKUP WITH
command

@backupfldr No Null The base folder to write the backups to. Sub folders will be created for each
database

@verify No 1 Indicates whether to verify the backup file.


Valid values are 1 and 0 with 1 = TRUE and 0 = FALSE

@verifywith No Null Specify additional verify options as documented in BOL for the VERIFY WITH
command

@dbretainunit No Null The unit of measure for the @dbretainval parameter. Valid values are minutes,
hours, days, weeks, months and copies. The combination of these two
parameters determines how long or how many copies of old backup files are
kept

@dbretainval No 1 The time period or number of copies of old backups to keep

@report No 1 Indicates whether to produce a report of the maintenance carried out.


Valid values are 1 and 0 with 1 = TRUE and 0 = FALSE

@reportfldr No Null The folder where maintenance reports are written to if @report = 1

@rptretainunit No Null The unit of measure for the @rptretainval parameter. Valid values are minutes,
hours, days, weeks, months and copies. The combination of these two
parameters determines how long or how many copies of old reports are kept

@rptretainval No 1 The time period or number of copies of old reports to keep

@checkattrib No 0 Indicates whether to check the archive bit on a backup file before deleting it. This
is a safety check to prevent deletion of files that have not been backed up onto
tape.
Valid values are 1 and 0 with 1 = TRUE and 0 = FALSE

@delfirst No 0 Indicates whether to delete old backups prior to doing the current backup. This is
not advisable but can be useful if disk space is limited.
Valid values are 1 and 0 with 1 = TRUE and 0 = FALSE

Page 15 of 15

You might also like