Thursday, April 25, 2019

Multi server PowerShell script to backup SQL Server databases automatically

Multi server PowerShell script to backup SQL Server databases automatically

Eighty-two percent of the enterprises expect the number of databases to increase over the next twelve months. An increase in data volumes can have negative effects on the performance of databases. Think about the storage requirement and backup strategy to meet the Recovery Time Objective and the Recovery Point Objective. RPO and RTO are two of the most important parameters of a disaster recovery or data protection plan.

Database backup overview

Let us take a look at some of the most common ways to back up the SQL Server database, and some of the best and most feasible solutions for data protection and disaster recovery scenarios.
Let us focus on handling huge volumes of data using various techniques and/or methodologies. Some of us may have questions on how to decide the best-suited backup strategies for our environments; on automating and managing SQL Server database backup; on whether we should automate the database backup process using T-SQL, SSIS, or PowerShell or some other tool or technique; what the data recovery and protection plans available are; whether the SQL engine provides the required capabilities to schedule a job and run it across multiple servers; whether customization options are available; whether we have a robust method to perform backup activity.
Let find out the answers to those questions. I’m sure you’ll not be disappointed!

Getting started

A database administrator must make sure that all databases are backed up across environments. Understanding the importance of database backup is critical. Setting the right recovery objective is vital, and hence, we need to consider the backup options carefully. Configuring the retention period is another area to ensure integrity of the data.
Backing up data regularly is always a good strategy on the one hand, and on the other, we must regularly test the backup copies to ensure that they’re tested and validated for smooth working of the systems, and to prevent any sort of corruption or, under extreme conditions, a disaster. The well-tested SQL Server database backup script that we’re going to discuss provides an essential safeguard for protecting the (critical) data stored in the SQL Server databases. Backups are also very important to preserve modifications to the data on regular basis.
With a well-configured SQL Server database backup, one can recover data from many failures such as:
  • Hardware failures
  • User-generated accidents
  • Catastrophic disasters
Let us now look at the various options and methodologies which can be used to initiate a database backup.
There are different ways to back-up a database:
  • SSMS – Backups can be performed manually using SQL Server Management Studio
  • SQL Agent Job – Using a T-SQL script for backup
  • Using Maintenance Plan – SSIS Packages
  • SMO (SQL Server Management Objects) – PowerShell Scripts
  • Using ApexSQL Backup
This article talks about the use SQL Server Management Objects (SMO) and its advantages in making life easier. SMO is a complete library of programmatically accessed objects that enable an application to manage a running instance of Microsoft SQL Server Services. PowerShell is used to create this SQL Server databases backup script using the SMO classes. The script backs up specific or all databases of an instance to the backup location, or a local/remote/network share, and manages the backup files as per the retention period set.
Let’s look at how other DBAs in the industry are tackling massive data growth, what their most important goals are, and strategy to backup SQL Server databases automatically. Let us also look at some of the third party tools for backup management.
The first three options are very well discussed in the How to backup multiple SQL Server databases automatically article. Now that the first three points are already covered, let’s look at the use of the PowerShell SMO options with ApexSQL Backup. We’ll learn about how we can increase the database performance and eliminate downtime to give users the best experience possible using ApexSQL Backup. Today’s challenge is to give customers the most visually appealing and contextually rich insights possible in a user-friendly interface. ApexSQL has all the rich features and has the intelligence to manage and deploy a SQL backup plan to many SQL instances. A good way to start this process is to test the feasibility by downloading the free trial version of the tool.

Initial preparation

The goal of many organizations is to manage the backup of SQL Server databases automatically. We’ll go through the necessary steps to create the PowerShell SQL Server database backup script shortly. We can list any number of SQL servers and databases using the script. We can also create multiple jobs to initiate backup on multiple servers.
Pre-requisites
  • Enable XP_CMDSHELL
  • EXEC sp_configure 'show advanced options', 1;  
    GO  
    -- To update the currently configured value for advanced options.  
    RECONFIGURE;  
    GO  
    -- To enable the feature.  
    EXEC sp_configure 'xp_cmdshell', 1;  
    GO  
    -- To update the currently configured value for this feature.  
    RECONFIGURE;  
    GO
  • Before you proceed, set the execution policy on PowerShell
  • Load the necessary modules if they’re not loaded automatically
  • Add full rights on file share or local or remote location where you’d like the backups stored
  • Add default permissions to BACKUP DATABASE and BACKUP LOG to members of the sysadmin fixed server role and the db_owner and db_backupoperator fixed database roles
