Skip to content

Restic backup to S3

Use restic to backup your data from Linux, BSD, Mac and Windows to S3.

Backup home folder to S3 (Linux/Mac)

Creating incremental encrypted backup of your home folder to s3 bucket using following example script:

#!/bin/bash

# Set S3 credentials and repository details
S3_ENDPOINT="https://s3.ice.ri.se"
S3_BUCKET="your-bucket-name"
S3_ACCESS_KEY="XXXXXXXXXXXXXXX"
S3_SECRET_KEY="XXXXXXXXXXXXXXXXXXX"

# Set restic repository and password
RESTIC_REPO="s3:${S3_ENDPOINT}/${S3_BUCKET}"
export RESTIC_PASSWORD="replace me"  # Replace with a strong password

# Export S3 credentials as environment variables
export AWS_ACCESS_KEY_ID=${S3_ACCESS_KEY}
export AWS_SECRET_ACCESS_KEY=${S3_SECRET_KEY}

# Initialize restic repository if it doesn't exist
if ! restic -r ${RESTIC_REPO} snapshots; then
    echo "Initializing restic repository..."
    restic init -r ${RESTIC_REPO}
fi

# Create a backup of the home folder
echo "Creating backup of home folder..."
restic -r ${RESTIC_REPO}  backup /home/${USER}/

# Verify the backup
echo "Verifying backup..."
restic -r ${RESTIC_REPO}  snapshots

# Remove any old backups (optional)
restic -r ${RESTIC_REPO} forget --keep-last 5 --prune

Listing snapshots

> restic -r ${RESTIC_REPO} snapshots
repository 4a14c5c2 opened successfully, password is correct
ID        Time                 Host              Tags        Paths
-------------------------------------------------------------------------
7fffe2bb  2025-02-03 23:13:00  daniel-precision              /home/daniel
edc444aa  2025-02-04 12:33:34  daniel-precision              /home/daniel
002059aa  2025-02-04 12:36:34  daniel-precision              /home/daniel
-------------------------------------------------------------------------
3 snapshots

Restore

# set environment variables as in backup script
# list snapshots and find out which snapshot to restore
# restore /home/daniel/bin folder from snapshot to /tmp/restore
restic -r ${RESTIC_REPO} restore --include /home/daniel/bin --target /tmp/restore/ edc444aa