Create a File backup of a DigitalOcean Spaces Object Storage bucket

DigitalOcean Spaces is an S3-compatible object storage service that can be integrated into your Ubuntu VPS using s3fs-fuse. This guide will walk you through mounting a DigitalOcean Space, securely handling your credentials, automating the mount process, and setting up file backups using SimpleBackups.

Prerequisites

β€’ Ubuntu VPS: Ensure your server is running Ubuntu or a distro that’s compatible with s3fs.

β€’ DigitalOcean Space: Have an existing Space with its Access and Secret Keys.

β€’ Root or Sudo Access: Necessary for installing packages and editing system files.

β€’ SimpleBackups Account: Sign up at SimpleBackups if you haven’t already.

Β 

Step 1: Install s3fs-fuse

s3fs-fuse allows you to mount S3-compatible storage as a local filesystem.

  1. Update Package List:

sudo apt update

  1. Install s3fs:

sudo apt install s3fs

Β 

Step 2: Securely Store Your Credentials

Storing credentials securely is crucial to maintain system security.

  1. Create a Directory for Secrets:

mkdir ~/.secrets

  1. Create the Credentials File:

echo "ACCESS_KEY_ID:SECRET_ACCESS_KEY" > ~/.secrets/dospace-credentials

Replace ACCESS_KEY_ID and SECRET_ACCESS_KEY with your actual DigitalOcean Spaces credential.

  1. Set Appropriate Permissions:

chmod 600 ~/.secrets/dospace-credentials

Β 

Step 3: Create a Mount Point

Decide on a directory where the Space will be mounted.

sudo mkdir /mnt/dospace

Β 

Step 4: Mount the DigitalOcean Space

Use the s3fs command to mount your Space.

s3fs YOUR_SPACE_NAME /mnt/dospace -o passwd_file=~/.secrets/dospace-credentials -o url=https://YOUR_REGION.digitaloceanspaces.com -o use_path_request_style

Replace:

  • YOUR_SPACE_NAME: Name of your DigitalOcean Space.
  • YOUR_REGION: Region code of your Space (e.g., nyc3).
Β 

Step 5: Verify the Mount

Ensure the Space is mounted correctly.

  1. Check Mounted Filesystems:

df -h

Look for an entry corresponding to /mnt/dospace.

  1. List Contents:

ls /mnt/dospace

You should see the contents of your DigitalOcean Space.

Β 

Step 6: Automate Mounting at Boot

To ensure the Space mounts automatically after a reboot:

  1. Edit the /etc/fstab File:

sudo nano /etc/fstab

  1. Add the Following Line:

s3fs#YOUR_SPACE_NAME /mnt/dospace fuse _netdev,passwd_file=/home/your_username/.secrets/dospace-credentials,url=https://YOUR_REGION.digitaloceanspaces.com,use_path_request_style 0 0

Replace your_username with your actual username.

  1. Test the Configuration:

sudo mount -a

Check for any errors and verify the mount as in Step 5.

Β 

Step 7: Set Up File Backups with SimpleBackups

With your DigitalOcean Space mounted, you can configure SimpleBackups to back up files to this location.

  1. Log in to SimpleBackups: Access your SimpleBackups dashboard.
  1. Connect Your Server:
      • Navigate to Servers and click Connect Server.
      • Choose the Automatic (SSH Key) method for seamless integration.
      • Follow the provided instructions to run the connection command on your Ubuntu VPS.
  1. Create a New Backup:
      • In the dashboard, click Create Backup and select File Backup.
      • Enter a name for your backup job.
      • Select the server you connected earlier.
  1. Select Directories to Back Up:
      • Specify the directories you wish to back up.
      • To back up data to your mounted DigitalOcean Space, choose the appropriate directories within /mnt/dospace.
  1. Configure Storage:
      • Choose SimpleStorage or connect an external storage provider.
      • If you prefer to store backups directly in DigitalOcean Spaces, ensure it’s connected as a storage provider in SimpleBackups.
  1. Set Schedule and Retention:
      • Define the backup frequency (e.g., daily, weekly).
      • Set retention policies to manage backup storage.
  1. Save and Enable:
      • Review your settings.
      • Click Save and enable the backup job.
Β 

Security Best Practices

β€’ Environment Variables: Alternatively, store credentials in environment variables and reference them in your s3fs command.

β€’ AWS CLI Integration: Utilize the AWS CLI credentials file for managing your DigitalOcean Spaces credentials.

β€’ Secrets Management Tools: Consider using tools like HashiCorp Vault for enhanced security.

β€’ Regular Key Rotation: Periodically rotate your Access and Secret Keys to maintain security.

By following these steps, you can securely mount your DigitalOcean Space on your Ubuntu VPS and configure SimpleBackups to back up your files effectively.

Did this answer your question?
😞
😐
🀩