Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects, and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Developer articles
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Aiddoo
Aido-platform
Repository navigation
Code
Issues
3
(3)
Pull requests
1
(1)
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
Aido-platform
/
scripts
/
ops
/
backup-database.sh
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
executable file
·
28 lines (23 loc) · 1.38 KB
main
Breadcrumbs
Aido-platform
/
scripts
/
ops
/
backup-database.sh
Copy path
Top
File metadata and controls
Code
Blame
executable file
·
28 lines (23 loc) · 1.38 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env bash
# 운영 DB를 pg_dump로 떠서 S3에 올린다. 서버 cron이 매일 03:00 UTC에 저장소의 이 파일을 실행한다.
# 설정은 ~/apps/backup.env(권한 600)의 BACKUP_DB_HOST·BACKUP_S3_URI, 비밀번호는 ~/.pgpass에서 읽는다.
set -euo pipefail
# 덤프는 사용자 데이터라 소유자만 읽는다
umask 077
# cron은 최소 PATH로 돌 수 있다. AWS CLI v2는 /usr/local/bin에 설치된다
export PATH="/usr/local/bin:/usr/bin:/bin"
# shellcheck source=/dev/null
source "${BACKUP_ENV_FILE:-$HOME/apps/backup.env}"
: "${BACKUP_DB_HOST:?BACKUP_DB_HOST 없음}" "${BACKUP_S3_URI:?BACKUP_S3_URI 없음}"
BACKUP_DIR="${BACKUP_DIR:-$HOME/backups}"
LOCAL_RETENTION_DAYS=7
backup_file="$BACKUP_DIR/aido_db_$(date -u +%Y%m%d_%H%M%S).sql.gz"
# pipefail이라 pg_dump가 실패하면 반쪽 파일을 올리지 않고 지운 뒤 멈춘다
trap 'rm -f "$backup_file"; echo "$(date -u +%FT%TZ) 백업 실패" >&2' ERR
mkdir -p "$BACKUP_DIR"
pg_dump -h "$BACKUP_DB_HOST" -U postgres aido | gzip >"$backup_file"
gzip -t "$backup_file"
aws s3 cp --only-show-errors "$backup_file" "$BACKUP_S3_URI/daily/$(basename "$backup_file")"
echo "$(date -u +%FT%TZ) 백업 완료: $(basename "$backup_file") ($(du -h "$backup_file" | cut -f1))"
# 올린 뒤에만 오래된 로컬 사본을 지운다
find "$BACKUP_DIR" -name 'aido_db_*.sql.gz' -mtime +"$LOCAL_RETENTION_DAYS" -delete
You can’t perform that action at this time.