The following code section details
  • Handling multiple SQL Server databases automatically
  • Managing local or remote database backups
  • Email notification upon completion of every successful backup
  • Setting the retention period
  • Scheduling automated jobs

Constructing the PowerShell script

Let us walk through the script, step-by-step, along with looking at the details of the setup and configuration of the script. The complete script can be found in Appendix (A)
Step 1: Declare the variable, and load the SMO library

Step 2: Define the email functionality

Step 3: Looping through databases

Step 4: Initiate Database backup and Email body preparation

Step 5: Manage database backup file

Let’s now go about using this script to back up the database by scheduling an SQL Job. Using Object Explorer, expand the SQL Server Agent. Right-click on Jobs. Select New job.

In the General tab of the window that pops up, enter the name, owner and the description for the job. Let’s call this SQLBackupCentralizedJob.

In the Steps tab, click on New to configure the job.
In the General tab,
  • Mention the step name as SQLBackup,
  • Set the job type to Transact-SQL script (T-SQL)
  • Select the master database in the Database box.
  • Paste the following script that will be used for this job in the Command box. Click OK.
    master..xp_cmdshell 'PowerShell.exe F:\PowerSQL\MSSQLBackup.ps1'
  • Click OK.


We have now successfully created the job.

Right-click on SQLBackup_CentralizedJob and run it.


We can check the backup folder for the backup files; it would tell us the progress, like so:
Invoke_SQLDBBackup -SQLServer HQDBT01 -BackupDirectory f:\SQLBackup -dbList "SQLShack_Demo,ApexSQLBAckup" -rentention 3 -Mail Yes
Invoke_SQLDBBackup -SQLServer HQDBSP18 -BackupDirectory f:\PowerSQL -dbList "SafetyDB,rtc,rtcab1" -rentention 3 -Mail Yes



Verify the email

Back up multiple SQL databases with ApexSQL Backup

ApexSQL Backup is a third-party software solution that can be used to define and/or manage the backup/restore processes and perform various maintenance operations. The tool is capable of performing the backup of SQL Server databases automatically.
The backup of multiple SQL databases can be configured in a few simple steps:
Step 1: Register the server
  • Select Home tab
  • Click Add button
    • Enter the SQL Server
    • Select authentication type
  • Click Ok


Step 2: The Backup Configuration Wizard
Now you should see all the databases that are available on that server. Click on the Backup button on the Home ribbon tab to configure the jobs.

The main tab of the backup wizard is for backup settings and defining the backup configuration. This section has three options
  1. Backup
    1. Select the SQL Server from the drop-down list; you can select the server you’d like to configure the backup for
    2. In the Databases, browse and check the intended databases for backup
    3. Click OK
      Next, set the backup type, defining the backup location and its standards
    4. Select the type of the database backup
    5. To have a better experience, set the Job name and the Job description. It’s usually a good practice to do so.
    6. Click on the Add button in Destination group, and set the backup destination path, or configure custom naming rules.

    7. Browse for the destination path in the Folder text box.
    8. In the Filename box, configure the format of the backup filename by clicking on the corresponding tags—you can select from the seven available tags. Each of those can be included in the backup filename. Check the summary and click OK if everything is configured as required. You can click on ApexSQL defaults to reset the configuration.
    9. Click OK

      Now, let us schedule the backup job using the Schedule wizard. This wizard is invoked using the overflow (…) button.
    10. In the wizard, set the frequency, daily frequency and activity schedule of database backup as desired. Check the summary at the bottom of the page to confirm that the configuration is done as required. Click OK to save changes in the Schedule Wizard.
    11. Click OK.

  2. The Advanced tab
    We can add various media, verification, compression and encryption options along with encryption settings in the Advanced tab of the wizard.
    1. Set the retention period in the cleanup tab to clean-up the database backup files
    2. Click OK.
  3. Notification
    Use the notification tab to set the type of alerts you would like an email notification sent for.
    1. Use Options tab to select the notification events
    2. Click the Add button to add recipient details
    3. Click OK to commit.

  4. After the configuration is complete, click OK to confirm the same. This would create backup jobs for the databases. We performed one configuration, but it created jobs for each of the databases we selected. It couldn’t get any easier! Of course, you can make individual modifications to create exceptions.

    Select the Schedules tab in main application form to check the jobs we created. Just like selecting the databases, you can check the box on the header to select all the schedules we created. Right-click on any of the schedules to bring up the context menu. Select Run now. The corresponding jobs will be executed immediately, irrespective of the schedule settings—this is like a force-run.
    The result column shows the final status of the database backup jobs—the status of each of the jobs that have the schedule information in the central repository. If you’d like to perform an action on any one job, you can select the relevant checkbox and click on the action, such as Run now, or Disable.

    The activities tab, the central dashboard to view the job activities performed through ApexSQL Backup.
    The message column gives user-friendly information, which is helpful in troubleshooting the backup jobs. The failures for another transaction log backup job are resulted by the inaccessible disk drive, as seen bellow.

    The History tab shows the backup history for the database selected from the Server pane on the left.

    Let us now check for the backup files that got created in the folder we specified as the backup path. We can easily recognize the backup files by their custom filenames. The creation date and time are also available. Notice the file names marked in red.

    Also, here’s the summary email notification (Success and Failure)


    Wrapping Up

    In an environment that relies on a SQL Server backup database script, or a managed native backup methodology, one could try using PowerShell scripts using SMO. We also saw how to backup SQL Server databases automatically using scripts. PowerShell scripts are mostly sequential in nature, unless they are enhanced in order to run parallel processes. However, the latter takes significant effort to define and configure. ApexSQL Backup makes managing these processes much simpler because of its built-in options to handle these tasks in a more efficient manner.

    References

    Appendix (A)

    Function Get-SQLDBBackup 
    { 
     param (
        
            [Parameter (Mandatory=$true,Position=0)][String]$SQLServer,  
            [Parameter(Mandatory=$true,Position=1)][String]$BackupDirectory, 
            [Parameter(Mandatory=$true,Position=2)][String]$dbList,
            [Parameter(Mandatory=$true,Position=3)][int]$retention,
            [Parameter(Mandatory=$true,Position=3)][String]$Mail) 
    
    #loading SMO library
      
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | Out-Null 
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoExtended") | Out-Null 
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.ConnectionInfo") | Out-Null 
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoEnum") | Out-Null 
    
    
    # Setting the backup data in yyyyMMdd_HHmmss that is 20170619_130939
      
    $BackupDate = get-date -format yyyyMMdd_HHmmss 
    
    Function sendEmail  
    
     { 
    param($from,$to,$subject,$smtpServer)  
    [string]$recipients="$to"
    $body = New-Object System.Net.Mail.MailMessage $from, $recipients, $subject, $body 
    $smtpServer = $smtpServer
    $smtp = new-object Net.Mail.SmtpClient($smtpServer)
    $smtp.Send($body)
    
     } 
    
    
    #Define the SMO class library
       
    $Server = new-object ("Microsoft.SqlServer.Management.Smo.Server") $SQLServer
    #Iterating the SQL Server databases of a given instance
       
    foreach ($Database in $Server.databases) 
        { 
            # Teh 
            foreach($db in $DbList.split(",")) 
            { 
                if($Database.Name -eq $db) 
                { 
                    $DatabaseName = $Database.Name 
    
                    $DatabaseBackup = new-object ("Microsoft.SqlServer.Management.Smo.Backup") 
                    $DatabaseBackup.Action = "Database"
                    $DatabaseBackup.Database = $DatabaseName 
                    #Set the directory for backup location 
                    $BackupFileName=$BackupDirectory + "\" + $DatabaseName + "_" + $BackupDate + ".BAK"
                    #write-host $BackupFileName
                    $DatabaseBackup.Devices.AddDevice($BackupFileName, "File") 
                    
                     try 
                       {
                       Write-Progress -Activity "Please wait! Backing up SQL databases... " -Status "Processing:" -CurrentOperation "Currently processing:  $DatabaseName" 
                       $DatabaseBackup.SqlBackup($Server)  
                       $body=@"
    Notification that a $DatabaseName is backed up! successfully with date and time stamp $BackupDate
    "@
                        }
                       catch 
                       {
                       $body=@"
    Notification that a $DatabaseName is backed failed! with an error message $_.Exception.Message
    "@
      }
    
                    write-host $status
                               
                    if ($Mail ='Yes') { 
                    
                      sendEmail -To "pjayaram@sqlshack.com" -Subject " $SQLServer -> $DatabaseName Backup Status" `
                       -From "pjayaram@sqlshack.com" -Body $body  `
                       -smtpServer "hqmail.abc.com"
                            
                        }
                    # Preparing the UNC path for the database backup file handling
                    # fetching the drive letter. First argument is that starting position in the string, and the second is the length of the substring, starting at that position. 
                    $drive=$BackupFileName.substring(0,1)
                    $len=$BackupDirectory.length
                    #write-host $len
                    #Selecting the string portion of a directory that is fetching the string starting from the character posittion
                    $path=$BackupDirectory.substring(3,$len-3)
                    #write-host \\$SQLServer\$drive$\$path
                    # Listing the files which is older than 3 minutes in this caseon a server. It can be local or remote location
                    $file=get-ChildItem \\$SQLServer\$drive$\$path -recurse -Filter $DatabaseName*.bak | Select-object LastWriteTime,directoryname,name |where-object {$_.LastWriteTime -lt [System.DateTime]::Now.Addminutes(-$rentention)}
                    #Iterating each file and remove the file with remove-item cmdlet
                    foreach($f in $file)
                    {
                    $filename=$f.directoryname+'\'+$f.name
                    write-host 'File deleted' $filename
                    remove-item $filename -Force
                    }
                #$DatabaseBackup | select LogicalName, Type, Size, PhysicalName | Format-Table -AutoSize
                } 
            } 
        } 
    }
      
     Get-SQLDBBackup -SQLServer HQDBT01 -BackupDirectory f:\SQLBackup -dbList "SQLShack_Demo,ApexSQLBackup" -rentention 3 -Mail Yes
     Get-SQLDBBackup -SQLServer HQDBSP18 -BackupDirectory f:\PowerSQL -dbList "SafetyDB,rtc,rtcab1" -rentention 3 -Mail Yes
    
     

