Chuyển đến nội dung
Skillpedia
Cơ sở dữ liệu48k · #4329

database-backups

Skill này làm gì

Công cụ này giúp bạn tạo bản sao an toàn (bản sao lưu) cho cơ sở dữ liệu và thiết lập cách thức, thời điểm sao lưu. Nó cũng đảm bảo bạn có thể khôi phục dữ liệu nếu có sự cố.

Khi nào nên dùng

  • ✓Khi bắt đầu một cơ sở dữ liệu mới.
  • ✓Khi muốn tự động sao lưu hằng ngày hoặc hằng giờ.
  • ✓Khi lên kế hoạch khôi phục sau thảm họa.

Liên kết skill

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/database-backups/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/database-backups/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Thiết lập sao lưu tự động mỗi giờ cho cơ sở dữ liệu PostgreSQL của tôi và gửi bản sao lưu đến S3.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Công cụ dùng các công cụ chuyên dụng cho từng loại cơ sở dữ liệu (như pg_dump cho PostgreSQL hoặc mysqldump cho MySQL) để tạo bản sao. Các bản sao có thể được lưu cục bộ hoặc gửi đến một nơi lưu trữ đám mây an toàn như S3.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Database Backups

Implement comprehensive, automated database backup strategies with tested recovery procedures.

When to Use

  • You are deploying a new database and need a backup plan from day one.
  • You need to automate nightly or hourly backups for PostgreSQL, MySQL, or MongoDB.
  • You want to ship backups to S3-compatible object storage with retention policies.
  • You are building or verifying disaster recovery runbooks.

Prerequisites

  • Database client tools installed (pg_dump, mysqldump, mongodump).
  • AWS CLI or restic for remote storage.
  • cron or systemd timers for scheduling.
  • An S3 bucket (or S3-compatible endpoint) for offsite backups.

Backup Types

Type Description Frequency Use Case
Full Complete database copy Weekly Baseline for restores
Incremental Changes since last backup Daily Reduce storage and time
Transaction log / WAL Continuous log shipping Continuous Point-in-time recovery (PITR)
Snapshot Storage-level snapshot (EBS, ZFS) Daily Fast full restores

PostgreSQL Backups

Logical Backup with pg_dump

#!/bin/bash
# pg_backup.sh — PostgreSQL logical backup
set -euo pipefail

DB_NAME="mydb"
DB_USER="backup_user"
DB_HOST="localhost"
BACKUP_DIR="/backups/postgres"
DATE=$(date +%Y%m%d_%H%M%S)
FILENAME="${BACKUP_DIR}/${DB_NAME}_${DATE}.dump"

mkdir -p "$BACKUP_DIR"

# Custom compressed format (recommended for selective restore)
pg_dump -h "$DB_HOST" -U "$DB_USER" -Fc -Z6 "$DB_NAME" > "$FILENAME"

echo "[$(date)] PostgreSQL backup complete: $FILENAME ($(du -h "$FILENAME" | cut -f1))"

Physical Backup with pg_basebackup

#!/bin/bash
# pg_basebackup.sh — PostgreSQL physical backup for PITR
set -euo pipefail

BACKUP_DIR="/backups/postgres/base_$(date +%Y%m%d)"
mkdir -p "$BACKUP_DIR"

pg_basebackup \
  -h localhost \
  -U replicator \
  -D "$BACKUP_DIR" \
  --wal-method=stream \
  --checkpoint=fast \
  --progress \
  --verbose

echo "[$(date)] Base backup complete: $BACKUP_DIR"

PostgreSQL Restore

# Restore from custom-format dump
pg_restore -h localhost -U myapp -d mydb --clean --if-exists /backups/postgres/mydb_20250115_020000.dump

# Restore a single table
pg_restore -h localhost -U myapp -d mydb -t orders /backups/postgres/mydb_20250115_020000.dump

# Restore from plain SQL
psql -h localhost -U myapp -d mydb < /backups/postgres/mydb_20250115.sql

MySQL Backups

Logical Backup with mysqldump

#!/bin/bash
# mysql_backup.sh — MySQL logical backup
set -euo pipefail

DB_NAME="mydb"
DB_USER="backup_user"
DB_PASS="${MYSQL_BACKUP_PASSWORD}"
BACKUP_DIR="/backups/mysql"
DATE=$(date +%Y%m%d_%H%M%S)
FILENAME="${BACKUP_DIR}/${DB_NAME}_${DATE}.sql.gz"

mkdir -p "$BACKUP_DIR"

mysqldump -u "$DB_USER" -p"$DB_PASS" \
  --single-transaction \
  --routines \
  --triggers \
  --events \
  "$DB_NAME" | gzip > "$FILENAME"

echo "[$(date)] MySQL backup complete: $FILENAME ($(du -h "$FILENAME" | cut -f1))"

Physical Backup with Percona XtraBackup

#!/bin/bash
# xtrabackup.sh — MySQL physical backup
set -euo pipefail

BACKUP_DIR="/backups/mysql/full_$(date +%Y%m%d)"

xtrabackup --backup \
  --user=backup_user \
  --password "$MYSQL_BACKUP_PASSWORD" # from your vault; never hardcode \
  --target-dir="$BACKUP_DIR"

xtrabackup --prepare --target-dir="$BACKUP_DIR"

echo "[$(date)] XtraBackup complete: $BACKUP_DIR"

MySQL Restore

# Restore from compressed mysqldump
gunzip < /backups/mysql/mydb_20250115_020000.sql.gz | mysql -u root -p mydb

# Restore from XtraBackup
sudo systemctl stop mysql
ls /var/lib/mysql/*  # verify this is the correct data dir first
sudo find /var/lib/mysql -mindepth 1 -delete  # empty the data dir; snapshots must exist (see Limitations)
xtrabackup --move-back --target-dir=/backups/mysql/full_20250115
sudo chown -R mysql:mysql /var/lib/mysql
sudo systemctl start mysql

MongoDB Backups

Logical Backup with mongodump

#!/bin/bash
# mongo_backup.sh — MongoDB backup
set -euo pipefail

MONGO_URI="mongodb://backup_user:${MONGO_BACKUP_PASSWORD}@localhost:27017"
BACKUP_DIR="/backups/mongodb"
DATE=$(date +%Y%m%d_%H%M%S)
TARGET="${BACKUP_DIR}/${DATE}"

mkdir -p "$BACKUP_DIR"

# Full backup with compression
mongodump --uri="$MONGO_URI" --gzip --out="$TARGET"

echo "[$(date)] MongoDB backup complete: $TARGET"

MongoDB Restore

# Restore all databases

…
Câu hỏi thường gặp

Bản sao lưu là gì?

Đó là bản sao an toàn của dữ liệu. Nếu bạn mất dữ liệu gốc, bạn có thể dùng bản sao lưu để lấy lại.

Vì sao tôi cần bản sao lưu?

Để bảo vệ dữ liệu khỏi lỗi phần cứng, sai sót của con người, tấn công mạng hoặc thảm họa, đảm bảo bạn có thể khôi phục thông tin.

Khôi phục sau thảm họa là gì?

Đó là kế hoạch khôi phục hệ thống và dữ liệu sau một sự kiện lớn gây gián đoạn hoặc mất dữ liệu.

Chi tiết

Mô tả gốc của tác giả

Implement database backup strategies. Configure automated backups, retention, and recovery testing. Use when designing backup and recovery procedures.

repo: sickn33/agentic-awesome-skills

Độ phổ biến

Sao GitHub
48k
Vị trí xếp hạng
#4329
Giấy phép
MIT
Cập nhật
15/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự