Skip to main content

Lab 12.1 - Production Administration

Objectives​

  • Apply best practices
  • Configure maintenance
  • Implement backups
  • Monitor system health

Exercise 1: Backup Script​

# Automatic backup
cat > backup.sh << 'EOF'
#!/bin/bash
BACKUP_DIR="/backup"
SOURCE="/data"
DATE=$(date +%Y%m%d_%H%M%S)
tar -czf "$BACKUP_DIR/backup-$DATE.tar.gz" "$SOURCE"
find "$BACKUP_DIR" -name "*.tar.gz" -mtime +7 -delete
EOF

chmod +x backup.sh

Exercise 2: Health Checks​

# Check script
cat > health-check.sh << 'EOF'
#!/bin/bash
# Check services
systemctl is-active nginx || echo "ALERT: nginx inactive"
# Check disk space
df -h / | awk 'NR==2 {if ($5+0 > 90) print "ALERT: Disk > 90%"}'
EOF

chmod +x health-check.sh

Lab created on: December 2024 - Tested on Ubuntu 24.04