BACKING UP A DATABASE



Similar documents
GENERATING SQL SCRIPTS FOR STORED PROCEDURES, FUNCTIONS, VIEWS & TRIGGERS

Backing Up CNG SAFE Version 6.0

Microsoft SQLServer Restore / Redirected Restore Procedure

HELP DOCUMENTATION E-SSOM BACKUP AND RESTORE GUIDE

KEYWORDS InteractX, database, SQL Server, SQL Server Express, backup, maintenance.

If you have questions or need assistance, contact PCS Technical Services using the contact information on page 10.

Backup and Recovery in MS SQL Server. Andrea Imrichová

Assured PackOut Best Practices: Create a Back-Up

Exam : Transition Your MCTS on SQL Server 2008 to MCSA: SQL Server 2012, Part 2. Title : The safer, easier way to help you pass any IT exams.

Microsoft SQL Server Scheduling

How to Copy A SQL Database SQL Server Express (Making a History Company)

Restoring Sage Data Sage 200

MS SQL Server Database Management

1.0 Doors.Net Database Backup Microsoft SQL Server 2005 Studio Express

Microsoft SQL Server 2005 How to Create and Restore Database (GRANTH3) Manually

HELP DOCUMENTATION E-SSOM BACKUP AND RESTORE GUIDE

Installing LearningBay Enterprise Part 2

SELF SERVICE RESET PASSWORD MANAGEMENT BACKUP GUIDE

PCSchool SQL Backup Tech Tip. SQL Backup Tech Tip. Created in version /9

Microsoft SQL Server 2005 How to Create and Restore Database (GRANTH3) Manually

This means that any user from the testing domain can now logon to Cognos 8 (and therefore Controller 8 etc.).

How to Set Up a Shared SQL Express Database with ManagePro 7 Standard version

How to Backup and FTP your SQL database using E2.

A Tutorial on SQL Server CMPT 354 Fall 2007

SalonTouch SQL and.net Database Backup Instructions Updated 10/16/2006

How To Backup A Database In Navision

2.3 - Installing the moveon management module - SQL version

QUANTIFY INSTALLATION GUIDE

CRM Setup Factory Installer V 3.0 Developers Guide

Automated backup. of the LumaSoft Gas database

WHITE PAPER: ENTERPRISE SOLUTIONS. Symantec Backup Exec Continuous Protection Server Continuous Protection for Microsoft SQL Server Databases

BrightStor ARCserve Backup for Windows

SonicWALL CDP 5.0 Microsoft Exchange InfoStore Backup and Restore

Norman Secure Backup. SQL Backup Training Guide. Author: Arne Stieghorst Layout: Eva Langballe

The safer, easier way to help you pass any IT exams. Exam : C_HANASUP_1. SAP Certified Support Associate - SAP HANA 1.0.

Backing Up and Restoring the SQL Server 2005 Environment

Notes Transfer instructions INTRODUCTION More information

Auditing manual. Archive Manager. Publication Date: November, 2015

How To Upgrade Your Microsoft SQL Server for Accounting CS Version

SQL Server 2005 Advanced settings

Sitecore Ecommerce Enterprise Edition Installation Guide Installation guide for administrators and developers

SQL Tuning and Maintenance for the Altiris Deployment Server express database.

Upgrading Litium Studio. From version C to 4.3

Version 4.61 or Later. Copyright 2013 Interactive Financial Solutions, Inc. All Rights Reserved. ProviderPro Network Administration Guide.

Backup Assistant. User Guide. NEC NEC Unified Solutions, Inc. March 2008 NDA-30282, Revision 6

Application Server Installation

InformationNOW SQL 2008 Database Backup and Restoration

1 of 10 1/31/2014 4:08 PM

Xopero Centrally managed backup solution. User Manual

PROJECTIONS SUITE. Database Setup Utility (and Prerequisites) Installation and General Instructions. v0.9 draft prepared by David Weinstein

Database Maintenance Guide

4 Backing Up and Restoring System Software

Setting up a database for multi-user access

USING FILERELICATIONPRO TO REPLICATE SQL SERVER

Setup and configuration for Intelicode. SQL Server Express

SQL Server 2008 R2 Express Edition Installation Guide

mylittleadmin for MS SQL Server Quick Start Guide