How to backup multiple SQL Server databases automatically

How to backup multiple SQL Server databases automatically

In situations with few databases, maintaining the regular backup routine can be achieved easily, either with the help of a few simple scripts, or by configuring a SQL Server agent job that will perform the backup automatically. However, if there are hundreds of databases to manage, backing up each database manually can prove to be quite time-consuming task. In this case, it would be useful to create a solution that would back up all, or multiple selected SQL Server databases automatically, on the regular basis. Furthermore, the solution must not impact the server performance, or cause any downtime.

There was a common misconception that some objects in the database get locked during backup operations, thus denying full access to the database. The misconception was based on the situations where some of the user transactions got blocked during the database backup operations. All backup operations in SQL Server are online operations and they are not supposed to cause locks on user objects. However, taking a database backup does take some system resources. Each database backup operation requires both disk reads and disk writes. This induces certain pressure to the IO subsystem, and if not configured correctly, can further cause timeouts for some user transactions. For example, backing up a database to the same disk drive where data files are located could cause the timeout errors, especially on the disk drives with low number of spindles. In this case, the system has to:
  • Read and write to the database files for all user transactions
  • Read the database files in order to create backup file
  • Write the read data for the backup file to the same disk drive
On high traffic servers, the pressure on the IO system in this case is simply too high. Therefore, a timeout error is returned for some of the transactions. If multiple larger databases are backed up, the backup process may last for quite some time. To prevent the timeouts, it is highly recommended to plan all backup operations while there is low activity on the server, and to avoid using same disk for the database and backup files.
In this article, three different ways of backing up multiple SQL databases will be demonstrated:
  • creating a SQL Server agent job,
  • configuring a maintenance plan
  • and the solution provided by ApexSQL Backup schedules.

