Segue o script:

#!/bin/bash

# Set variables (replace with your actual values)
backupdir="/home/wdigital/_BACKUP/"
dbuser="your_username"
dbname="your_database_name"
dbpass="your_password"
dbhost="your_database_host" # (if applicable)
backupdb="backup_$(date +%s).sql"  # Temporary backup file
backupfile="backup_$(date +%s).tar.gz"
backup_img="images_$(date +%s).tar.gz"
origem_img="/path/to/your/images"  # Replace with actual path

# Create directory with permissions 766 (modify if needed)
mkdir -p "$backupdir"  # Assuming backupdir is already defined
chmod 0766 "$backupdir"

# Backup databases based on type
# Check for PostgreSQL
if which pg_dump >/dev/null 2>&1; then
  pg_dump -U "$dbuser" "$dbname" > "$backupdir/$backupdb"
fi

# Check for MySQL
if which mysqldump >/dev/null 2>&1; then
  mysqldump -h "$dbhost" -u "$dbuser" -p"$dbpass" --lock-tables "$dbname" > "$backupdir/$backupdb"
fi

# Check for SQLite
if which sqlite3 >/dev/null 2>&1; then
  sqlite3 "$dbname" ".dump" > "$backupdir/$backupdb"
fi

# Check for Firebird (assuming gbak exists)
if which gbak >/dev/null 2>&1; then
  gbak -backup -v -ignore "$dbname" "$backupdir/$backupdb" -user "$dbuser" -pass "$dbpass"
fi

# Create compressed archive of the backup file
tar -czvf "$backupdir/$backupfile" "$backupdir/$backupdb"

# Remove the temporary backup file
#rm -f "$backupdir/$backupdb"

# Create compressed archive of images (modify path as needed)
tar -czvf "$backupdir/$backup_img" "$origem_img"

# Remove the temporary backup directory (assuming it's empty)
# Use with caution, only if backupdir is not used for other purposes
# rm -rf "$backupdir"

 

Hai trovato utile questa risposta? 0 Utenti hanno trovato utile questa risposta (0 Voti)