Syncing AWS S3 Bucket to DigitalOcean Spaces with Rclone and Restic

In this comprehensive guide, we’ll walk you through the process of syncing an AWS S3 bucket to a DigitalOcean Spaces bucket using Rclone and Restic. This tutorial caters to both beginners and advanced users, making it easy for anyone to follow along.

Table of Contents

1). Introduction

This guide will show you how to seamlessly sync your AWS S3 bucket with a DigitalOcean Spaces bucket. By leveraging Rclone and Restic, you can ensure your data is consistently backed up and accessible across both platforms.

2). Prerequisites

Before you begin, make sure you have the following:

  • An AWS account with an S3 bucket.
  • A DigitalOcean account with a Spaces bucket.
  • Rclone installed on your local machine.
  • Restic installed on your local machine.
  • Basic knowledge of command-line operations.

3). Understanding the Workflow

Here’s a simple diagram to illustrate the workflow of syncing between AWS S3 and DigitalOcean Spaces:

4). Set Up AWS S3 and DigitalOcean Spaces

Creating an S3 Bucket

  1. Log in to your AWS Management Console.
  2. Navigate to S3 and create a new bucket.

  3. Configure your bucket settings as needed.

Creating a DigitalOcean Space

  1. Log in to your DigitalOcean account.

  2. Navigate to the Spaces section and create a new Space.

  3. Configure your Space settings as needed.

5). Access Keys and Permissions

AWS IAM User
Create an IAM user with permissions to read the S3 bucket:

Create a new IAM user.

Go to the IAM service in the AWS Management Console.

  1. Set Up AWS Access Keys:
    Go to the AWS IAM Management Console. Select the IAM user you created.

  • Under the “Security credentials” tab, click Create access key.


    Select option according to your need



  • Attach the necessary policies to read from S3.




DigitalOcean API Token

  1. Generate an API token for accessing DigitalOcean Spaces:
  • Go to the API section in the DigitalOcean Control Panel.
  • Generate a new API token with appropriate permissions.

Environment Variables

Store your access keys and tokens securely using environment variables:

export AWS_ACCESS_KEY_ID=YOUR_AWS_ACCESS_KEY
export AWS_SECRET_ACCESS_KEY=YOUR_AWS_SECRET_KEY
export DO_ACCESS_KEY=YOUR_DO_ACCESS_KEY
export DO_SECRET_ACCESS_KEY=YOUR_DO_SECRET_KEY

6).Install and Configure Rclone

Installation

Install Rclone using the following command:

curl https://rclone.org/install.sh | sudo bash

Configuration for AWS S3

  1. Run rclone config in the terminal.
  2. Choose n for a new remote.
  3. Name the remote aws for AWS S3:
  • Storage: s3
  • Provider: AWS
  • Access Key ID: <AWS_ACCESS_KEY>
  • Secret Access Key: <AWS_SECRET_KEY>
  • Region: <AWS_REGION>

    4.Name the remote do for DigitalOcean Spaces:
  • Storage: s3
  • Provider: DigitalOcean
  • Access Key ID:
  • Secret Access Key:
  • Endpoint: nyc3.digitaloceanspaces.com

Configuration for DigitalOcean Spaces

  1. Name the remote do for DigitalOcean Spaces:
  • Storage: s3
  • Provider: DigitalOcean
  • Access Key ID: <DigitalOcean_ACCESS_KEY>
  • Secret Access Key: <DigitalOcean_SECRET_KEY>
  • Endpoint: nyc3.digitaloceanspaces.com

    Example Rclone Config File (.config/rclone/rclone.conf):

7). Initial Sync

Perform the Initial Sync

To perform the initial data sync from AWS S3 to DigitalOcean Spaces, use:

rclone sync aws:s3-bucket-name do:space-name

Example Rclone Config File

Here’s a sample of what your Rclone config file might look like:

[aws]
type = s3
provider = AWS
access_key_id = YOUR_AWS_ACCESS_KEY
secret_access_key = YOUR_AWS_SECRET_KEY
region = YOUR_AWS_REGION

[do]

type = s3 provider = DigitalOcean access_key_id = YOUR_DO_ACCESS_KEY secret_access_key = YOUR_DO_SECRET_KEY endpoint = nyc3.digitaloceanspaces.com

8).Preventing Deletion from Backup

To prevent deletions in DigitalOcean Spaces when objects are deleted from AWS S3, use the rclone copy command instead of rclone sync:

rclone copy aws:s3-bucket-name do:space-name/content_or_files

9). Organizing Backups with Timestamps

  1. Copy the content from AWS S3 to DigitalOcean Space:
   rclone copy aws:s3-bucket-name do:space-name/content_or_files
  1. Initialize the Restic Repository:
   restic -r do:space-name/backup init
  1. Back Up the Content to DigitalOcean Space Using Restic:
   restic -r do:space-name/backup backup /path/to/your/data
  1. List Restic Snapshots:
   restic -r do:space-name/backup snapshots
  1. Restore a Snapshot:
   restic -r do:space-name/backup restore <snapshot_ID> --target /path/to/restore

10). Conclusion

By following these steps, you can easily sync your AWS S3 bucket to a DigitalOcean Spaces bucket using Rclone and Restic. This setup not only ensures your data is securely backed up but also readily accessible across both platforms.


This structured format, complete with headings, bullet points, and a workflow diagram, should make your blog both visually appealing and easy to navigate!

Related posts

Exploring the World of Open-Source DevOps📝: Tools, Benefits, and Best Practices

Choosing the Best Linux Distribution for DevOps: A Comprehensive Guide

Mastering Docker Exec Commands: Running Commands Inside Docker Containers