Linux Bash Script for Automated Database and Logs Backup
- Category DevOps
- Type Command
- Platform Linux
- Language Bash
- Price Free
- Copy 32 741
- Comments 0
Linux Bash Script for Automated Database and Logs Backup
#!/bin/bash
# Configuration and path settings
BACKUP_DIR="/var/backups/snippet_app"
SOURCE_DIR="/var/www/snippet_app/logs"
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
ARCHIVE_NAME="logs_backup_$TIMESTAMP.tar.gz"
# Guarantee clean container directory state exists
mkdir -p "$BACKUP_DIR"
# Package and compress targets using standard system stream tar utilities
tar -czf "$BACKUP_DIR/$ARCHIVE_NAME" "$SOURCE_DIR"
# Retain only the last 7 daily data states to maintain healthy disk capacities
find "$BACKUP_DIR" -type f -mtime +7 -name "*.tar.gz" -delete
echo "Infrastructure backup operation completed successfully at: $TIMESTAMP"
Free snippet — copy & paste!
Copy this snippet for free on Clayi Code. One click — no account required.

There are no comments yet :(