GO!NotifyLink. Database Maintenance. GO!NotifyLink Database Maintenance 1

How to Backup Your Eclipse.Net Database Automatically. To clearly document a specific automatic SQL database backup method for Eclipse.net.

Hosted File Backup for business. Keep your data safe with our cloud backup service

ACCESSING IBM iseries (AS/400) DB2 IN SSIS

Installation / Backup \ Restore of a Coffalyser.Net server database using SQL management studio

AuditWizard v8. SQL Maintenance

How To Create An Easybelle History Database On A Microsoft Powerbook (Windows)

MSSQL quick start guide

SSO Plugin. J System Solutions. Upgrading SSO Plugin 3x to 4x - BMC AR System & Mid Tier.

Using the Windows XP Backup Wizard. Introduction. Open the Backup Wizard

Basic SQL Server operations

How to Back Up and Restore an ACT! Database Answer ID 19211

MS SQL Server Backup - User Guide

How To Install The Welchallyn Cardioperfect Webstation On A Computer Or Network With A Hard Disk Drive (For A Non-Procedure)

Protecting SQL Server Databases Software Pursuits, Inc.

SAM Server Utility User s Guide

CA ARCserve Backup for Windows

Table of Contents SQL Server Option

RFMS, INC. Reference Library Documentation. Version 10 Conversion Manual. Microsoft SQL

Enterprise PDM - Backup and Restore

National Fire Incident Reporting System (NFIRS 5.0) NFIRS Data Entry/Validation Tool Users Guide

Moving Components of an Amicus Premium Installation

Migrating from SharePoint 2007 to SharePoint

Introduction. There are several bits of information that must be moved:

SQL 2012 Installation Guide. Manually installing an SQL Server 2012 instance

Installing SQL Express. For CribMaster 9.2 and Later

SPI Backup via Remote Terminal

SQL Server Protection Whitepaper

4cast Server Specification and Installation

FaxCore 2007 Application-Database Backup & Restore Guide :: Microsoft SQL 2005 Edition

SQL Backup and Restore using CDP

SonicWALL CDP Local Archiving

InformationNOW SQL 2005 Database Backup and Restoration

Livestock Office Backup Database

Database Server Maintenance Plan

Published. Technical Bulletin: Use and Configuration of Quanterix Database Backup Scripts 1. PURPOSE 2. REFERENCES 3.

About database backups

Optional Lab: Data Backup and Recovery in Windows Vista

vcenter Configuration Manager Backup and Disaster Recovery Guide VCM 5.3

Backup and Restore Back to Basics with SQL LiteSpeed

Hosted File Back-up for business. Keep your data safe with our cloud back-up service

How To Restore Your Data On A Backup By Mozy (Windows) On A Pc Or Macbook Or Macintosh (Windows 2) On Your Computer Or Mac) On An Pc Or Ipad (Windows 3) On Pc Or Pc Or Micro

Backing up and restoring HP Systems Insight Manager 6.0 or greater data files in a Windows environment

Transcription:

BACKING UP A DATABASE April 2011 Level: By : Feri Djuandi Beginner Intermediate Expert Platform : MS SQL Server 2008, Visual C# 2010 Pre requisites: Suggested to read the first part of this document series titled Connecting the SQL Server as the introduction and basic. In this article we are going to learn how to backup a database using SQL Server Management Objects (SMO). Following are the tools used for the program demo: MS SQL Server 2008 Evaluation Edition MS Visual C# 2010 Express There are three types of database backups that commonly performed in the routine database maintenance: full, differential and transaction log backup. This article will not explain the differences and the details of those types, but we will learn how to run the process easily using SMO. Please open the sample program SmoPractice04.zip attached to this document. Please extract the ZIP file into your local computer and open the project file. Try to run the program, and you will find a screen like this. As moving the selection around from one database to another, you will realize that a transaction log backup is not allowed for some databases. That is because the recovery model of the respective database is Simple. As already known, there are three kinds of database recovery model: full, bulk-logged and simple. Each database in the SQL Server instance may have - 1 -

