Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Backups of Drupal sites
#!/bin/bash
# DATOS
WEB_ROOT=/apps/
BACKUP_ROOT=/home/core/backups
DB_USER=backup #Permiso para SELECT y LOCK TABLES
DB_PASSWORD=b4ckup
DAYS_FOR_BACKUP=100
DATE=$( date -I )
#[directory]=database
declare -A WEBS=(
[web_ishcom]=ishcom_db
[web_ctes]=ctes_db
)
#Script
for directory in "${!WEBS[@]}" ;
do
DATABASE_NAME=${WEBS[$directory]}
APP_DIRECTORY=$WEB_ROOT$directory
BACKUP_DIR="$BACKUP_ROOT/$directory/$DATE"
MYSQL_BACKUP_FILE="$BACKUP_DIR/$DATABASE_NAME-$DATE.sql"
APP_BACKUP_FILE="$BACKUP_DIR/$directory-$DATE.tar.gz"
if [ ! -d "$BACKUP_DIR" ]; then
mkdir -p $BACKUP_DIR
fi
echo "backup dir: $APP_DIRECTORY to $APP_BACKUP_FILE";
tar czf $APP_BACKUP_FILE $APP_DIRECTORY
echo "backup database: $DATABASE_NAME to $MYSQL_BACKUP_FILE";
mysqldump -u$DB_USER -p$DB_PASSWORD $DATABASE_NAME > $MYSQL_BACKUP_FILE
done
@isholgueras
Copy link
Author

isholgueras commented Jul 13, 2015

Ahora es dinámico, y con un array asociativo se asocia el nombre del directorio con el nombre de la base de datos.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment