Skip to content

ahmed-sayed-devops/aws-s3-automated-backup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧰 Automated Backup to S3 using Bash Script

This project automates backing up a local directory using Bash. It compresses the directory, stores the archive locally, uploads it to an AWS S3 bucket, and uses cron to automate the process every 2 minutes. All steps are documented with screenshots.


🖼 Project Overview

Project Cover


🧱 Project Architecture

The following diagram shows the structure and flow of the backup process, including local compression, S3 upload, and automation using cron.

Project Diagram


📁 Project Structure

. ├── scripts/ │ ├── backup-local.sh │ ├── backup-to-s3.sh ├── screenshots/ │ ├── 01-first-script.png │ ├── ... ├── Project Architecture/ │ ├── project-cover.png │ ├── project-diagram.png ├── README.md


🧾 Script 1: Local Backup Script

A basic Bash script to compress a local directory into a .tar.gz archive.

Local Backup Script

🔹 Testing the Script

  • Run without argument (error)
  • Run with valid directory: creates archive and log file

Test Run - Error and Success

🔹 Archive content after backup

Backup Archive Content


🔐 AWS Configuration

Create IAM user with S3FullAccess

IAM User

Create IAM Role with S3 & SSM FullAccess

IAM Role

Attach IAM Role to EC2 Instance

Attach Role

Install AWS CLI on EC2

Install AWS CLI


☁ S3 Bucket Setup

Check: No buckets exist

No Buckets Yet

Create S3 bucket via AWS CLI

bash aws s3 mb s3://your-bucket-name

Create Bucket

Confirm bucket created in Console

Bucket Confirmed


🚀 Script 2: Backup + Upload to S3

A Bash script that compresses the folder and uploads the archive to S3.

Second Script

🔹 First manual run

Manual Run

🔹 S3 Console confirms upload

S3 Upload

🔹 Local backup folder check

Local Folder

🔹 Final archive contents

Archive Internal


⏱ Automate with Cron

Add cronjob in /etc/crontab

bash */2 * * * * ec2-user /home/ec2-user/scripts/backup-to-s3.sh

Crontab Entry

First test – wait 2 minutes

Auto Backup 1

S3 check after auto backup

S3 Auto Upload

Confirm backup continues every 2 minutes

Auto Backup 2

Log file after auto backups

Log File


📦 Final S3 and Archive Checks

S3 Bucket Final Content

S3 Final

Archive after modifying source dir

Final Archive


🧹 Cleanup

Delete bucket using CLI

bash aws s3 rb s3://your-bucket-name --force

Delete Bucket

Confirm deletion in console

Confirm Delete


📌 Notes

  • Tested on Amazon Linux EC2 with AWS CLI v2
  • Make sure the IAM Role has correct permissions
  • Cronjob runs every 2 minutes (customizable)
  • All logs saved to backup.log

👤 Author

Ahmed Sayed
LinkedIn
GitHub


📜 License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A Bash script that automates local file backups and uploads them to AWS S3 with IAM role configuration and scheduled cron jobs.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages