---
title: "Duplicity"
sidebar_label: "Duplicity"
sidebar_position: 7
description: "How to install and configure Duplicity for backups via the Duplicity command-line interface"
---

import Formbricks from '@theme/MDXComponents/Formbricks'
import Tabs from '@theme/Tabs'
import TabItem from '@theme/TabItem'
import {TabItemLabel} from '@selectel/docux/components'
import GrantAccess from '@site/i18n/en/docusaurus-plugin-content-docs/current/_partials/s3/grant-access.mdx'

# Duplicity

[Duplicity](https://duplicity.gitlab.io/) is a command-line interface for backups. Duplicity supports SSH/SCP, FTP, HSI, WebDAV, Tahoe-LAFS, and Amazon S3 protocols to connect to a file server, archives data, uploads it to a local or remote file server, and encrypts data using the [GnuPG](http://www.gnupg.org/) utility.

## Configure Duplicity \{#configure-duplicity}

1. [Configure access to S3](#configure-s3-access).
2. [Install the client](#install-client).
3. [Configure Duplicity settings](#configuration).

### 1. Configure S3 access \{#configure-s3-access}

<GrantAccess />

### 2. Install the client \{#install-client}

<Tabs queryString="os">
  <TabItem value="ubuntu" default>
    <TabItemLabel>
      Ubuntu
    </TabItemLabel>

    1. Open the terminal.

    2. Install Duplicity:

       ```bash
       sudo apt-get install duplicity
       ```

    3. Install the `python-swiftclient` and `librsync` packages:

       ```bash
       sudo apt-get install python-swiftclient
       sudo apt-get install librsync-dev
       ```

    4. Install the Bazaar version control system and download `swiftbackend`:

       ```bash
       sudo apt-get install bzr
       bzr branch lp:~mhu-s/duplicity/swiftbackend
       ```

    5. Install `swiftbackend`:

       ```bash
       cd swiftbackend && sudo python dist/setup.py install
       ```
  </TabItem>
</Tabs>

### 3. Configure Duplicity settings \{#configuration}

<Tabs queryString="api">
  <TabItem value="swift" default>
    <TabItemLabel>
      5.1. Copy the script from step 1.
    </TabItemLabel>

    1. Create a file with the backup script:

       ```bash
       export SWIFT_PASSWORD=<password>
       export SWIFT_AUTHVERSION=3
       export SWIFT_TENANTNAME=<project_name>
       export SWIFT_AUTHURL="https://cloud.api.selcloud.ru/identity"
       export SWIFT_REGIONNAME=<pool>
       export SWIFT_USERNAME=<username>
       export SWIFT_USER_DOMAIN_NAME=<account_id>
       export SWIFT_PROJECT_DOMAIN_NAME=<account_id>

       duplicity <path> swift://<bucket_name>

       unset SWIFT_PASSWORD
       unset SWIFT_AUTHVERSION
       unset SWIFT_TENANTNAME
       unset SWIFT_AUTHURL
       unset SWIFT_USERNAME
       ```

       Specify:

       * `<password>` — service user password. If you forgot the password, [create a new one](/access-control/manage/edit-user-data-or-role.mdx#change-service-user-password);
       * `<project_name>` — project name;
       * `<pool>` — [pool](/infrastructure/locations.mdx#pool) where S3 is located;
       * `<username>` — service user name;
       * `<account_id>` — Control panel account ID, can be found in the [control panel](https://my.selectel.ru/) in the upper-right corner;
       * `<path>` — path to the folder on the local machine;
       * `<bucket_name>` — bucket name.

    2. Make the file executable:

       ```bash
       chmod +x <file_name>
       ```

       Specify `<file_name>` — name of the script file.

    3. Run the script:

       ```bash
       ./<file_name>
       ```

    4. Enter the passphrase. The backup will start, and statistics will be displayed in the console.

    5. Optional: to download an encrypted backup from storage to a local machine:

       5.1. Copy the script from step 1.

       5.2. In the script, replace the `duplicity <path> swift://<bucket_name>` command with `duplicity swift://<bucket_name> <path>`.

       5.3. Save the script to a file named `restore.sh`.

       5.4. Make the file executable:

       ```bash
       chmod +x restore.sh
       ```

       5.5. Run the script:

       ```bash
       ./restore.sh
       ```

       5.6. Enter the passphrase. All files from the backup will be downloaded to the specified directory on the local machine.
  </TabItem>

  <TabItem value="s3" default>
    <TabItemLabel>
      S3
    </TabItemLabel>

    1. Make sure that [Virtual-Hosted addressing is enabled](/s3/buckets/addressing-types.mdx#enable-virtual-hosted) in the bucket.

    2. Install boto:

       ```bash
       sudo apt install python3-boto
       ```

    3. Create a file `touch duplicity.conf` with the configuration:

       ```bash
       [s3]
       aws_access_key_id = <access_key>
       aws_secret_access_key = <secret_key>
       bucket = <bucket_name>
       region = <pool>
       endpoint = <s3_domain>
       type = s3
       provider = Other
       env_auth = false
       ```

       Specify:

       * `<access_key>` — value of the **Access key** field from the [S3 key](#configure-s3-access);
       * `<secret_key>` — value of the **Secret key** field from the [S3 key](#configure-s3-access);
       * `<bucket_name>` — bucket name;
       * `<pool>` — [pool](/infrastructure/locations.mdx#pool) where S3 is located;
       * `<s3_domain>` — [S3 API domain](/s3/manage/domains.mdx#s3-api-domains). The domain depends on the [pool](/infrastructure/locations.mdx#pool) where S3 is located.

    4. Perform archiving:

       ```bash
       duplicity <path> s3://<s3_domain>/<bucket_name>
       ```

       Specify:

       * `<path>` — path to the folder on the local machine;
       * `<bucket_name>` — bucket name.
  </TabItem>
</Tabs>

<Formbricks />
