Home / CodeDevOps / DevOps / Linux Bash Script for Automated Database and Logs Backup

Linux Bash Script for Automated Database and Logs Backup

Linux Bash Script for Automated Database and Logs Backup
  • Category DevOps
  • Type Command
  • Platform Linux
  • Language Bash
  • Price Free
  • Copy 32 741
  • Comments 0
Go to Code
Linux Bash Script for Automated Database and Logs Backup

Linux Bash Script for Automated Database and Logs Backup

Copy this Bash snippet on Clayi Code — one click, no account required. Free DevOps commands and configs with one-click copy — built for teams that ship fast.

What it does and when to use

Deployment, Git, containers, web servers, SSH, CI/CD, or automation — ready to paste into your workflow. Apply it for repo tasks, image builds, config changes, log checks, or pipeline steps.

How to copy from Clayi Code

Paste into your terminal, Dockerfile, nginx/Apache vhost, Compose file, or CI workflow YAML.

Validate and stay safe

Run nginx -t, apachectl configtest, docker compose config, or dry-run Git commands before production. Test on staging servers first; watch permissions, secrets, and destructive flags. Use least-privilege tokens in CI/CD pipelines.

DevOps reference

Category: DevOps. Tool: Bash. Platform: Linux. Format: Command.

Popularity
0%
  • Votes: 2863
  • 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.

Similar Snippets

Populer Snippets

There are no comments yet :(

Linux Bash Script for Automated Database and Logs Backup
Tell us what you think about "Linux Bash Script for Automated Database and Logs Backup"
Information
Users of Guests are not allowed to comment this publication.