0Pricing
Supabase Backend as a Service · 课时

备份、恢复与灾难恢复

了解 Supabase 的备份机制,学习如何执行手动备份,并为数据制定灾难恢复计划

备份、恢复与灾难恢复 是 CoddyKit 上的免费 Supabase Backend as a Service 课时。 这是第 2 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Supabase Backend as a Service 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Supabase Backend as a Service 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

Data Safety: Why Backups?

In the world of applications, your data is one of your most valuable assets. Losing it due to an accident, corruption, or malicious activity can be catastrophic.

This lesson will guide you through Supabase's backup mechanisms, how to perform manual backups, and how to create a solid Disaster Recovery Plan (DRP).

Supabase's Automatic Backups

Supabase provides robust automatic backup solutions to protect your database. These backups are taken daily and stored securely.

  • Daily Snapshots: Your entire database is backed up automatically every 24 hours.
  • Retention: These backups are typically retained for 7 days on the free plan and up to 30 days on paid plans.
  • Managed Service: Supabase handles the complexity of these backups for you, ensuring data durability.

Understanding Backup Types

When discussing database backups, it's helpful to understand the difference between logical and physical backups:

  • Logical Backups: These export your database schema and data as a series of SQL commands. They are flexible and portable, great for migrating data. pg_dump creates logical backups.
  • Physical Backups: These are direct copies of the database files on disk. They are faster for large databases but less portable. Supabase's automatic backups are typically physical snapshots.

Performing Manual Database Dumps

While Supabase handles automatic backups, performing manual dumps gives you direct control over specific data points or for local development. You can use the standard PostgreSQL tool pg_dump via your terminal.

Remember to replace <YOUR_DB_HOST> with your actual database host (e.g., db.<PROJECT_REF>.supabase.co) and set the PGPASSWORD environment variable before running.

PGPASSWORD="<YOUR_DB_PASSWORD>" pg_dump \
  -h <YOUR_DB_HOST> -p 5432 \
  -U postgres -d postgres > my_supabase_backup.sql

Restoring from a Manual Backup

To restore your database from a .sql backup file, you can use the psql command-line client. This is useful for migrating data or recovering to a specific state.

Important: Restoring usually involves dropping existing tables, so be extremely careful and ensure you have a fresh backup of your current state before proceeding!

PGPASSWORD="<YOUR_DB_PASSWORD>" psql \
  -h <YOUR_DB_HOST> -p 5432 \
  -U postgres -d postgres \
  < my_supabase_backup.sql

Point-in-Time Recovery (PITR)

For business-critical applications, Supabase offers Point-in-Time Recovery (PITR) on higher-tier plans. This advanced feature allows you to restore your database to *any* specific second within a given retention period.

PITR is crucial for minimizing data loss in scenarios where you need to undo a specific accidental change or recover from a precise moment before an incident occurred.

Backing Up Supabase Storage

Beyond your database, Supabase Storage holds your application's files (images, videos, documents). Unlike the database, Storage buckets are not automatically backed up by Supabase in the same way.

You should implement your own strategy for backing up critical files from your Storage buckets. This might involve:

  • Regularly downloading files using the Supabase CLI.
  • Using a custom script that interacts with the Storage API.
  • Integrating with cloud storage backup services.

What is a Disaster Recovery Plan?

A Disaster Recovery Plan (DRP) is a documented process for an organization to recover from an unplanned event that disrupts normal operations. It's more comprehensive than just backups.

A DRP outlines steps to ensure your application can quickly resume critical functions after a major incident, such as a regional outage, data center failure, or severe data corruption.

Key DRP Components

A robust Disaster Recovery Plan (DRP) should include:

  • Recovery Time Objective (RTO): The maximum acceptable downtime.
  • Recovery Point Objective (RPO): The maximum acceptable amount of data loss.
  • Roles & Responsibilities: Who does what during a disaster.
  • Communication Plan: How to inform users and stakeholders.
  • Testing Schedule: Regularly testing the DRP to ensure it works.
  • Runbooks: Step-by-step guides for recovery procedures.

DRP Quick Check

Consider the core components of a Disaster Recovery Plan (DRP).

Recap: Data Safety First

Congratulations! You've learned about the critical aspects of data safety with Supabase.

  • Supabase provides automatic daily database backups.
  • You can perform manual logical backups and restores using pg_dump and psql.
  • Point-in-Time Recovery offers advanced restoration capabilities.
  • Remember to plan for backing up your Supabase Storage files.
  • A comprehensive Disaster Recovery Plan (DRP) is essential for business continuity, defining RTO, RPO, roles, and testing.

Always prioritize your data's safety!

常见问题解答

「备份、恢复与灾难恢复」课时是免费的吗?

是的 — 「备份、恢复与灾难恢复」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Supabase Backend as a Service 课程的其余内容,请升级到 CoddyKit PRO。 Supabase Backend as a Service 课程共包含 4 节课。

「备份、恢复与灾难恢复」这节课中我会学到什么?

了解 Supabase 的备份机制,学习如何执行手动备份,并为数据制定灾难恢复计划 你通过在浏览器中直接运行的动手代码来练习 Supabase Backend as a Service,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 Supabase Backend as a Service 需要有经验吗?

无需任何先前经验。CoddyKit 上的 Supabase Backend as a Service 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 2 节课,共 4 节。

「备份、恢复与灾难恢复」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 Supabase Backend as a Service 课中编写并运行代码吗?

能。每节 Supabase Backend as a Service 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. 环境管理与持续集成/持续交付
  2. 备份、恢复与灾难恢复
  3. 安全审计与最佳实践
  4. 监控、日志记录与可观测性
← 返回 Supabase Backend as a Service