Menu
Coddy logo textTech

Success Message

Part of the Fundamentals section of Coddy's Terminal journey — lesson 79 of 82.

challenge icon

Challenge

Easy

Let's complete the backup script by adding a final success message that summarizes what was backed up.

Modify backup.sh to:

  1. Keep all the existing code from the previous lesson
  2. After the "Files copied successfully" message, add a final summary line
  3. Print: Backup complete: [source_dir] -> [backup_dir]

Run the script and enter documents when prompted. Your output should look like:

Backing up: documents
Created backup folder: backup_20240115_143052
Files copied successfully
Backup complete: documents -> backup_20240115_143052

The timestamp in your output will be different based on the current date and time.

Congratulations! You've built a complete backup script that:

  • Prompts the user for a source directory
  • Creates a timestamped backup folder
  • Copies all files to the backup
  • Provides clear feedback at each step

Hint: Add echo "Backup complete: $source_dir -> $backup_dir" at the end of your script to display the final summary message.

Try it yourself

Terminal
cat > backup.sh << 'EOF'
#!/bin/bash
echo "Enter folder to backup:"
read folder
echo "Backing up: $folder"
timestamp=$(date +%Y%m%d_%H%M%S)
backup_dir="backup_$timestamp"
mkdir "$backup_dir"
echo "Created backup folder: $backup_dir"
cp "$folder"/* "$backup_dir"/
echo "Files copied successfully"
EOF
chmod +x backup.sh
echo "documents" | bash backup.sh

All lessons in Fundamentals