Backup Status aaPanel → Synology NAS ← Quay lại Dashboard

Hướng dẫn Khôi phục Dữ liệu (Restore)

Tài liệu này hướng dẫn khôi phục dữ liệu (website, database) cho các trường hợp xử lý sự cố hàng ngày (lỡ tay xoá file, cần rollback,...).

Lưu ý: Nếu VPS của bạn bị hỏng hoàn toàn (mất sạch toàn bộ dữ liệu trên ổ cứng), vui lòng tham khảo file docs/backup-dr-runbook.md trong mã nguồn dự án.

Thông tin chuẩn bị chung

Khôi phục từ bản lưu trữ trực tiếp trên VPS. Sử dụng thư mục mặc định: /opt/backup/repo

1. Tìm bản backup (Snapshot) cần khôi phục

restic -r /opt/backup/repo --password-file /opt/backup/secrets/repo-passphrase snapshots

Ghi lại ID của snapshot (VD: d2b8b93f) và thay chữ latest bằng ID này ở các bước dưới (nếu không muốn lấy bản mới nhất).

2. Khôi phục một Website cụ thể

restic -r /opt/backup/repo --password-file /opt/backup/secrets/repo-passphrase restore latest \
  --target / \
  --include /www/wwwroot/domain.com

3. Khôi phục toàn bộ Website & Cấu hình

restic -r /opt/backup/repo --password-file /opt/backup/secrets/repo-passphrase restore latest --target /
Lệnh này sẽ ghi đè toàn bộ dữ liệu hiện tại ở thư mục wwwroot và config Nginx/Panel.

4. Khôi phục Database

Sau khi chạy lệnh restore (Bước 3), các file dump database sẽ được phục hồi về /opt/backup/staging/. Chạy lệnh dưới để import:

MongoDB:

gunzip -c /opt/backup/staging/docker/tên-container.dump.gz | docker exec -i tên-container mongorestore --archive --drop

MySQL:

gunzip -c /opt/backup/staging/sql/tên-db.sql.gz | mysql tên-db

Sử dụng khi thư mục /opt/backup/repo trên VPS bị mất hoặc lỗi.

1. Kéo bản dự phòng từ NAS về VPS

Cách 1: Kéo tự động bằng script (Khuyên dùng)

bash /root/superback-host/restore-from-nas.sh /opt/restore-from-nas/repo

Cách 2: Tải thủ công

2. Tìm bản backup (Snapshot)

restic -r /opt/restore-from-nas/repo --password-file /opt/backup/secrets/repo-passphrase snapshots

3. Khôi phục một Website cụ thể

restic -r /opt/restore-from-nas/repo --password-file /opt/backup/secrets/repo-passphrase restore latest \
  --target / \
  --include /www/wwwroot/domain.com

4. Khôi phục toàn bộ Website & Cấu hình

restic -r /opt/restore-from-nas/repo --password-file /opt/backup/secrets/repo-passphrase restore latest --target /

5. Khôi phục Database

Tiến hành import sau khi các file dump đã được restore về /opt/backup/staging/:

MongoDB:

gunzip -c /opt/backup/staging/docker/tên-container.dump.gz | docker exec -i tên-container mongorestore --archive --drop

MySQL:

gunzip -c /opt/backup/staging/sql/tên-db.sql.gz | mysql tên-db