Skip to content

Latest commit

 

History

History
315 lines (205 loc) · 15.4 KB

backup.md

File metadata and controls

315 lines (205 loc) · 15.4 KB

Azure DevOps Backup Tool: Guide to creating your first backup pipeline

Introduction

This document provides a detailed procedure for backing up your Azure DevOps (ADO) organization or project using the Azure DevOps Backup Tool from Solidify.

Process overview

  1. Determining the correct Azure DevOps project to house our backup infrastructure
  2. Creating a git repository to hold our backup pipeline resources
  3. Creating our first backup pipeline
  4. Storing pipeline variables and secrets in Variable Groups
  5. Advanced config file usage + examples for various scenarios
  6. Running our backup pipeline and assessing the results
  7. Troubleshooting and support requests

1. Determining the correct Azure DevOps project to house our backup infrastructure

Before creating your backup pipeline, select the appropriate Azure DevOps project to house your backup infrastructure. Consider the following guidelines:

  • Dedicated Backup Project: Create a dedicated project in Azure DevOps to isolate the backup pipelines, repositories, and related resources from your development activities. This helps in managing access control and ensures that backup-related activities do not interfere with your other projects.
  • Permissions: Ensure that the project has the necessary permissions for accessing the resources you want to back up. Administrators and pipeline contributors should have access to this project.
  • Naming Conventions: Use clear and descriptive names for the project to easily identify its purpose, such as Backup-Infrastructure or Project-Backup.

2. Creating a git repository to hold our backup pipeline resources

After selecting the appropriate Azure DevOps project, the next step is to create a Git repository to store the resources required for the backup pipeline.

Navigate to your Azure DevOps project, go to the Repos section, and create a new repository. Name it something descriptive like Backup-Pipelines.

image

image

Our repository should now be initialized with an empty README:

image

3. Creating our first backup pipeline

With your Git repository ready, you can now create your first backup pipeline.

In Azure DevOps, go to the Pipelines section and create a new pipeline:

image

When asked Where is your code?, select Azure Repos Git (YAML):

image

Under Select Repository, choose the repository you created in the previous step (Backup-Pipelines):

image

Under Configure your pipeline, choose Starter pipeline:

image

You can now design your pipeline. You can bring in the tasks provided by Azure DevOps Backup Tool by clicking Show assistant and then searching for Azure DevOps Backup Tool in the assistant column. image

image

This will bring you into the task configuration. Here you you can view and change how the backup pipeline behaves, where it should look for components to back up, as well as API credentials for Azure DevOps:

image

Below is a basic YAML configuration for a backup pipeline. In order to make the setup process as simple as possible, please copy the below code block in its entirety and paste into your YAML pipeline text editor:

trigger: none

workspace:
  clean: all

variables:
- group: backup-pipeline
- name: workspace
  value: '$(System.DefaultWorkingDirectory)/MigrationWorkspace'
- name: System.Debug
  value: false       # Set to "true" to enable system diagnostics for troubleshooting or support requests

pool:
  vmImage: windows-latest

steps:
- task: ado-backup-tool-export@1
  displayName: 'ADO Backup Tool: Export'
  inputs:
    source: '$(sourceUrl)'
    sourceOrgName: '$(sourceOrg)'
    sourceProject: '$(sourceProject)'
    sourceUsername: '$(sourceUsername)'
    sourcePAT: '$(migrationToken)'
    onPrem: false
    workspace: '$(workspace)'
    useCustomConfigurations: false
    customConfigurationPath: '$(System.DefaultWorkingDirectory)/custom-configs'
    resourceAreaPath: true
    resourceArtifact: true
    resourceAuditLog: true
    resourceBoard: true
    resourceDeploymentGroup: true
    resourceEnvironment: true
    resourceGit: true
    resourceGitBranchPolicy: true
    resourceIterationPath: true
    resourcePipeline: true
    resourcePullRequest: true
    resourceQuery: true
    resourceTeam: true
    resourceTestplan: true
#    resourceTFS: true      # Uncomment if there are any TFVC repositories in the source Project
    resourceVariableGroup: true
    resourceWiki: true
    resourceWorkItem: true
  env:
    SYSTEM_ACCESSTOKEN: $(system.accesstoken)

- task: ArchiveFiles@2
  continueOnError: true
  condition: succeededOrFailed()
  inputs: 
    rootFolderOrFile: '$(workspace)'
    includeRootFolder: false
    archiveType: 'zip'
    archiveFile: '$(Build.ArtifactStagingDirectory)\$(Build.BuildNumber)-export.zip'
    replaceExistingArchive: false
        
- task: PublishPipelineArtifact@1
  condition: succeededOrFailed()
  continueOnError: true
  inputs:
    targetPath: '$(Build.ArtifactStagingDirectory)\$(Build.BuildNumber)-export.zip'
    artifact: 'Export'
    publishLocation: 'pipeline'

Optionally, you may comment our or delete any of the resource* inputs if those components are not desired to be backed up.

The resulting pipeline should now look like this:

image

Now click Save:

image

In the Save dialogue, click Save:

image

We are now done with creating our Backup Pipeline. Before we run it, we must specify some parameters to let the pipeline know our API credentials, where our resources are, etc.

4. Storing pipeline variables and secrets in Variable Groups

We will use Variable Groups to store our pipeline parameters, which will enable us to use the backup pipeline in a dynamic fashion.

Under the Pipelines -> Library menu, add a new Variable Group:

image

Name the variable group "backup-pipeline" (must match the variable group name in the YAML definition of the backup pipeline). You can change the name at any time as long as your consistently update the variable group name in the YAML definition of the pipeline. Enter the same variables as shown in the screenshot below (replace the values with your own scenario) and click Save.

image

The necessary variables for the Backup Job are as follows:

  • migrationToken (The Personal Access Token to be used by the backup job)
  • sourceOrg (The source Azure DevOps organization name)
  • sourceProject (The source ADO Project name)
  • sourceUrl (The URL of the ADO organization)
  • sourceUsername (The email address of the user account to be used by the backup job. Must be the same account as the owner of the migrationToken)

Optionally, you may opt to store your Backup Job variables inside the YAML build pipeline definition itself, or in an Azure KeyVault (use the Link secrets from an Azure key vault as variables setting).

5. Advanced config file usage + examples for various scenarios

You can extend the functionality of ADO Backup Tool by using custom configuration files. These files will override the default configuration of the underlying application behind the pipeline task, and enable you to change the behavior on a per-component basis.

If you are simply demoing the backup functionality or otherwise have no use for custom configuration files, you can skip ahead to step 6.

Description of custom configuration file usage

Common use cases for using custom config files are:

  • Filtering git repositories by name (wildcard supported)
  • Filtering build/release pipelines by name (wildcard supported)
  • Filtering work items based on a WIQL query
  • Overriding default git credentials for git repositories and wikis

How to enable custom configuration files

Edit your back up pipeline again. You will need to supply the useCustomConfigurations and customConfigurationPath parameters in the task configuration, like this:

useCustomConfigurations: true
customConfigurationPath: '$(System.DefaultWorkingDirectory)/custom-configs'

Your pipeline should now look like this:

image

Save the pipeline before continuing with the next step.

How to create custom configuration files

You provide custom configuration files by placing them in the same git repository as your backup/restore pipeline. The naming convention of the configuration files is always "config-[type of component]-[export/import].json.

You can find additional information about the usage of custom configuration files here: https://github.com/solidify/azure-devops-backup-tool-docs/blob/main/custom-configs.md.

You can view templates for individual configuration files for each ADO component here https://github.com/solidify/azure-devops-backup-tool-docs/tree/main/config-templates.

You can find documentation and usage samples with example configuration files for each ADO component here: https://github.com/solidify/azure-devops-backup-tool-docs/tree/main/adapter-docs

As an exercise, let us create a custom configuration file which will let us granularly filter which Work Items to export in the Backup Pipeline.

Start by creating a new folder inside the git repository named Backup-Pipelines:

image

The new folder name should be custom-configs and the residing file name should be config-workitem-export.json. This will create a configuration file which will affect only Work Items during the backup phase (and not the restore phase):

image

Paste the following file contents into the new file, and replace ORGNAME with your Azure DevOps organization name, and PROJECTNAME with your target project to be backed up:

{
    "configuration":
    {
        "source": "https://dev.azure.com/ORGNAME",
        "target": "D:\\a\\1\\s\\MigrationWorkspace",
        "batchSize": 50,
        "skip": 0,
        "projects": [
            {
              "name":"PROJECTNAME",
              "query":"Select * From WorkItems Where [System.TeamProject] = 'PROJECTNAME' AND [System.CreatedDate] < '2024-08-08T00:00:00.0000000' Order By [Id] Asc"
            }
        ],
        "SkipAlreadyDownloadedRevisions": true,
        "apiVersion": "7.0"
    }
}

The resulting file should look like this:

image

Save the new file by committing it to the version control history:

image

We are now set up to use our custom configuration file.

Verify the configuration file in use

Let us verify that the pipeline has successfully picked up our new custom configuration file.

Go ahead and edit the pipeline, and set the System.Debug property to true, like in the below screenshot:

image

Now, save and run the pipeline. Inspect the log for the ADO Backup Tool: Export task and verify that the task is picking up the correct configuration file. The configuration should appear just like you entered it in the file custom-configs/config-workitem-export.json:

image

If the configuration as reported by the pipeline is identical to the configuration you specified earlier, then everything is now set up correctly, and you can continue to step 6.

6. Running our backup pipeline and assessing the results

Finally, let us run our newly created Backup Job and verify that the results are as expected.

From the pipeline menu under Pipelines, click Run pipeline:

image

In the Run pipeline dialogue, simply click Run:

image

After clicking Run, you will be taken to the Run results screen. Simply wait here until the pipeline finishes or times out (you might need to refresh your browser tab). You may also need to authorize the pipeline to access all of the necessary variable groups.

If you ever need to get back to the Run results screen, simply navigate to Pipelines -> Backup-Pipelines -> (click the latest Run) from anywhere within Azure DevOps.

The pipeline should finish without errors.

image

From the results screen of the run, you can do either of the following from the screen:

  • Click on the Job to view the log file.
  • Click on the build artifact to view the components that were successfully backed up. We also require you to send us the build artifact in order to troubleshoot any issues.

image

From the Artifacts menu, in order to download and inspect the build artifact, simply click the downward-facing arrow to the left of "Export" -> click the 3 dots to the right -> Download artifacts. This will download a .zip-file to your computer which contains the backed up resources.

image

7. Troubleshooting and support requests

In the event that the ADO Backup Tool fails, you will receive an error message similar to this one at the bottom of the task log:

image

Click anywhere in the log to bring the focus to the log file area, then press ctrl+F to search the log file. Enter the search string ERR]. All relevant errors should become highlighted, and you can use the search panel to navigate between them:

image

If you are making a support request, please make a note of each error and forward all relevant error messages to us via e-mail.

For a more comprehensive guide on troubleshooting the ADO Backup Tool and submitting support requests, please read this article: https://github.com/solidify/azure-devops-backup-tool-docs/blob/main/troubleshooting.md.