π 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
, anduntil
loops - Handling conditions using
if
,else
, andelif
- 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.
Top comments (0)