RECIPE 079
데이터베이스 백업 자동화 → 클라우드 저장
- ▸PostgreSQL/MySQL 데이터베이스 정기 백업 자동 실행
- ▸백업 파일을 Google Drive/S3에 자동 업로드
- ▸백업 성공/실패 여부를 Slack으로 자동 알림
✅사전 준비
- □데이터베이스 읽기 전용 접속 계정 준비
- □n8n 서버에 pg_dump/mysqldump 설치 확인
- □Google Drive API 또는 AWS S3 자격증명 설정
- □백업 보존 기간 정책 결정 (예: 30일)
Execute Command 노드로 백업
// PostgreSQL 백업
Node: Execute Command
Command: pg_dump -h {{ $env.DB_HOST }} -U {{ $env.DB_USER }} -d {{ $env.DB_NAME }} -F c -f /tmp/backup_{{ $now.toFormat('yyyyMMdd_HHmmss') }}.dump
// MySQL 백업
Node: Execute Command
Command: mysqldump -h {{ $env.DB_HOST }} -u {{ $env.DB_USER }} -p{{ $env.DB_PASS }} {{ $env.DB_NAME }} > /tmp/backup_{{ $now.toFormat('yyyyMMdd') }}.sql
// 환경 변수는 n8n Settings → Variables에서 설정백업 파일 압축 + 업로드
// 압축
Node: Execute Command
Command: gzip /tmp/backup_{{ $json.filename }}
// Google Drive 업로드
Node: Google Drive (Upload File)
Folder ID: YOUR_BACKUP_FOLDER_ID
File Name: {{ $json.filename }}.gz
Binary Property: data
// 7일 이전 파일 정리
Node: Google Drive (List Files)
Query: modifiedTime < '{{ $now.minus({days: 30}).toISO() }}' and '{{ $json.folder_id }}' in parents💡 TIPn8n의 `Execute Command` 노드를 사용하려면 n8n 서버에서 해당 명령어 실행 권한이 있어야 합니다. Docker 환경이라면 컨테이너 내부에 pg_dump 등의 도구를 별도로 설치해야 합니다.
⚡
워크플로우 JSON
아래 JSON을 복사해 n8n에 바로 임포트하세요
📥 n8n 임포트 방법
n8n 화면 우측 상단 메뉴 (⋮) → Import from JSON → 아래 JSON 전체 복사 후 붙여넣기 → Import 클릭
n8n 화면 우측 상단 메뉴 (⋮) → Import from JSON → 아래 JSON 전체 복사 후 붙여넣기 → Import 클릭
{
"recipeId": "recipe079",
"title": "외부 기고 진행 상황 추적",
"chapter": 7,
"category": "콘텐츠 & 미디어 자동화",
"difficulty": "⭐⭐",
"estimatedTime": "25분",
"usedApps": [
"Google Sheets",
"Slack",
"Gmail"
],
"description": "외부 기고 제안 현황을 Google Sheets에서 관리하다가, 제안한 지 7일 이상 경과하고 상태가 '대기 중'인 항목을 매주 월요일 자동 조회해 담당자에게 '팔로업 해보세요!' Slack 알림을 발송합니다.",
"nodes": [
{
"id": "node1",
"type": "n8n-nodes-base.scheduleTrigger",
"name": "매주 월요일 오전 9시 실행",
"parameters": {
"rule": {
"interval": [
{
"field": "cronExpression",
"expression": "0 9 * * 1"
}
]
}
}
},
{
"id": "node2",
"type": "n8n-nodes-base.googleSheets",
"name": "기고 제안 현황 조회",
"parameters": {
"operation": "getAll",
"spreadsheetId": "={{$env.CONTENT_SHEET_ID}}",
"sheetName": "기고현황",
"filters": {
"conditions": [
{
"column": "상태",
"condition": "equals",
"value": "대기 중"
}
]
}
}
},
{
"id": "node3",
"type": "n8n-nodes-base.code",
"name": "7일 초과 항목 필터링",
"parameters": {
"jsCode": "const today = new Date();\nreturn items.filter(item => {\n const proposedDate = new Date(item.json['제안일']);\n const diffDays = Math.floor((today - proposedDate) / (1000 * 60 * 60 * 24));\n return diffDays >= 7;\n});"
}
},
{
"id": "node4",
"type": "n8n-nodes-base.if",
"name": "팔로업 대상 있음?",
"parameters": {
"conditions": {
"number": [
{
"value1": "={{$items().length}}",
"operation": "largerEqual",
"value2": 1
}
]
}
}
},
{
"id": "node5",
"type": "n8n-nodes-base.slack",
"name": "팔로업 알림 발송",
"parameters": {
"channel": "={{$json['담당자슬랙ID']}}",
"text": "📝 기고 팔로업 리마인더!\n\n매체: {{$json['매체명']}}\n기고 주제: {{$json['기고주제']}}\n제안일: {{$json['제안일']}}\n\n→ 아직 답변이 없어요. 한 번 연락해보시겠어요?"
}
}
],
"envVariables": {
"CONTENT_SHEET_ID": "Google Sheets 기고 현황 시트 ID"
},
"tips": [
"Google Sheets '기고현황' 탭에 매체명, 기고주제, 제안일, 상태, 담당자슬랙ID 열을 미리 구성해두세요.",
"답변을 받은 경우 상태를 '수락' 또는 '거절'로 변경하면 자동으로 팔로업 대상에서 제외됩니다.",
"월 단위로 기고 성과(수락률, 발행 건수)를 집계하는 레시피를 추가하면 PR 전략 수립에 도움이 돼요."
],
"qrUrl": "www.koreaaitimes.com/books/n8n-vol2/recipe079"
}