Upload
alessandro-pilotti
View
4.138
Download
3
Embed Size (px)
DESCRIPTION
Drupal 7 provides great support for SQL Server as a backend and there are a lot of reasons why you'll like this combination. This webcast starts by showing you how to install a Drupal 7 web site with a SQL Server Express backend in a few clicks with WebPi and then discusses how to create and manage databases, logins and users using SQL Server Management Studio (SSMS) and the command line (SQLCMD).
Citation preview
Drupal on IIS with a SQL Server
databaseAlessandro Pilotti
@alexpilottiMVP ASP.NET / IIS
MCSD, MCAD, MCSE, MCDBA, MCTRed Hat Certified Engineer
SQL Server and DrupalDrupal offers the option to choose the database
backend No more limited to MySQL
Drupal 7 provides great support for SQL Server 2008 All major modules nowadays use PDO and portable SQL Works as well with SQL Server 2008 R2 and 2012
MS provides a PHP PDO driver for SQL Server
There’s a free Express edition Limited to 10GB per database
SQL Azure
SQL Server for MySQL devs / admins
SQL Server is a relational database like MySQL
You can write SQL queries (SELECT, INSERT, UPDATE DELETE)Like for every other DBMS there are some tricky
differencesE.g. MySQL is more forgiving in the GROUP BY clause
Management tools:Management Studiosqlcmd.exe
Edition comparisonExpress (free)
Contains everything you need for the average Drupal site
Limited to 10GB database size, 1GB memory, 1 socket / 4 cores
Web
Standard
Enterprise
Feature comparison charts: http://msdn.microsoft.com/en-us/library/cc645993.aspx
SQL Server useful features Online backup (included also in express edition!)
Full Differential Log
Replication Min. standard edition, web and express only as subscribers
Mirroring Min. standard edition
Log shipping Min. web editition
Great profiling tools UI tools in standard edition
InstancesYou can install multiple isolated instances on the
same server
Only one can be the default unnamed instance
All the others are named
It means that you connect to the server with a name:E.g. yourserver\SQLEXPRESS
DatabasesSQL Server instances, like MySQL, contain
multiple databases
Every Drupal site has usually a separate databaseOr you can use table_prefix of course
Databases can be moved to different instancesdetached from oneAttached to the other
Databases can be put individually offline
Authentication Login
Credentials needed to connect to the instance Windows account (integrated)
No password, best security approach SQL server (mixed mode)
Classic username and password Instance wide roles can be assigned to logins
Database users Specific to each database Logins are mapped to database users Object level (table, etc) permissions are granted to users
Roles A collection of permissions Users can be assigned to roles
Main database roles db_owner
Can do everything on the database (not the instance!)
db_datareaderCan run SELECT on any table / view
db_datawriterCan run INSERT, UPDATE, DELETE
db_ddladminCan run any DDL command (CREATE, DROP, etc)
How to create a databaseVery easily with Management Studio
Via command line:sqlcmd –S .\SQLEXPRESS –E
create database drupal7
create login drupal7 with password = 'Passw0rd’
go
use drupal7
go
create user drupal7 for login drupal7
exec sp_addrolemember db_owner, drupal7
go
Drupal 7 site with SQL Server using WebPi
With just a few click using WebPiAdd also: SQL Server 2008 R2 Management Studio Express
with SP1
Drupal 7 site with SQL Server w/o WebPi
Create web site
Download and install SQL Server PDO driver:http://www.microsoft.com/en-us/download/details.
aspx?id=20098
Enable PHP extensions php_sqlsrv and php_pdo_sqlsrvDrush @drupal7 dl sqlsrvcd your_drupal_site_pathxcopy /i sites\all\modules\sqlsrv\sqlsrv includes\
database\sqlsrv
Database managementSchedule proper backup policy
With or without transaction log
Schedule maintenance tasks Update statisticsReindexShrink database
Backup policySchedule a proper backup policy, e.g.:
Full database backup every nightLog every 5’ (or more, depending on your db)This way you will not lose more than 5’ of data!
To be able to backup the transaction log, set the database recovery model toFull or Bulk-LoggedDefault is Simple
BackupUse Management Studio
or
BACKUP DATABASE [drupal7] TO DISK = N'c:\backup\drupal7_backup.bak' WITH INIT, NAME = N'drupal7-Full Database Backup’
Store backups on a remote file share!To do that run the SQL service with an ad hoc userCreate the same user on the server with the
network share
Set recovery model Management Studio (very easy)
T-SQL (e.g. sqlcmd):USE [master]
GO
ALTER DATABASE [drupal7] SET RECOVERY FULL WITH NO_WAIT
How to schedule a backup The express edition of SQL Server doesn’t have a UI to schedule
backups and other tasks
We can use the windows scheduler to schedule: Full backup every night Log backup every 5’ Delete of old backups every night
schtasks.exe /create /tn drupal7_db_backup_full /tr "sqlcmd -S .\SQLExpress -E -i c:\backup\drupal7_backup_full.sql" /sc DAILY /ru Administrator /rp /st 02:00:00
Useful task commands:
schtasks.exe /run /tn drupal7_db_backup_full
schtasks.exe /delete /tn drupal7_db_backup_full
To schedule a log backup
E.g.: every 15’:schtasks.exe /create /tn drupal7_dbbackup_log /tr
"sqlcmd -S .\SQLExpress -E -i c:\backup\drupal7_backup_log.sql" /sc MINUTE /MO 15 /ru administrator /rp
Restore a database Best done via Management Studio
Or manually (here’s a complete sample): RESTORE DATABASE [drupal7] FROM DISK = N'c:\backup\
drupal7_backup_full_2012_05_15_14_53_06_470.bak' WITH FILE = 1, NORECOVERY
GO RESTORE DATABASE [drupal7] FROM DISK = N'c:\backup\
drupal7_backup_diff_2012_05_15_14_53_09_867.bak' WITH FILE = 1, NORECOVERY
GO RESTORE LOG [drupal7] FROM DISK = N'c:\backup\
drupal7_backup_log_2012_05_15_14_53_13_913.trn' WITH FILE = 1, NORECOVERY
GO RESTORE LOG [drupal7] FROM DISK = N'c:\backup\
drupal7_backup_log_2012_05_15_14_53_15_200.trn' WITH FILE = 1 GO