MySQL Backup Script Generator

Build a ready-to-use mysqldump backup script for MySQL/MariaDB — gzip compression, retention cleanup, optional rsync remote transfer, timestamped filenames and cron schedule presets.

MySQL 백업 스크립트 생성기

MySQL/MariaDB용 mysqldump 백업 스크립트를 즉시 생성 — gzip 압축, 보관 기간 자동 정리, rsync 원격 전송, 타임스탬프 파일명, 크론 스케줄 프리셋 지원.

Credentials are read from ~/.my.cnf, not stored in this script
Older local backups are auto-deleted after this many days
backup.sh
Fill the form (or pick a cron preset) and click "Generate backup.sh"

How to Use

STEP 1

Set database & backup options

Enter the database name, MySQL user, and where backups should be stored. Keep gzip and timestamped filenames on for smaller, non-overwriting backups.

STEP 2

Add remote transfer (optional)

Enable rsync transfer and enter a user@host and remote path so backups leave the VPS — critical for real disaster recovery.

STEP 3

Pick a cron schedule

Click a preset — daily 2 AM, every 6 hours, or weekly Sunday 3 AM — or type your own crontab expression.

STEP 4

Generate, install & schedule

Copy or download backup.sh, follow the install instructions to save it as /usr/local/bin/backup-db.sh, chmod +x, and add the generated crontab line.

사용 방법

STEP 1

DB 및 백업 옵션 설정

데이터베이스 이름, MySQL 사용자, 백업 저장 위치를 입력하세요. gzip 압축과 타임스탬프 파일명을 켜두면 더 작고 덮어쓰지 않는 백업을 얻을 수 있습니다.

STEP 2

원격 전송 추가 (선택)

rsync 전송을 켜고 user@host와 원격 경로를 입력하면 백업이 VPS 밖으로 전송됩니다 — 실제 재해 복구에 필수입니다.

STEP 3

크론 스케줄 선택

프리셋(매일 새벽 2시, 매 6시간, 매주 일요일 새벽 3시)을 클릭하거나 직접 crontab 표현식을 입력하세요.

STEP 4

생성, 설치 및 스케줄 등록

backup.sh를 복사·다운로드한 뒤, 설치 안내에 따라 /usr/local/bin/backup-db.sh로 저장, chmod +x, 생성된 crontab 라인을 등록하세요.

Frequently Asked Questions

Never put a plaintext password directly in the script or on the mysqldump command line, since it becomes visible to anyone who reads the file or runs ps aux during the dump. Instead, create a ~/.my.cnf file with a [client] section containing user and password, then run chmod 600 ~/.my.cnf so only that account can read it — mysqldump picks up these credentials automatically. An alternative is a dedicated backup MySQL user with SELECT, LOCK TABLES and SHOW VIEW privileges only, further limiting the damage if credentials ever leak.
For a gzip-compressed dump, run gunzip -c backup_file.sql.gz | mysql -u root -p database_name to decompress and pipe the SQL directly into the target database. For an uncompressed .sql file, use mysql -u root -p database_name < backup_file.sql instead. Always restore into a freshly created or empty database first when testing, and confirm the dump completed successfully (no truncated file) before relying on it — periodically test-restoring backups is the only way to know they actually work.
A backup stored only on the same VPS as the live database is not a real disaster-recovery plan — if the server is compromised, the disk fails, or the provider account is suspended, the backups disappear along with the data they were meant to protect. Copying dumps off-box with rsync (or to object storage) to a separate host, provider, or region means a single point of failure cannot take out both your database and its backups at the same time. This is often called the 3-2-1 rule: at least 3 copies, on 2 different types of storage, with 1 copy off-site.
A common baseline is 7 daily backups for quick recent-history recovery, but the right number depends on your recovery point objective and how quickly you would notice data corruption or accidental deletion. Sites with slow-to-detect issues (e.g. a bad migration discovered weeks later) benefit from a tiered approach: keep daily backups for 7-14 days, plus a few weekly or monthly snapshots retained longer. Balance this against available disk space — the retention_days setting in this generator only controls local cleanup via find -mtime, so remote or object-storage copies can follow a separate, longer retention policy.
mysqldump is single-threaded and reads every row through SQL, so on databases in the tens or hundreds of gigabytes it can take hours and place heavy load on the server. mydumper is a drop-in alternative that dumps tables in parallel across multiple threads, cutting backup time significantly. For very large or high-write databases, physical/hot backup tools like Percona XtraBackup (MySQL/MariaDB) copy the underlying data files directly with minimal locking, and cloud-VPS snapshot features (LVM or provider-level disk snapshots) can capture a consistent point-in-time image almost instantly. mysqldump remains the simplest and most portable option for small-to-medium databases where a few minutes of extra load is acceptable.

자주 묻는 질문

스크립트나 mysqldump 명령줄에 평문 비밀번호를 직접 넣지 마세요 — 파일을 읽거나 덤프 중 ps aux를 실행하는 누구에게나 노출됩니다. 대신 ~/.my.cnf 파일에 [client] 섹션으로 user와 password를 넣고 chmod 600 ~/.my.cnf로 권한을 제한하면 mysqldump가 자동으로 이 값을 읽습니다. SELECT, LOCK TABLES, SHOW VIEW 권한만 가진 전용 백업 계정을 쓰면 자격증명이 유출되어도 피해를 줄일 수 있습니다.
gzip으로 압축된 덤프는 gunzip -c backup_file.sql.gz | mysql -u root -p database_name로 압축을 풀며 바로 대상 DB에 주입할 수 있습니다. 압축하지 않은 .sql 파일은 mysql -u root -p database_name < backup_file.sql을 사용하세요. 테스트할 때는 항상 새로 만든 빈 데이터베이스에 먼저 복원하고, 덤프가 잘리지 않고 완전히 끝났는지 확인한 뒤 신뢰하세요 — 주기적으로 실제 복원 테스트를 해보는 것만이 백업이 실제로 작동하는지 아는 유일한 방법입니다.
실제 DB와 같은 VPS에만 저장된 백업은 진정한 재해 복구 계획이 아닙니다 — 서버가 침해되거나, 디스크가 고장 나거나, 제공업체 계정이 정지되면 백업이 지키려던 데이터와 함께 사라집니다. rsync로 덤프를 다른 호스트·제공업체·리전으로 전송하면(또는 오브젝트 스토리지에 저장) 하나의 장애 지점이 DB와 백업을 동시에 무너뜨릴 수 없습니다. 이를 흔히 3-2-1 규칙이라 부릅니다 — 최소 3개 사본, 2가지 다른 저장 매체, 1개는 오프사이트.
일반적인 기준은 빠른 최근 복구를 위한 7일치 일일 백업이지만, 적절한 기간은 복구 시점 목표(RPO)와 데이터 손상·실수 삭제를 얼마나 빨리 알아차리는지에 달려 있습니다. 문제 발견이 느린 사이트(예: 몇 주 뒤 발견되는 잘못된 마이그레이션)는 일일 백업 7-14일 + 주간·월간 스냅샷을 더 오래 보관하는 계층형 전략이 유리합니다. 사용 가능한 디스크 공간과 균형을 맞추세요 — 이 생성기의 retention_days는 find -mtime를 통한 로컬 정리만 제어하므로, 원격이나 오브젝트 스토리지 사본은 별도의 더 긴 보관 정책을 따를 수 있습니다.
mysqldump는 단일 스레드로 SQL을 통해 모든 행을 읽기 때문에 수십~수백 기가바이트 규모 DB에서는 몇 시간이 걸리고 서버에 큰 부하를 줄 수 있습니다. mydumper는 여러 스레드로 테이블을 병렬 덤프하는 대체 도구로 백업 시간을 크게 줄여줍니다. 매우 크거나 쓰기가 많은 DB에는 Percona XtraBackup(MySQL/MariaDB) 같은 물리적·핫 백업 도구가 최소한의 잠금으로 데이터 파일을 직접 복사하며, 클라우드 VPS의 스냅샷 기능(LVM 또는 제공업체 디스크 스냅샷)은 거의 즉시 일관된 시점 이미지를 캡처할 수 있습니다. 몇 분의 추가 부하가 허용되는 중소 규모 DB에는 mysqldump가 여전히 가장 단순하고 이식성 좋은 선택입니다.