feat: Add database backup system
- Add Dockerfile.backup for backup container - Add backup.py script with PostgreSQL backup functionality - Add backup service to docker-compose.prod.yml - Update env.production.example with backup configuration - Add db/README.md with backup system documentation Features: - Automated daily backups (07:30, 18:00) - Local and FTP remote backup support - 7-day retention policy - PostgreSQL 16 client for waceplm database
This commit is contained in:
54
Dockerfile.backup
Normal file
54
Dockerfile.backup
Normal file
@@ -0,0 +1,54 @@
|
||||
# Use an official Python runtime as a parent image
|
||||
FROM dockerhub.wace.me/python:3.10-slim.linux
|
||||
|
||||
# Set environment variables
|
||||
ENV PYTHONDONTWRITEBYTECODE=1
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
ENV TZ=Asia/Seoul
|
||||
|
||||
# Install system dependencies including PostgreSQL client 16
|
||||
RUN apt-get update && \
|
||||
apt-get install -y --no-install-recommends \
|
||||
gnupg \
|
||||
lsb-release \
|
||||
wget \
|
||||
ca-certificates \
|
||||
tzdata \
|
||||
gpg \
|
||||
lftp && \
|
||||
# Add PostgreSQL Apt Repository
|
||||
# Download the key
|
||||
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | \
|
||||
# Dearmor the key and save to the keyring directory
|
||||
gpg --dearmor -o /usr/share/keyrings/postgresql-archive-keyring.gpg && \
|
||||
# Set correct permissions for the keyring file
|
||||
chmod 644 /usr/share/keyrings/postgresql-archive-keyring.gpg && \
|
||||
# Add the repository source, signed by the keyring
|
||||
sh -c 'echo "deb [signed-by=/usr/share/keyrings/postgresql-archive-keyring.gpg] https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' && \
|
||||
# Update again after adding repo
|
||||
apt-get update && \
|
||||
# Install specific client version
|
||||
apt-get install -y --no-install-recommends \
|
||||
postgresql-client-16 && \
|
||||
# Configure timezone
|
||||
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \
|
||||
# Clean up (remove build dependencies)
|
||||
apt-get purge -y --auto-remove wget gnupg lsb-release ca-certificates gpg && \
|
||||
apt-get clean && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install Python dependencies
|
||||
# Using requirements.txt is generally better, but for a simple script:
|
||||
RUN pip install --no-cache-dir schedule pytz
|
||||
|
||||
# Set the working directory in the container
|
||||
WORKDIR /app
|
||||
|
||||
# Copy the Python script into the container
|
||||
COPY db/backup.py .
|
||||
|
||||
# Ensure .ssh directory exists (still good practice, though key might not be used)
|
||||
# RUN mkdir -p /root/.ssh && chmod 700 /root/.ssh # No longer needed for SSH keys
|
||||
|
||||
# Command to run the application
|
||||
CMD ["python", "backup.py"]
|
||||
Reference in New Issue
Block a user