different configurations. To see or change the option, please use the MS SQL Server Management Studio program and select the database followed by opening the Properties menu. The recovery model is set in the Options page as shown in the following picture. The recovery model is chosen based on the purpose and nature of the database. Please read the SQL Server documentation carefully to know the description of these settings and the effects of changing the value. Anyhow, for the sake of this tutorial, it is enough to know that transaction log backup is allowed for full and bulk-logged, and disallowed for the simple one. Don t ask why, please seek the answer by your self. The outcome of a database backup is a backup file, whether written on a disk, tape or other media. A backup file may contain one or several backup sets. For instance on Sunday you do a full backup, and in the week days you do the transaction log backups in the same backup file. The log backup sets will be appended to the original full backup set, so in the file there will be one full backup set and six transaction log backup sets. In the next Sunday, we need to initialize the backup file to empty it and erase the previous backup sets if not, the subsequent backup set will be kept added into the file and it grows rapidly. That s why in the program sample there is an Overwrite Backup Set option to reset the backup file. Of course there are many different strategies to arrange the backup sets whether put in a backup file or spread over multiple files it is really up to the need. As you are ready to backup, simply press the Backup button and a nice progress bar will be sliding to indicate the progress of the backup process. Now stop the program and look into the source code, let us see how the program works. Please be aware, that firstly we need to reference the SMO libraries into the source code. - 2 -

The first line of the Form class contains a constant declaration of the SQL Server instance. This value should be changed according to your SQL Server installation because (local)\sql2k8 is the instance name that specified in my installation. Next is the declaration of the ServerConnection object to specify the connection parameter to the SQL Server; and finally the Server object as the central of the SMO operation. public partial class Form1 : Form private const string INSTANCE_NAME = "(local)\\sql2k8"; private Microsoft.SqlServer.Management.Common.ServerConnection conn = new ServerConnection(INSTANCE_NAME); private Microsoft.SqlServer.Management.Smo.Server server; public Form1() InitializeComponent(); private void Form1_Load(object sender, EventArgs e) try //Login using Windows Authentication conn.loginsecure = true; conn.connect(); server = new Server(conn); As the program is executed, it immediately tries to connect the SQL Server using Windows authentication. This is done by setting the LoginSecure to True, followed by calling the Connect method. Another alternative to connect is to do it using the SQL Server authentication. If you wish to have more explanation on various methods to connect the SQL Server, please read the first article as suggested earlier. The most important part of the program is in the click event of the Backup button. In this script, the Backup object is created and prepared for the device type (in this example is chosen as File). The backup file path and the backup set name are also specified. string dbname = ""; dbname = lvdatabase.selecteditems[0].text; Microsoft.SqlServer.Management.Smo.Backup backup = new Backup(); Microsoft.SqlServer.Management.Smo.Database database = server.databases[dbname]; backup.database = database.name; backup.devices.adddevice(txtbackupfile.text, DeviceType.File); backup.backupsetname = txtbackupset.text; - 3 -

The rest of the script is quite straight forward. It sets the properties of the Backup object according to the options selected, like backup type, log truncation, backup initialization etc. //The backup type: database, files or log if (rbfull.checked) //Full backup backup.action = BackupActionType.Database; backup.incremental = false; else if (rbdiff.checked) //Differential backup backup.action = BackupActionType.Database; backup.incremental = true; else //Log backup backup.action = BackupActionType.Log; if (cbxtruncatelog.checked) backup.logtruncation = BackupTruncateLogType.Truncate; else backup.logtruncation = BackupTruncateLogType.NoTruncate; //append or overwrite media set if (cbxoverwrite.checked) backup.initialize = true; else backup.initialize = false; Please have a try to perform some database backups in some different scenarios. In my experiment, first I do a full backup then a differential backup and lastly the transaction log backup. All is done in the same backup file, so I expect there are three backup sets inside it. To verify the backup results, we can pretend to about restoring the backup file: - 4 -

1. Open the MS SQL Server Management Studio program and select the Restore Database menu. 2. Select the source as From device, and the backup media as File. Locate the backup file just created and press the Contents button. - 5 -

3. The next window opened shows a header of the backup file. The contents confirm my actions earlier that there are three backup sets representing the full, differential and transaction log backup sets respectively. 4. Press the Close button and cancel the database restore because our intention is only to verify. That s all you need to know how to backup a database in SQL Server using SMO. There are more another interesting and easy-to-learn articles in this SMO series. Please continue reading and enjoy! - 6 -