DEV Community

Azmat Ahmed
Azmat Ahmed

Posted on

DevOps Journey – Week 6: Completed Shell Scripting with a Server Backup Automation Project"

πŸš€ Week 6 of My DevOps Journey: Shell Scripting Completed πŸŽ‰

This week, I reached an exciting milestone: I officially completed my Shell Scripting course as part of my DevOps learning track. To make my learning more impactful, I built a real-world project β€” a server backup automation script using Bash and crontab.


🧠** What I Learned**

In this Shell Scripting course, I practiced:

  • Declaring and working with variables
  • Using for, while, and until loops
  • Handling conditions using if, else, and elif
  • Accepting user arguments via $1, $2, etc.
  • Creating .sh files and making them executable
  • Scheduling automation with crontab

πŸ› οΈ My Project – Server Backup Script

πŸ”Ή Problem:

I wanted to automatically back up a folder every day.

πŸ”Ή Solution:

I created a Bash script that:

  • Accepts source and backup folder as arguments
  • Compresses the source folder using tar
  • Appends a timestamp to the filename
  • Ensures the backup folder exists
  • Can be scheduled daily with crontab

πŸ”§ backup.sh


bash
#!/bin/bash

source_folder=$1
backup_folder=$2

mkdir -p "$backup_folder"

timestamp=$(date +%d-%m-%y-%H-%M-%s)
filename=$(basename "$source_folder")-backup-$timestamp.tar.gz

tar -czf "$backup_folder/$filename" "$source_folder"

echo "βœ… Backup created: $filename"
▢️ Run the Script
bash
Copy
Edit
bash backup.sh /home/ubuntu/data /home/ubuntu/backups
⏰ Automate with Cron
To schedule the script to run every night at midnight:

bash
Copy
Edit
crontab -e
Then add this line:

bash
Copy
Edit
0 0 * * * /bin/bash /home/ubuntu/backup.sh /home/ubuntu/data /home/ubuntu/backups
πŸ“Œ Why This Matters
This small project solidified my understanding of:

Automation

Bash scripting in real-world tasks

Scheduled jobs using cron

DevOps mindset: scripting + reliability

🧭 Next Step: Infrastructure as Code
Up next: learning Ansible and Terraform to automate server configurations and infrastructure provisioning.

πŸ”— GitHub Repo
πŸ“ https://github.com/Azmat-Ahmed/Shell-Scripting-Backup-Automation-DevOps-Journey-Week-6
πŸ™Œ Thanks for Reading!
Let me know what shell scripts you’ve built! Drop a comment or tag me with your feedback.

Enter fullscreen mode Exit fullscreen mode

Top comments (0)