#!/bin/bash USER_ROOT=/home/fasoonli CONFIG_FILE="$USER_ROOT/backup-config" . $CONFIG_FILE if [ $# -eq 0 ]; then echo "Usage: $0 BACKUP_NAME" exit 1 fi BACKUP_NAME="$1" BACKUP_NAME_Q=$(quote_name "$BACKUP_NAME") BACKUP_PATH="$BACKUP_ROOT/$BACKUP_NAME_Q" BACKUP_PATH_FILES="$BACKUP_PATH/files" BACKUP_PATH_DB="$BACKUP_PATH/db" if [ -d $BACKUP_PATH ]; then echo -e "The backup \"$BACKUP_NAME\" already exists.\nPlease use another name or remove it with ./$SCRIPT_REMOVE \"$BACKUP_NAME\" before proceeding" echo -e "Use ./$SCRIPT_LIST to view all backups" exit 2 fi #good to go mkdir -p $BACKUP_PATH_FILES mkdir -p $BACKUP_PATH_DB #backup database #uses credentials from .my.cnf for db_name in $DB_NAMES; do $MYSQLDUMP -Q --skip-triggers --single-transaction --hex-blob -n $db_name | $GZIP > "$BACKUP_PATH_DB/$db_name.sql.gz" done #backup files, only public_html for now $RSYNC -av --delete "$USER_ROOT/public_html" "$BACKUP_PATH_FILES" #save metadata, so the backup can be found and restored echo -n "$BACKUP_NAME" > "$BACKUP_PATH/$METATXT" echo Done!