Version 2023 upgrade guide

Version 2023 Upgrade Guide

Trial & Platform Version

Introduction

The backup and restore feature is an essential safeguard for protecting critical data stored in our Leapwork databases. To minimize the risk of catastrophic data loss and to preserve data configurations, we should perform a backup of our databases on a regular basis. A well-planned backup and restoration strategy for our databases can provide timely protection against unforeseen situations like:

Cloud data storage solutions minimize the loss of data when compared to natural disasters affecting on-premise data. Additionally, database backups are useful for performing several routine administrative tasks, such as database migration, mirroring, and archiving.

What Data Should I Backup?

The Leapwork Controller holds all data, such as flows, sub-flows, images, schedules, and locators, etc., in the form of multiple .sqlite database files. The Controller also holds automation runs containing test flow execution artifacts, similar to automation run video and screenshots. If we have sufficient disk space, it is recommended that we create a backup of everything under the assets folder, including AutomationRunMedia.

Note: A backup of all .sqlite files is mandatory.

Backup Procedure

You can manually or automatically initiate the backup process using a PowerShell script.

Preconditions

Manual Backup

To perform a manual backup:

  1. Log in to the Controller machine.
  2. Stop the Leapwork Controller service:
    1. Press the Win+R key combination to open the Run dialog.
    2. Type services.msc and press OK to open the Services window.
    3. Find the Leapwork Controller and stop it by right-clicking the mouse button, then by clicking Stop.
  3. Open File Explorer and navigate to the C:\Program Files\LEAPWORK.
  4. Copy the Assets folder.
  5. Navigate to our selected backup location.
  6. Paste the Assets folder and wait until the file copy process is completed.
  7. Start the Controller service:
    1. Press the Win+R key combination to open the Run dialog.
    2. Type services.msc and press OK to open the Services window.
    3. Find the Leapwork Controller and restart it by right-clicking the mouse button, then by clicking Start. The Leapwork data backup is now complete.

Script-based Backup

The script-based backup automatically performs the same process as the manual backup process. The following is an example of the script-based backup in PowerShell script:

##############################################################################################################
# Leapwork DATA BACKUP SCRIPT
##############################################################################################################

# Variables to be altered by user
# $assetsFolderPath- This is path to Assets folder in Controller machine- Change only if you custom path
# $backupPath- This is safe location where user should keep backup of Assets(Could be UNC/network path)
##############################################################################################################

Write-Host "Backup Process Started"
Write-Host "Step1: Stopping LEAPWORK Controller Service.."

$ServiceName = "LEAPWORK Controller"
Stop-Service $ServiceName

Write-Host "Step2: Check Controller Service State.."
do
{
    Start-Sleep -Seconds 2
    Write-Host "Getting the service status.."
    $ServiceStatus = (Get-Service -Name $ServiceName).Status
    Write-Host $ServiceName "-" $ServiceStatus
}
while ($ServiceStatus -ne 'Stopped')

Write-Host "Step3: Taking Backup.."
$assetsFolderPath = "C:\Program Files\LEAPWORK\Assets" #Path to Assets folder in Controller Machine
$dateTimeOfBackup= Get-Date -format "dd-MMM-yyyy-HH-mm-ss" #Date time to be added in the folder name to identify daily backup
$backupPath = "D:\Backup-$dateTimeOfBackup" #Path of safe location to backup Assets, it can be UNC/network path
Copy-Item -Path $assetsFolderPath -Recurse -Destination $backupPath

Write-Host "Step4: Backup Finished.."

Write-Host "Step5: Starting LEAPWORK Controller.."
Start-Service "LEAPWORK Controller"

Write-Host "Backup Finished !!"
##############################################################################################################

On a Controller machine, we can create a schedule using the Windows task scheduler to run the previously supplied PowerShell script, for creating a backup during a defined interval of time.

Restore Database

The restore process copies data from a backup by converting the backup file into a database. Perform the following steps to restore our Leapwork databases.

  1. Navigate to our backup folder location.
  2. Copy the Assets folder from our backup folder.
  3. Log in to the Controller machine.
  4. Stop the Leapwork Controller services.
    • Press the Win+R key combination to open the Run dialog.
    • Type services.msc and press OK to open the Services window.
    • Find the Leapwork Controller and stop it by right-clicking the mouse button, then by clicking Stop.

After performing the previous steps, open Leapwork studio and verify that the data is present. You can also automate this process by creating a restore PowerShell script.

Note: It is suggested that we test our strategy by backing up and restoring databases, to better prepare us for any unforeseen disaster situations.

How Often Should I Perform a Backup?

The frequency in performing backups depends on how often automation flows and data changes.

Database Backup for Enterprise

Introduction

The backup and restore feature is an essential safeguard for protecting critical data stored in our Leapwork databases. To minimize the risk of catastrophic data loss and to preserve data configurations, we should perform a backup of our databases on a regular basis. A well-planned backup and restoration strategy for our databases can provide timely protection against unforeseen situations like:

Backup Procedure

You can manually or automatically initiate the backup process using a PowerShell script.

Manual Backup

Script-based Backup

The below steps are listed to demonstrate how to perform SQL database backup & restore for a SQL server using a script (bat) file.

Prerequisites

We will need to know the following information before proceeding.

Take a Backup

  1. Open Notepad (or any text editor).
  2. Copy the code from the backup script and paste it into the text editor.
  3. Save the file with an extension .bat to ensure that it is a batch file and not a plain text file.

Note: The icon should change to a command prompt. If not, the file extension is probably .bat.txt, which means that we will need to display file extensions to remove the .txt extension.

  1. To perform the backup, double-click on the new batch file. We will see it perform some queries and then it will export the data to a file.

Note: The amount of time to perform the backup may take a while depending on the size of the database.

Backup Script Snippet

@echo off

cls

rem Set these variables to the desired values

set SqlServer=SERVER_NAME (The name of your SQL server)
set InstanceName=MSSQLSERVER (The name of the SQL instance)
set Username=SQL_USERNAME (The username with backup rights)
set Password=SQL_PASSWORD (The password for the above user)
set Database=DATABASE_NAME (The database to be backed up)
set LocalFolder=C:\Temp (Temporary local folder to hold backup, no quotes)
set NetworkFolder="\\remotecomputer\folder" (URL to permanent backup location, include quotes)

echo Getting current date and time...
echo.
for /f %%a in ('sqlcmd -S %SqlServer% -U %Username% -P %Password% -Q "SET NOCOUNT ON select ltrim(convert(date, getdate()))" -h -1') do set CurrentDate=%%a
for /f %%a in ('sqlcmd -S %SqlServer% -U %Username% -P %Password% -Q "SET NOCOUNT ON select right('00' + ltrim(datepart(hour, getdate())), 2)" -h -1') do set CurrentHour=%%a
for /f %%a in ('sqlcmd -S %SqlServer% -U %Username% -P %Password% -Q "SET NOCOUNT ON select right('00' + ltrim(datepart(minute, getdate())), 2)" -h -1') do set CurrentMinute=%%a
for /f %%a in ('sqlcmd -S %SqlServer% -U %Username% -P %Password% -Q "SET NOCOUNT ON select right('00' + ltrim(datepart(second, getdate())), 2)" -h -1') do set CurrentSecond=%%a

echo.
echo Backing up database to %LocalFolder%
echo.
SqlCmd -S %SqlServer% -U %Username% -P %Password% -Q "Backup Database %Database% To Disk='%LocalFolder%\%Database%-%CurrentDate%_%CurrentHour%%CurrentMinute%%CurrentSecond%.bak'"
echo.
echo.
echo Copying backup to %NetworkFolder%
echo.
mv /Y %LocalFolder%\%Database%-*.bak %NetworkFolder%

After making sure that the batch file works as expected, we can add it as a scheduled task in the Task Scheduler to have it run daily at the desired time.

Auto Backup Procedure using Task Scheduler

Step 1. Click Windows Start button, search and open Task Scheduler.

Step 2. Click on Action - Create Task.

Step 3. In General, Name the task (ex. SQL Backup).

Step 4. Click on Triggers - New and define the Schedule for executing the script.

Step 5. Click Actions-New, in action, choose to start a program, and in Program/Script browse the script we want to execute.

Step 6. This will create a task in Task Scheduler which will execute as per the schedule defined.

Restoration Procedure

  1. Open Notepad (or any text editor).

  2. Copy the code from the backup script and paste it into the text editor.

  3. Save the file with an extension .bat to ensure that it is a batch file and not a plain text file.

  4. To perform the backup, double-click on the new batch file. We will see it perform some queries and then it will export the data to a file.

Note: The amount of time to perform the backup may take a while depending on the size of the database.

Restore Script Snippet

@echo off

cls

echo.
SQLCMD -S %SQLSERVERNAME% -U %USERNAME% -P %PASSWORD% -d master -q "Restore Database %My DB% From Disk='Path to My DB'"

If you have any questions, contact our Priority Support.