Writing T-SQL backup scripts

Before we start configuring a backup job for the SQL Server agent, it is necessary to create backup script that will be used for the job. There is an option to use common backup command with each database that needs to be backed up. In this case, the following script can be used:
--Script 1: Backup selected databases only

BACKUP DATABASE Database01
TO DISK = 'C:\Database01.BAK'
BACKUP DATABASE Database02
TO DISK = 'C:\Database02.BAK'
BACKUP DATABASE Database03
TO DISK = 'C:\Database03.BAK'

This script is quite simple but it contains hard coded names for the backup files. The script can be used for the one-time jobs, but as soon as it is included in a regular schedule, the old backup files will simply be overwritten by the new ones. The most elegant way to prevent this situation, is to include the creation date in the backup filename. This can be easily achieved with the dynamic T-SQL script:
--Script 2: Include creation date in backup filenames

--1. Variable declaration

DECLARE @BackupFileName varchar(1000)

--2. Specifying backup path and filename

SELECT @BackupFileName = (SELECT ' E:\Backup\AdventureWorks2008_' + 
convert(varchar(500),GetDate(),112) + '.bak') 

--3. Executing the backup command

BACKUP DATABASE AdventureWorks2008 TO DISK=@BackupFileName

--4. Repeat steps 2. and 3. for all other databases

SELECT @BackupFileName = (SELECT ' E:\Backup\AdventureWorks2012_' + 
convert(varchar(500),GetDate(),112) + '.bak') 

BACKUP DATABASE AdventureWorks2012 TO DISK=@BackupFileName

SELECT @BackupFileName = (SELECT ' E:\Backup\AdventureWorks2014_' + 
convert(varchar(500),GetDate(),112) + '.bak') 

BACKUP DATABASE AdventureWorks2014 TO DISK=@BackupFileName

In the first step of the script, a variable for the backup file name is declared.
In step two, the BackupFileName variable is defined by combining strings for the backup path and database name with the string generated by the GetDate() function. The backup paths and the backup filenames must be provided for each database that needs to be backed up. In this example, databases AdventureWorks2008, AdventureWorks2012 and AdventureWorks2014 are used.
In step three, backup command for the specified database is executed. Steps 2 and 3 must be repeated for each other database that needs to be included in the backup job.
If there are too many databases on the server (a few hundred for example), and most of them need to be backed up, it would be impractical to apply the method used in script 2. Also, writing the script itself would take a a lot of time. To back up all databases on the server, with the possibility to exclude system (or any specific database), script 3 can be used. One of the greatest advantages of this script is that it will always back up all non-system databases on the server, even those databases that are added to the server after the agent job creation.
--Script 3: Backup all non-system databases

--1. Variable declaration

DECLARE @path VARCHAR(500)
DECLARE @name VARCHAR(500)
DECLARE @filename VARCHAR(256)
DECLARE @time DATETIME
DECLARE @year VARCHAR(4)
DECLARE @month VARCHAR(2)
DECLARE @day VARCHAR(2)
DECLARE @hour VARCHAR(2)
DECLARE @minute VARCHAR(2)
DECLARE @second VARCHAR(2)
 
-- 2. Setting the backup path

SET @path = 'E:\Backup\'  

 -- 3. Getting the time values

SELECT @time = GETDATE()
SELECT @year   = (SELECT CONVERT(VARCHAR(4), DATEPART(yy, @time)))
SELECT @month  = (SELECT CONVERT(VARCHAR(2), FORMAT(DATEPART(mm,@time),'00')))
SELECT @day    = (SELECT CONVERT(VARCHAR(2), FORMAT(DATEPART(dd,@time),'00')))
SELECT @hour   = (SELECT CONVERT(VARCHAR(2), FORMAT(DATEPART(hh,@time),'00')))
SELECT @minute = (SELECT CONVERT(VARCHAR(2), FORMAT(DATEPART(mi,@time),'00')))
SELECT @second = (SELECT CONVERT(VARCHAR(2), FORMAT(DATEPART(ss,@time),'00')))

-- 4. Defining cursor operations
 
DECLARE db_cursor CURSOR FOR  
SELECT name 
FROM master.dbo.sysdatabases 
WHERE name NOT IN ('master','model','msdb','tempdb')  -- system databases are 
excluded

--5. Initializing cursor operations

OPEN db_cursor   
FETCH NEXT FROM db_cursor INTO @name   

WHILE @@FETCH_STATUS = 0   
BEGIN

-- 6. Defining the filename format
   
       SET @fileName = @path + @name + '_' + @year + @month + @day + @hour + 
@minute + @second + '.BAK'  
       BACKUP DATABASE @name TO DISK = @fileName  

 
       FETCH NEXT FROM db_cursor INTO @name   
END   
CLOSE db_cursor   
DEALLOCATE db_cursor

Script 3 uses separate string variables for year, month, day, hour, minute and second to create the unique name for each subsequent backup file. To apply this script in a specific environment, it is necessary to configure the following parameters in the script 3:
  • Set the custom backup path in step 2
  • In step 4, add names of the databases that should be excluded from the script. In this example, only four system databases are excluded.
  • If needed, change the sequence of variables in step 6 to define the backup file name
After deciding which script to use for the backup job, we can start to configure SQL Server agent job. In further examples, script 3 will be used.

Create SQL Server agent job

In order to create any SQL Server Agent job, make sure that SQL Server Agent is running first.
Start SQL Server Management Studio, and locate the icon that represents SQL Server Agent at the bottom of the Object Explorer. If there is “Agent XPs disabled” message in parenthesis, the agent is not running. To start the SQL Server Agent, right click on its label, and select Start from the context menu.

As soon as agent is running, proceed with the following steps to configure the job:
  1. Expand SQL Server Agent node in Object Explorer, right click on Jobs, and select New job… in the context menu.
  2. In the General tab of the New Job form, provide the name, owner and description for the job. Since script 3 will be used for the agent job, Name and Description fields should describe situation where backups are taken for all databases on the server. If job needs to be active right after it is created, check the Enabled box.
  3. In Steps tab, click on the New… button to configure job steps.
  4. In General tab of the New Job Step wizard, provide the step name, set the job type to Transact-SQL script (T-SQL), and select master database in the Database box. Paste the script that will be used for this job in the Command box. In this example, script 3 will be used. Click on OK button to save the job step.
  5. Back in the New job wizard, select Schedules tab, and click on New… button.
  6. In New Job Schedule window, set the name for the schedule, select the schedule type, and set the frequency. In this case, the schedule that runs at 12AM each day will be used. Click OK button to save changes.
  7. Optionally, set alerts and notifications in respective tabs of the New Job wizard, and click OK to complete agent job configuration.
  8. The best way to check if the job is working, is to run it, and see the results. As mentioned in the introduction, avoid running this job during the high-traffic hours on the server. To run created jobs immediately, expand SQL Server Agent and Jobs nodes in Object Explorer, right click on the created job, and select Start job at step… option.
  9. Success message is displayed as soon as job is executed.
  10. Finally, check the backup folder for the created backup files. Since script 3 adds values for the exact time in seconds to all backup filenames, the job can be run all over again – and each new run will create set of new, separate backup files.

Create a maintenance plan to back up selected databases

