Automatic Website Restore from Backup Setup

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.
Development and maintenance of all types of websites:
Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:
Development stages
Latest works
  • image_website-b2b-advance_0.png
    B2B ADVANCE company website development
    1212
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_websites_belfingroup_462_0.webp
    Website development for BELFINGROUP
    852
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1041
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    822
  • image_bitrix-bitrix-24-1c_fixper_448_0.png
    Website development for FIXPER company
    815

Setting up automatic website restore from backup

Website restore from backup must be documented and tested before incident. Panic during emergency + unfamiliar restore process = hours of downtime. Goal: RTO (Recovery Time Objective) no more than 1 hour.

PostgreSQL restore script

#!/bin/bash
BACKUP_SOURCE="${1:-latest}"
TARGET_DB="${2:-myapp_restore}"
S3_BUCKET="s3://myapp-backups/postgresql"

if [ "$BACKUP_SOURCE" = "latest" ]; then
    BACKUP_FILE=$(aws s3 ls "${S3_BUCKET}/" | sort | tail -1 | awk '{print $4}')
    aws s3 cp "${S3_BUCKET}/${BACKUP_FILE}" "/tmp/${BACKUP_FILE}"
    LOCAL_FILE="/tmp/${BACKUP_FILE}"
fi

psql -U postgres -c "CREATE DATABASE ${TARGET_DB};" 2>/dev/null || true

gunzip -c "$LOCAL_FILE" | psql -U postgres -d "$TARGET_DB" -v ON_ERROR_STOP=1

TABLES=$(psql -U postgres -d "$TARGET_DB}" -t -c "SELECT COUNT(*) FROM information_schema.tables;")
echo "Restore completed. Tables: $TABLES"

rm -f "$LOCAL_FILE"

Full site restore

#!/bin/bash
DOMAIN="example.com"
APP_DIR="/var/www/myapp"
GIT_REPO="[email protected]:company/myapp.git"
GIT_TAG="${1:-main}"

# 1. Maintenance page
cat > /var/www/maintenance/index.html << 'EOF'
<h1>Technical maintenance</h1>
<p>Site unavailable. Recovery up to 60 minutes.</p>
EOF

# 2. Restore code from git
git clone --branch "$GIT_TAG" "$GIT_REPO" "$APP_DIR"
cd "$APP_DIR"
composer install --no-dev --optimize-autoloader

# 3. Restore database
/usr/local/bin/restore-db.sh latest myapp

# 4. Restore files
aws s3 sync s3://myapp-backups/files/uploads/ "${APP_DIR}/storage/app/uploads/"

# 5. Permissions and cache
chown -R www-data:www-data "$APP_DIR/storage"
php artisan config:cache
php artisan route:cache
php artisan migrate --force

# 6. Remove maintenance
nginx -s reload

# Verify
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" "https://${DOMAIN}/health")
if [ "$HTTP_CODE" = "200" ]; then
    echo "Recovery SUCCESSFUL"
fi

Runbook for on-call engineer

# Recovery Runbook: restore myapp after incident

## Step 1: Diagnostics (5 min)
- ssh web01.example.com
- systemctl status nginx php8.3-fpm postgresql
- tail -100 /var/log/nginx/error.log

## Step 2: Notification
- Update status page
- Slack #incidents message

## Step 3: Recovery
- Full: sudo /usr/local/bin/restore-site.sh v1.2.3
- DB only: sudo /usr/local/bin/restore-db.sh latest
- Files only: aws s3 sync s3://myapp-backups/files/ /var/www/myapp/storage/

## Step 4: Verification
- https://example.com/ → HTTP 200
- Login → success
- Critical functions from /docs/smoke-tests.md

## Step 5: Post-mortem
- Fill incident template in Confluence
- Add prevention to backlog

Monthly recovery drill

0 8 1 * * /usr/local/bin/restore-site.sh latest >> /var/log/dr-drill.log 2>&1 && \
  curl -fsS https://hc-ping.com/dr-drill-uuid > /dev/null

Implementation Timeline

Restore scripts with runbook: 2–3 days. Automated restore testing with monthly drill: 3–4 days.