Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
Sichere ProgrammierungRefreshed repository pull requests page generally available(22.09.2026 um 03:25 Uhr)
Sichere ProgrammierungThe Joy of Learning the Basics Again(22.09.2026 um 03:28 Uhr)
Sichere ProgrammierungZero-Code OpenTelemetry Tracing for Dagster(22.09.2026 um 03:39 Uhr)
Linux Tipps & Hardening`prime-all`(22.09.2026 um 02:28 Uhr)
IT Security Toolsopensoho v0.15.2(22.09.2026 um 03:33 Uhr)
IT Security NachrichtenUS Proposes AI Incident Alert System in Talks With China, Bessent Says(22.09.2026 um 04:01 Uhr)
Sichere ProgrammierungRefreshed repository pull requests page generally available(22.09.2026 um 03:25 Uhr)
Sichere ProgrammierungThe Joy of Learning the Basics Again(22.09.2026 um 03:28 Uhr)
Sichere ProgrammierungZero-Code OpenTelemetry Tracing for Dagster(22.09.2026 um 03:39 Uhr)
Linux Tipps & Hardening`prime-all`(22.09.2026 um 02:28 Uhr)
IT Security Toolsopensoho v0.15.2(22.09.2026 um 03:33 Uhr)
IT Security NachrichtenUS Proposes AI Incident Alert System in Talks With China, Bessent Says(22.09.2026 um 04:01 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

Day 9: Shell Scripting Challenge Directory Backup with Rotation

Day 9 task — on day 9, the task is to create a directory Back-up with rotation. Objective The objective of day 9 is to write a bash script that can back up a directory and retain only the 3 most recent backups, automatically deleting o…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

Day 9 task — on day 9, the task is to create a directory Back-up with rotation.



Objective



The objective of day 9 is to write a bash script that can back up a directory and retain only the 3 most recent backups, automatically deleting older ones. This is useful for automating backup tasks while managing disk space efficiently.



🔹 Step 1: Open your Terminal



🔹Step 2: Create a New Bash Script File

In your terminal




nano backup_with_rotation.sh







🔹 Step 3: Paste the Script

Copy and paste this into the terminal window:




#!/bin/bash

# Description:
# This script backs up a directory by creating a timestamped backup folder
# and implements a rotation mechanism to retain only the last 3 backups.

if [ -z "$1" ]; then
echo "Usage: $0 /path/to/target_directory"
exit 1
fi

TARGET_DIR="$1"

if [ ! -d "$TARGET_DIR" ]; then
echo "Error: Directory does not exist: $TARGET_DIR"
exit 1
fi

TIMESTAMP=$(date +"%Y-%m-%d_%H-%M-%S")
BACKUP_NAME="backup_$TIMESTAMP"
BACKUP_PATH="$TARGET_DIR/$BACKUP_NAME"

mkdir "$BACKUP_PATH"
cp -r "$TARGET_DIR"/* "$BACKUP_PATH" 2>/dev/null

echo "Backup created: $BACKUP_PATH"

cd "$TARGET_DIR"
BACKUPS=$(ls -dt backup_* 2>/dev/null)
NUM_BACKUPS=$(echo "$BACKUPS" | wc -l)

if [ "$NUM_BACKUPS" -gt 3 ]; then
TO_DELETE=$(echo "$BACKUPS" | tail -n +4)
echo "$TO_DELETE" | xargs rm -rf
echo "Old backups removed. Only the latest 3 are retained."
fi







Save and exit the text editor.



🔹 Step 4: Make the Script Executable




chmod +x backup_with_rotation.sh







🔹 Step 5: Create a Test Directory:




mkdir test_dir
touch test_dir/file{1..5}.txt







🔹 Step 6: Run the Script




./backup_with_rotation.sh ./test_dir







output:




Backup created: ./test_dir/backup_YYYY-MM-DD_HH-MM-SS






Run multiple times to see the backup rotation in effect.



🔹 Step 7. Create a GitHub Repository

Go to https://github.com/new.




  • Name the Repository - 90DaysOfDevOps-Day9



Choose:



Public or Private



Don't initialize with a README.



Click "Create repository"



🔹 Step 8. Clone the Repository

back in your IDE




git clone https://github.com/your-username/90DaysOfDevOps-Day9.git
cd 90DaysOfDevOps-Day9







🔹 Step9. Move Your Script into the Repo Folder

If your script is outside the cloned folder:




mv ../backup_with_rotation.sh .







🔹 Step 10. Initialize Git

If you didn’t clone, but are working in a folder you want to turn into a repo:




git init
git remote add origin https://github.com/your-username/90DaysOfDevOps-Day9.git







🔹 Step 11. Add and Commit




git add backup_with_rotation.sh
git commit -m "Add Day 9 backup with rotation script"







🔹 Step 7. Push to GitHub




git push origin main



Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Day 9: Shell Scripting Challenge Directory Backup with Rotation

Thematisch verwandte Begriffe: Shell, Scripting, Challenge, Directory · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-61647 | NotebookLM MCP is an MCP server and HTTP service for interacting with Go…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick