Cloud 8.02

Snapshots and Backups

Understanding snapshots, database dumps, backup strategies, and restoration processes.

Exam Critical: Understanding how to create snapshots, backups, and database dumps is important for the exam!

Snapshots and Backups

mindmap root((Snapshots & Backups)) Snapshots All Starter and Pro Project Web Interface snapshots button magento cloud CLI Snapshot CLI snapshot create snapshot list snapshot restore Database Dump ece tools db dump DB Dump class mysqldump command Availability All environments Manual creation Restoration

Snapshots Overview

What Are Snapshots?

Key Facts

Snapshots are available for ALL Starter and Pro projects.

  • Complete backup of environment
  • Includes code, database, and files
  • Can be restored when needed
  • Available on all environments (integration, staging, production)
  • Manual creation (on-demand)
  • Essential for disaster recovery

What's Included in a Snapshot?

  • Code: All application code and configuration
  • Database: Complete database dump
  • Files: Uploaded media, generated files
  • Mounted directories: pub/media, var, etc.

Creating Snapshots: Project Web Interface

Web Interface Method

Location: Upper Right-Hand Corner

Snapshots can be created using the Project Web Interface with the "snapshots" button in the upper right-hand corner.

Step-by-Step Process

  1. Log in to Project Web Interface
  2. Navigate to the desired environment
  3. Look for "Snapshot" button in upper right-hand corner
  4. Click "Create Snapshot"
  5. Wait for snapshot creation (may take several minutes)
  6. Snapshot appears in the list of available backups

When to Create Snapshots

  • Before major deployments: Safe rollback point
  • Before configuration changes: Easy restoration
  • After significant content updates: Preserve work
  • Before module installations: Rollback if issues
  • Regular backups: Disaster recovery planning

Creating Snapshots: Magento Cloud CLI

Command Line Method

Create Snapshot Command

magento-cloud snapshot:create
# Create snapshot for current environment
magento-cloud snapshot:create

# Create snapshot for specific environment
magento-cloud snapshot:create -e staging

# Create snapshot with project ID
magento-cloud snapshot:create -p PROJECT_ID -e production
Command Output:
Creating a snapshot of master
  Waiting...
Snapshot created successfully

List Snapshots

# List all snapshots for environment
magento-cloud snapshot:list

# List with environment specified
magento-cloud snapshot:list -e production
Output Example:
Snapshots on the environment master:
+------------------+----------------------+------------+
| Created          | Snapshot name        | Restorable |
+------------------+----------------------+------------+
| 2024-01-15 10:30 | manual-2024011510    | Yes        |
| 2024-01-10 08:15 | manual-2024011008    | Yes        |
+------------------+----------------------+------------+

Restore Snapshot

# Restore a specific snapshot
magento-cloud snapshot:restore SNAPSHOT_NAME

# Restore with environment
magento-cloud snapshot:restore SNAPSHOT_NAME -e staging
Important:
  • Restoration overwrites current environment
  • Creates a backup of current state before restoring
  • Downtime may occur during restoration
  • Test restorations in non-production first

Database Dumps

Creating Database-Only Backups

Database Dump Command

You can create a database dump using the ./vendor/bin/ece-tools db-dump command.

Command Syntax

./vendor/bin/ece-tools db-dump
# Create database dump
./vendor/bin/ece-tools db-dump

# Output location
# /app/var/dump-main-TIMESTAMP.sql.gz
How It Works:
  • Uses the DB\Dump class
  • Utilizes the mysqldump command under the hood
  • Compresses output (gzip)
  • Saves to /app/var/ directory
  • Includes all database tables

Example Workflow

# SSH to environment
magento-cloud ssh -e production

# Create database dump
./vendor/bin/ece-tools db-dump

# Output:
# Database dump saved to /app/var/dump-main-1705315200.sql.gz

# Download dump to local
exit
magento-cloud mount:download --mount var --target ./local-var -e production

# Or use SCP
scp SSH_URL:/app/var/dump-main-*.sql.gz ./local-backup/

Database Dump Technical Details

Under the Hood

DB\Dump Class

Class Location:

vendor/magento/ece-tools/src/DB/Dump.php

Functionality:
  • Handles database connection credentials
  • Constructs mysqldump command
  • Applies gzip compression
  • Manages output file naming
  • Error handling and logging

mysqldump Command

What db-dump Executes:
mysqldump -h HOST -u USER -p PASSWORD DATABASE | gzip > dump-main-TIMESTAMP.sql.gz
Includes:
  • All database tables
  • Table structures (CREATE TABLE)
  • Table data (INSERT statements)
  • Indexes and constraints
  • Triggers (if any)

Snapshot vs Database Dump

When to Use Each

Feature Snapshot Database Dump
What's Included Code + Database + Files Database only
Creation Method Web UI or CLI (snapshot:create) CLI (ece-tools db-dump)
Speed Slower (full backup) Faster (DB only)
Size Larger Smaller
Restoration Complete environment restore Manual import required
Use Case Full disaster recovery Data migration, analysis
Download Via CLI or support Direct file download

Choose Snapshot When:

  • You need complete environment backup
  • Planning major changes or deployments
  • Want easy one-click restoration
  • Need to preserve code and files too

Choose Database Dump When:

  • You only need database backup
  • Want to download and analyze data locally
  • Need quick backup before data changes
  • Performing database migration

Best Practices

Backup Strategy

Do's

  • Create snapshots before deployments: Safe rollback point
  • Regular snapshot schedule: Weekly or before major changes
  • Test restoration process: Verify backups work
  • Document snapshot names: Know what each contains
  • Use db-dump for quick DB backups: Faster than full snapshot
  • Keep local copies: Download critical backups
  • Verify backup completion: Check logs for success

Don'ts

  • Don't rely on automatic backups only: Create manual snapshots
  • Don't skip pre-deployment snapshots: Always create one
  • Don't forget to test restoration: Verify process works
  • Don't delete all snapshots: Keep recent backups
  • Don't restore to production untested: Test in staging first

Common Scenarios

Practical Use Cases

Scenario 1: Pre-Deployment Snapshot

# Before deploying to production
magento-cloud snapshot:create -e production

# Deploy changes
git push production master

# If issues occur, restore
magento-cloud snapshot:restore SNAPSHOT_NAME -e production

Scenario 2: Database-Only Backup

# Quick DB backup before data import
magento-cloud ssh -e production
./vendor/bin/ece-tools db-dump

# Import new data
# bin/magento import:customers customers.csv

# If issues, restore from dump manually

Scenario 3: Download Database for Local Development

# Create dump on Cloud
magento-cloud ssh -e staging
./vendor/bin/ece-tools db-dump
exit

# Download to local
magento-cloud mount:download --mount var --target ./local-var -e staging

# Import to local database
gunzip local-var/dump-main-*.sql.gz
mysql -u root local_db < local-var/dump-main-*.sql

Scenario 4: Disaster Recovery

# Environment corrupted, need full restore
magento-cloud snapshot:list -e production

# Identify last good snapshot
magento-cloud snapshot:restore SNAPSHOT_NAME -e production

# Verify restoration
magento-cloud ssh -e production
bin/magento cache:flush

Automated vs Manual Snapshots

Backup Types

Automated Snapshots (Pro Production)

  • Adobe creates automatic backups of Pro production
  • Retention varies by plan
  • Cannot control schedule
  • Available for restoration through support

Manual Snapshots (All Environments)

  • Created on-demand by you
  • Available on ALL Starter and Pro environments
  • Full control over timing
  • Can restore yourself via CLI or UI
  • Recommended before any major change

Exam Tips

Key Points to Remember

  • Snapshots available: ALL Starter and Pro projects
  • Web UI location: "Snapshots" button in upper right-hand corner
  • CLI command: magento-cloud snapshot:create
  • Database dump: ./vendor/bin/ece-tools db-dump
  • DB\Dump class: Uses mysqldump command under the hood
  • Snapshot includes: Code + Database + Files (complete backup)
  • DB dump includes: Database only (faster, smaller)
  • Output location: /app/var/dump-main-TIMESTAMP.sql.gz
  • Compressed: Database dumps are gzipped
  • CLI commands: snapshot:create, snapshot:list, snapshot:restore
  • Best practice: Create snapshot before deployments
  • Restoration: Overwrites current environment