revise backup
parent
f6db0d4dd9
commit
d8c7209b7a
|
@ -107,22 +107,31 @@ function create_snapshot(){
|
|||
|
||||
function backup(){
|
||||
local backup_repo_path="/mnt/backups/${ENV_NAME}"
|
||||
mkdir -p "${backup_repo_path}"
|
||||
echo $$ > "/var/run/${ENV_NAME}_backup.pid"
|
||||
echo "$(date) ${ENV_NAME} Creating the ${BACKUP_TYPE} backup (using the backup addon with commit id ${BACKUP_ADDON_COMMIT_ID})" | tee -a "${BACKUP_LOG_FILE}"
|
||||
echo "$(date) ${ENV_NAME} Creating the ${BACKUP_TYPE} backup" | tee -a "${BACKUP_LOG_FILE}"
|
||||
|
||||
# Database credentials and dump
|
||||
source /var/www/webroot/ROOT/wp-config.php
|
||||
DB_HOST=$(echo "${DB_HOST}" | awk -F ':' '{print $1}')
|
||||
DB_PORT=$(echo "${DB_HOST}" | awk -F ':' '{print $2:-3306}')
|
||||
# Ensure Restic repository is initialized
|
||||
restic -r "${backup_repo_path}" snapshots &>/dev/null || restic -r "${backup_repo_path}" init
|
||||
|
||||
# Extract database credentials
|
||||
DB_NAME=$(grep DB_NAME /var/www/webroot/ROOT/wp-config.php | cut -d "'" -f 4)
|
||||
DB_USER=$(grep DB_USER /var/www/webroot/ROOT/wp-config.php | cut -d "'" -f 4)
|
||||
DB_PASSWORD=$(grep DB_PASSWORD /var/www/webroot/ROOT/wp-config.php | cut -d "'" -f 4)
|
||||
DB_HOST=$(grep DB_HOST /var/www/webroot/ROOT/wp-config.php | cut -d "'" -f 4 | awk -F':' '{print $1}')
|
||||
DB_PORT=$(grep DB_HOST /var/www/webroot/ROOT/wp-config.php | cut -d "'" -f 4 | awk -F':' '{print $2}')
|
||||
DB_PORT=${DB_PORT:-3306}
|
||||
|
||||
echo "$(date) ${ENV_NAME} Creating the DB dump" | tee -a "${BACKUP_LOG_FILE}"
|
||||
if ! mysqldump -h "${DB_HOST}" -P "${DB_PORT}" -u "${DB_USER}" -p"${DB_PASSWORD}" "${DB_NAME}" --force --single-transaction --quote-names --opt --databases > "${backup_repo_path}/wp_db_backup.sql"; then
|
||||
mysqldump -h "${DB_HOST}" -P "${DB_PORT}" -u "${DB_USER}" -p"${DB_PASSWORD}" "${DB_NAME}" --force --single-transaction --quote-names --opt --databases > "${backup_repo_path}/wp_db_backup.sql"
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "$(date) ${ENV_NAME} DB backup process failed." | tee -a "${BACKUP_LOG_FILE}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Backup process
|
||||
if ! restic -r "${backup_repo_path}" backup "${backup_repo_path}/wp_db_backup.sql" "${APP_PATH}" --tag "${BACKUP_TYPE}" --host "${ENV_NAME}"; then
|
||||
restic -r "${backup_repo_path}" backup "${backup_repo_path}/wp_db_backup.sql" "${APP_PATH}" --tag "${BACKUP_TYPE}" --host "${ENV_NAME}"
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "$(date) ${ENV_NAME} Backup process failed." | tee -a "${BACKUP_LOG_FILE}"
|
||||
exit 1
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue