Hướng dẫn Khôi phục Dữ liệu (Restore)
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
- Passphrase giải mã: nằm ở
/opt/backup/secrets/repo-passphrase - Repo URL (chứa mật khẩu rest-server): nằm ở
/opt/backup/secrets/repo-url
Repo restic nằm trực tiếp trên NAS (/volume2/Work 2024/BackupWebsite/restic-repo-v2), VPS đọc qua rest-server (append-only) qua SSH tunnel nas-tunnel.service — không cần tải cả repo về.
0. Khai báo repo (chạy trên VPS, user root)
Kiểm tra tunnel trước: systemctl is-active nas-tunnel.service (phải ra active).
export RESTIC_REPOSITORY_FILE=/opt/backup/secrets/repo-url
export RESTIC_PASSWORD_FILE=/opt/backup/secrets/repo-passphrase
Hoặc chạy nhanh: bash /opt/backup/restore-from-nas.sh (liệt kê snapshot + in lệnh mẫu).
1. Tìm bản backup (Snapshot) cần khôi phục
restic 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 restore latest --target / --include /www/wwwroot/domain.com
3. Khôi phục toàn bộ Website & Cấu hình
restic restore latest --target /
4. Khôi phục Database
Sau khi restore, các file dump database nằm ở /opt/backup/staging/. 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
Từ máy khác (VPS chết hẳn)
Cần: restic, file passphrase, mật khẩu rest-server (user goku), và 1 SSH key được NAS chấp nhận (dòng authorized_keys có permitopen="127.0.0.1:18080", do admin thêm). Alias nas-backup trong ~/.ssh/config, rồi mở tunnel ở terminal riêng: ssh -N -L 28480:127.0.0.1:18080 nas-backup. Sau đó đặt RESTIC_REPOSITORY_FILE trỏ tới file chứa rest:http://goku:<pass>@127.0.0.1:28480/goku/ và chạy các lệnh như trên.