Microsoft SQL Server Analysis Services Analysis Services Data-Base Backup and Restore Authored by: AVINASH KUMAR SINGH COMPANY: PAXCEL TECHNOLOGIES PVT.LTD
ANALYSIS SERVICE SHORT INTRODUCTION Analysis Services is an online analytical processing (OLAP) database, a type of database that is highly optimized for the kinds of queries and calculations that are common in a business intelligence environment. It does many of the same things that a relational database can do, but it differs from a relational database in many respects. In most cases, it will be easier to develop your BI solution by using Analysis Services in combination with a relational database such as Microsoft SQL Server than by using SQL Server alone. Analysis Services certainly does not replace the need for a relational database or a properly designed data warehouse. SQL SERVER ANALAYSIS SERVICES DATABASE BACKUP Administrators can back up an Analysis Services database to a single Analysis Services backup file (.abf), regardless of size of the database. If the Analysis Services database contains remote partitions, the remote partitions can also be backed up. When you back up a database with remote partitions, all the remote partitions on each remote server are backed up to a single file on each of those remote servers respectively. Therefore, if you want to create those remote backups off their respective host computers, you will have to manually copy those files to the designated storage areas. Backing up an Analysis Services database produces a backup file whose contents vary depending upon the storage mode used by the database objects. This difference in backup content results from the fact that each storage mode actually stores a different set of information within an Analysis Services database. For example, multidimensional hybrid OLAP (HOLAP) partitions and dimensions store aggregations and metadata in the Analysis Services database, while relational OLAP (ROLAP) partitions and dimensions only store metadata in the Analysis Services database. Because the actual contents of an Analysis Services database vary based on the storage mode of each partition, the contents of the backup file also vary. The following table associates the contents of the backup file to the storage mode used by the objects. Storage Mode Multidimensional MOLAP partitions and dimensions Multidimensional HOLAP partitions and dimensions Multidimensional ROLAP partitions and dimensions Tabular In-Memory Models Tabular Direct-Query Models NOTE Contents of backup file Metadata, source data, and aggregations Metadata and aggregations Metadata Metadata and source data Metadata only Backing up an Analysis Services database does not back up the data in any underlying data sources, such as a relational database. Only the contents of the Analysis Services database are backed up. 1
When you back up an Analysis Services database, you can choose from the following options: Whether to compress all database backups. The default is to compress backups. Whether to encrypt the contents of the backup files and require a password before the file can be unencrypted and restored. By default, the backed up data is not encrypted. Restoring an Analysis Services Database Administrators can restore an Analysis Services database from one or more backup files. Note If a backup file is encrypted, you must provide the password specified during backup before you can use that file to restore an Analysis Services database. During restoration, you have the following options: You can restore the database using the original database name, or you can specify a new database name. You can overwrite an existing database. If you choose to overwrite the database, you must expressly specify that you want to overwrite the existing database. You can choose whether to restore existing security information or skip security membership information. You can choose to have the restore command change the restoration folder for each partition being restored. Local partitions can be restored to any folder location that is local to the Analysis Services instance to which the database is being restored. Remote partitions can be restored to any folder on any server, other than the local server; remote partitions cannot become local. Security Note For each backup file, the user who runs the restore command must have permission to read from the backup location specified for each file. To restore an Analysis Services database that is not installed on the server, the user must also be a member of the server role for that Analysis Services instance. To overwrite an Analysis Services database, the user must have one of the following roles: a member of the server role for the Analysis Services instance, or a member of a database role with Full Control (Administrator) permissions on the database to be restored. Note After restoring an existing database, the user who restored the database might lose access to the restored database. This loss of access can occur if, at the time that the backup was performed, the user was not a member of the server role or was not a member of the database role with Full Control (Administrator) permissions. 2
IMPLEMENTION TO SHOW HOW ANALYSIS SERVICE DATABASE IS ATTACHED AND DETACHED Detach Analysis Services Database in Command Mode <Detach xmlns="http://schemas.microsoft.com/analysisservices/2003/engine"> <Object> <DatabaseID>test2</DatabaseID> </Object> </Detach> Detach Analysis Services Database in GUI Mode Follow the following steps for detaching database in GUI mode right click on the database it will pop-up a dialogue box there is option to detach as shown below click on the detach option to detach. 3
Attach Analysis Services Database in Command Mode <Attach xmlns="http://schemas.microsoft.com/analysisservices/2003/engine"> <Folder>E:\CROOKY_WORKS\Analysis_Services\test2.0.db\</Folder> <ReadWriteMode xmlns="http://schemas.microsoft.com/analysisservices/2008/engine/100">readwri te</readwritemode> </Attach> Attach Analysis Services Database in GUI Mode 1. Now to attach the database fist we have to set the browse option to browse for folder from where we are going to attach database.go to properties of the analysis services and click on it. 4
2. Now click on the check box Show advanced option and at the first option in the properties pane we will get AllowedBrowsingFolders click on that now append your path of the database which you want to attach after putting for e.g. C:\Program_Files\Microsoft_SQL_Server\MSAS10_50.MSSQLSERVER\OLAP\Backup\ C:\Program Files\Microsoft_SQL_Server\MSAS10_50.MSSQLSERVER\OLAP\Log E:\CROOKY_WORKS\Analysis_Services\test2.0.db 5
3. Now go the database right click on the button and click on the attach button as shown 4. Here you can see that directory appears which we added previously in properties of analysis services.please note that it does not require restart of analysis service SQL server engine 6
5. Now click on the ok button by selecting the directory where your database resides which will make the folder available in the first dialogue box click OK to attach and you are done. 6. Click on the refresh button to show the database on the list of databases. 7
Backing up Analysis Services Database in Command Mode <Backup xmlns="http://schemas.microsoft.com/analysisservices/2003/engine"> <Object> <DatabaseID>test2</DatabaseID> </Object> <File>E:\CROOKY_WORKS\Analysis_Services\test2.0.db\test2.abf</File> <AllowOverwrite>true</AllowOverwrite> <Password>paxcel@123</Password> </Backup> Backing up Analysis Services Database in GUI Mode 1. Right Click on the Analysis Service Database in dialogue box Backup as shown. 8
2. You can change the location of the backup of analysis service database by click on the browse button and directories which are available in browsing list,there is option to overwrite the existing backup on the same location you can also specify password to encrypt your backup when you are done with the above mentioned scenario go ahead and click on OK button to initiate the backup of analysis service database in GUI mode. 9
Scheduling Backup of Analysis Services Database in Command Mode through SQL Server Agent USE [msdb] GO /****** Object: Job [Analysis service_backups] Script Date: 04/24/2013 23:52:27 ******/ BEGIN TRANSACTION DECLARE @ReturnCode INT SELECT @ReturnCode = 0 /****** Object: JobCategory [Database Maintenance] Script Date: 04/24/2013 23:52:27 ******/ IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE name=n'database Maintenance' AND category_class=1) BEGIN EXEC @ReturnCode = msdb.dbo.sp_add_category @class=n'job', @type=n'local', @name=n'database Maintenance' IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback END 10 DECLARE @jobid BINARY(16) EXEC @ReturnCode = msdb.dbo.sp_add_job @job_name=n'analysis service_backups', @enabled=1, @notify_level_eventlog=0, @notify_level_email=0, @notify_level_netsend=0, @notify_level_page=0, @delete_level=0, @description=n'analysis service_backups', @category_name=n'database Maintenance', @owner_login_name=n'avinash-pc\avinash', @job_id = @jobid OUTPUT IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback /****** Object: Step [SAAS_BACKUP] Script Date: 04/24/2013 23:52:28 ******/ EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobid, @step_name=n'saas_backup', @step_id=1, @cmdexec_success_code=0, @on_success_action=1, @on_success_step_id=0, @on_fail_action=2, @on_fail_step_id=0, @retry_attempts=0, @retry_interval=0, @os_run_priority=0, @subsystem=n'analysiscommand', @command=n'<backup xmlns="http://schemas.microsoft.com/analysisservices/2003/engine"> <Object> <DatabaseID>test2</DatabaseID> </Object> <File>E:\CROOKY_WORKS\Analysis_Services\test2.0.db\test2.abf</File> <AllowOverwrite>true</AllowOverwrite> <Password>paxcel@123</Password> </Backup> ',
@server=n'localhost', @database_name=n'master', @flags=0 IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback EXEC @ReturnCode = msdb.dbo.sp_update_job @job_id = @jobid, @start_step_id = 1 IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback EXEC @ReturnCode = msdb.dbo.sp_add_jobschedule @job_id=@jobid, @name=n'saas_job', @enabled=1, @freq_type=4, @freq_interval=1, @freq_subday_type=1, @freq_subday_interval=0, @freq_relative_interval=0, @freq_recurrence_factor=0, @active_start_date=20130424, @active_end_date=99991231, @active_start_time=0, @active_end_time=235959, @schedule_uid=n'328e1b34-d23f-4bbb-89ca-3499d79e2512' IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobid, @server_name = N'(local)' IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback COMMIT TRANSACTION GOTO EndSave QuitWithRollback: IF (@@TRANCOUNT > 0) ROLLBACK TRANSACTION EndSave: GO 11
Scheduling Backup of Analysis Services Database in GUI Mode through SQL Server Agent 1. Connect To SQL Server Management Studio and then Browse to SQL Server Agent and right click on the new job. 12
2. A new job will appear in the pane and name it as Analysis Service_Backups define owner of the job in this case here owner is AVINASH-PC\AVINASH.Choose category database maintenance and describe your job in description text box and the browse to steps. 13
3. Click on the new button in the steps. 14
4. Name the step and in the type drop down select SQL Server Analysis Service Command and in Run as select SQL Server Agent Service Account and in the Server textbox write your server name and in the command text box enter the following command which will be run by the job <Backup xmlns="http://schemas.microsoft.com/analysisservices/2003/engine"> <Object> <DatabaseID>test2</DatabaseID> </Object> <File>E:\CROOKY_WORKS\Analysis_Services\test2.0.db\test2.abf</File> <AllowOverwrite>true</AllowOverwrite> <Password>paxcel@123</Password> </Backup> And then click on ok button. 15
5. Now schedule your job accordingly name the job schedule and scheduling type and its frequency and time and click ok. 16
6. Now at this point we are done refresh your job pane to check the new job which we have added. Restore Analysis Services Database in Command Mode <Restore xmlns="http://schemas.microsoft.com/analysisservices/2003/engine"> <File>C:\Program Files\Microsoft SQL Server\MSAS10_50.MSSQLSERVER\OLAP\Backup\test2.abf</File> <DatabaseName>test2</DatabaseName> <AllowOverwrite>true</AllowOverwrite> <Password>paxcel@123</Password> <DbStorageLocation xmlns="http://schemas.microsoft.com/analysisservices/2008/engine/100/100">e:\ CROOKY_WORKS\Analysis_Services\test2.0.db\</DbStorageLocation> </Restore> 17
Restore Analysis Services Database in GUI Mode 1. Right click on the database button and dialogue box will show restore option click on it. 2. Click on the browse option to browse the backup file. 18
3. Select the path where we have taken backup and name backup file having extension.abf as shown and click OK. 19
4. In restore database write your database name and data directory path from the list of available data directories available in browse section since we have deleted over database so we are opting for Allow database overwrite option.there is option for overwrite security information u can check it also but it is not mandatory select copy all option and the give the password at the encryption part as shown which was given when to database was being backed.then click on OK button to complete the restore process. 20