The same result can be achieved with the use of maintenance plans. One of the advantages of maintenance plans is that there is no need for the T-SQL scripts. To configure a maintenance plan, perform the following steps:
  1. Expand Management node in Object Explorer, right click on Maintenance Plans, and select Maintenance Plan Wizard from the context menu.
  2. In first step of the wizard, provide name and description for the maintenance plan. Check the option to use single schedule for the entire plan. Also, click on the Change… button to configure the schedule.
  3. In New Job Schedule window, specify name, schedule type and frequencies. Check the description in Summary, and click OK to save changes if schedule is configured properly. Click on the Next button in Maintenance Plan Wizard to proceed with the configuration.
  4. In second step of the wizard, select Back Up Database (Full) option, and click on Next to proceed.
  5. Since only one task got selected in the previous step, there is no need to set the task execution order. Click Next to proceed.
  6. In the General tab, open the drop-down menu for Database(s), and select option to back up All databases.
  7. In the Destination tab, select the option to Create a backup file for every database. Provide the backup destination path in Folder text box, and click on Next button.
  8. Set the options for text and E-mail reports if needed, and click Next.
  9. In the final step, review all configured settings, and click Finish to save changes.
  10. The success message is generated as soon as wizard executes all given instructions.
  11. To execute created maintenance plan, expand the Management and Maintenance Plans nodes in the Object Explorer. Right click on the created maintenance plan (Back up all databases in this case), and select Execute.
  12. A “Success” message is generated upon successfull execution.
  13. To make sure that the maintenance plan worked, check the folder specified as the backup destination. When maintenance plans are used, the names for the backup files are generated automatically, and they contain strings for database name, year, month, date, hours, minutes and seconds. Unfortunately, there is no option to set custom naming rules for backup files when maintenance plans are used.

Back up multiple SQL databases with ApexSQL Backup

ApexSQL Backup is a 3rd party software solution used for managing backup, restore and various maintenance operations. Backup schedules for multiple SQL databases can be configured in a few simple steps:
  1. To be able to manage any server with the application, it is necessary to add it in the server pane first. In the Home tab, click on Add button.
  2. In Add SQL Server dialogue, select the server to add, specify the authentication type, and provide username and password if SQL Server authentication type is selected. Click OK button to add selected server.
  3. As soon as the server is added, it becomes visible in the server list, along with all databases that are available on that server. Click on the Backup button in the Home tab to configure backup jobs.
  4. All important settings are configured in the main tab of the backup wizard. Select the server from the SQL Server drop-down list. Click on the browse button in Databases box to specify which databases to back up. Check the box in the Name row to select all databases on the server. Uncheck the boxes in front of system databases if they need to be excluded from the job. Click OK to close the form.
  5. Set the backup type to Full database backup. If needed, set the tags for the Job name and Job description. To set backup destination path, and configure custom naming rules, click on Add Destination button.
  6. In Add backup destination dialogue, type or browse for the backup destination path in the Folder text box. In the Filename box, configure the format of the backup filename by clicking on the corresponding tags. There are 7 different tags available, and each can be included in the backup filename. Check the name preview at the bottom of the page, and click OK if it is configured properly.
  7. Set the backup schedule by selecting Schedule radio button. In the Schedule wizard, set the frequency to match desired backup schedule. Check the summary at the bottom of the page to confirm that schedule is configured well. Click OK to save changes in the Schedule wizard. As in previous examples, the schedule is set to run at midnight, on a daily basis.
  8. Various options regarding media, verification, compression and encryption settings can be added to the job in the Advanced tab of the backup wizard.
  9. Optionally, set the E-mail notifications in Notification tab.
  10. After all steps in the Backup wizard are configured, click on the OK button at the bottom to create backup jobs for the selected databases selected in step 4. As seen on the completion message, a single job is created for each of the databases.
  11. To test created jobs, select Schedules view in main application form. Select all created schedules by clicking on the checkbox in the column heading row. Right click on any of the schedules to bring up the context menu, and select Run now. Jobs will be executed immediately, regardles of the schedule settings.
  12. Finally, check for the created backup files in the folder speciffied in the backup path. Backup files can be easily recognized by the custom filenames. Furthermore, the creation date and time are readable directly from the filename.

  How to Change Instance Type & Security Group of EC2 in AWS By David Taylor Updated April 29, 2023 EC2 stands for Elastic Compute Cloud...