Greetings, fellow file wizards and byte-stackers.
If you’re like me, you care a lot about your data—not just the important stuff like work files and school projects, but also weird memes, favorite screenshots, and “someday” ideas saved in text files. That’s why setting up a backup system is one of the smartest things you can do. Today, I’ll walk you through how I set up an automatic backup to Amazon S3 on my Ubuntu machine.
Don’t worry—I’ll keep it simple. If you’re a Linux beginner or someone who just wants your files safely tucked away in the cloud, this guide is for you.
What’s Amazon S3, and Why Should You Care?
Let’s break it down.
Amazon S3 stands for Simple Storage Service. It’s part of Amazon Web Services (AWS). You can think of it as a giant digital locker that lives online, where you can safely store files. Amazon keeps it secure, redundant (which means they store copies), and available 24/7.
A few new terms you’ll see:
- Bucket: Like a folder in S3 where your files go.
- Access keys: Think of them as passwords for letting your computer talk to your S3 account.
- CLI: Short for Command Line Interface. It lets you type commands to control AWS.
You can use S3 for photos, videos, documents, backups, logs—pretty much anything. And you only pay for what you use, like ordering snacks à la carte instead of a giant mystery buffet.
Why Back Up to Amazon S3?
Here’s what I like about S3:
- It’s reliable. Amazon’s servers are pretty much always online.
- It’s cheap for small users. I’m just backing up a few gigabytes, and it costs me pennies.
- It’s easy to automate. I don’t have to remember to run a backup—it just happens.
Before S3, I was copying files to a USB drive. One day, I lost it. Poof. Gone. So I switched to cloud backups. Haven’t looked back.
What You’ll Need
Before we dive in, here’s what you need:
- An Amazon AWS account
- A Linux system (Ubuntu 20.04 or later) with terminal access
- A little patience
- About 30–60 minutes to set things up
- Optional: a cat to sit on your keyboard for moral support
Step 1: Set Up Your AWS Account and S3 Bucket
First, log in to aws.amazon.com. If you don’t have an account, create one. It’s free to start.
Once you’re in:
- Go to S3.
- Click Create bucket.
- Choose a name (like
my-ubuntu-backup
) and a region. - Leave most settings as default (you can change them later).
- Click Create at the bottom.
Done. You’ve got a bucket ready to store your stuff.
Step 2: Get Your Access Keys
To let your Ubuntu system talk to AWS, you need access keys. Here’s how:
- Click your name on the top right in AWS and go to Security Credentials.
- Under Access Keys, click Create Access Key.
- Copy the Access Key ID and Secret Access Key and save them somewhere safe. These are like passwords—don’t share them.
Step 3: Install AWS CLI on Ubuntu
Now let’s get our Ubuntu system talking to Amazon.
In your terminal, type:
sudo apt update
sudo apt install awscli -y
After it installs, check the version:
aws --version
It should show something like aws-cli/2.x.x
. That means it’s working.
Step 4: Configure AWS CLI
Now, connect your keys to your machine.
aws configure
It will ask for four things:
- AWS Access Key ID → paste it here
- AWS Secret Access Key → paste that too
- Default region name → for example,
us-east-1
- Default output format → just press
Enter
(defaults tojson
)
Now your machine is ready to send files to the cloud.
Step 5: Try Uploading a Test File
Let’s see if it works.
Make a simple file:
echo "Hello, cloud!" > test.txt
Then upload it:
aws s3 cp test.txt s3://your-bucket-name/
Replace your-bucket-name
with your real bucket. If it works, you’ll see a progress bar and a success message.
Want to check if it’s there? Log in to AWS, go to S3, and look in your bucket. Hello, cloud!
Step 6: Write a Backup Script
Now let’s make it automatic.
Create a script file:
nano ~/s3-backup.sh
Paste this inside:
#!/bin/bash
DATE=$(date +%F)
BACKUP_DIR="/home/yourusername/documents"
S3_BUCKET="s3://your-bucket-name/backups"
aws s3 sync $BACKUP_DIR $S3_BUCKET/$DATE
Replace:
yourusername
with your actual Linux usernameyour-bucket-name
with your S3 bucket
Make it executable:
chmod +x ~/s3-backup.sh
Try it:
~/s3-backup.sh
It should back up your files into a folder labeled by date.
Step 7: Automate It with Cron
To make it run every day, use cron.
Edit your crontab:
crontab -e
Add this line:
0 2 * * * /home/yourusername/s3-backup.sh
This makes your backup run every night at 2 AM. You can change the time if you’re more of a night owl.
Quick Benefits of This Setup
- Peace of mind: No more panic attacks after deleting important files.
- No manual work: Once set up, it backs up by itself.
- You choose what to back up: Only save what matters.
Common Mistakes I Made (So You Don’t Have To)
Here’s where I messed up the first time:
- Forgot to give correct file permissions to my script.
- Misspelled my bucket name (twice).
- Used a weird region and wondered why nothing worked.
Don’t be like me. Double-check your spelling, and keep notes.
Tools That Help You Back Up to S3
If you want to explore more, here are other tools you can try:
- rclone
Good for syncing large directories and supports many cloud services. - Duplicity
Encrypted backups with support for S3. - Restic
Great for versioned and encrypted backups.
All of these run in the terminal and can work with S3.
Final Thoughts
Setting up Amazon S3 backup on Ubuntu might feel like building IKEA furniture at first. So many pieces, weird names, confusing instructions. But once it’s done, it works beautifully.
And when your hard drive crashes—or your cat walks across your keyboard and deletes a folder—you’ll be glad your files are floating safely in the cloud.
Backups aren’t magic, but they do feel like a time machine. So, what’s stopping you? Got a favorite folder you want to protect?
If this helped or made you smile, consider naming your next backup script “Sir Save-a-lot.”