This commit is contained in:
1 parent
e83d8008bb
commit
0f45a43f56
4 files changed
+69
-27
No files matched your search
@@ -25,6 +25,10 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
cron bash curl tzdata ca-certificates && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install MinIO Client (mc) for S3 bucket management
|
||||
RUN curl -o /usr/local/bin/mc https://dl.min.io/client/mc/release/linux-amd64/mc && \
|
||||
chmod +x /usr/local/bin/mc
|
||||
|
||||
COPY --from=builder /usr/local/cargo/bin/rustic /usr/local/bin/rustic
|
||||
|
||||
COPY backup.sh /usr/local/bin/backup.sh
|
||||
|
||||
@@ -57,6 +57,6 @@ rustic prune --forget ${PRUNE_POLICY}
|
||||
# Note: Check is kept for completeness, but can be disabled or scheduled separately
|
||||
# to reduce daily resource usage.
|
||||
echo "$(date): --> Running integrity check (check)..."
|
||||
rustic check
|
||||
rustic check ${CHECK_ARGS}
|
||||
|
||||
echo "$(date): --- ALL BACKUP TASKS COMPLETED SUCCESSFULLY. ---"
|
||||
+15
-15
@@ -10,34 +10,33 @@ services:
|
||||
restart: "unless-stopped"
|
||||
|
||||
environment:
|
||||
# --- 1. CRON SCHEDULING (Daemon Manager) ---
|
||||
# --- 1. CRON SCHEDULING ---
|
||||
# Defines WHEN the entire backup script (backup, prune, check) will run.
|
||||
# Example: "0 0,12 * * *" runs at 00:00 and 12:00 daily (every 12 hours)
|
||||
# Example: "0 0,12 * * *" runs at 00:00 and 12:00 daily
|
||||
- CRON_SCHEDULE="0 0,12 * * *"
|
||||
|
||||
# --- 2. RUSTIC CORE SETTINGS ---
|
||||
# Repository URL (uses your existing Restic/S3-compatible setup)
|
||||
- RUSTIC_REPOSITORY="s3:http://192.168.110.135:9000/{{ inventory_hostname }}"
|
||||
|
||||
# CRITICAL: Repository Encryption Password (REQUIRED for init/backup/check)
|
||||
# CRITICAL: Repository Encryption Password
|
||||
- RUSTIC_PASSWORD="YOUR_SUPER_SECRET_REPOSITORY_PASSWORD_HERE"
|
||||
|
||||
# --- 3. EXECUTOR SETTINGS (Used by backup.sh) ---
|
||||
# --- 3. S3 REPOSITORY CONFIGURATION ---
|
||||
# These variables are used to generate /etc/rustic/rustic.toml and to create the bucket.
|
||||
- S3_ENDPOINT="http://192.168.110.135:9000"
|
||||
- S3_BUCKET="mybucket" # Example: use hostname as bucket name
|
||||
- S3_REGION="us-east-1" # Can be any string for MinIO, but required by the S3 spec
|
||||
- AWS_ACCESS_KEY_ID="YOUR_ACCESS_KEY"
|
||||
- AWS_SECRET_ACCESS_KEY="YOUR_SECRET_KEY"
|
||||
|
||||
# --- 4. EXECUTOR SETTINGS (Used by backup.sh) ---
|
||||
# Paths to backup (space-separated list). Must match the volume mount source.
|
||||
# This corresponds to your original /mnt/volumes mount.
|
||||
- BACKUP_PATHS="/data/volumes/"
|
||||
|
||||
# Pruning policy arguments (corresponds to RESTIC_FORGET_ARGS)
|
||||
# Pruning policy arguments
|
||||
- PRUNE_POLICY="--keep-daily 7 --keep-weekly 5 --keep-monthly 12"
|
||||
|
||||
# Check arguments (corresponds to RESTIC_CHECK_ARGS)
|
||||
# Check arguments
|
||||
- CHECK_ARGS="--read-data-subset 10%"
|
||||
|
||||
# --- 4. CLOUD CREDENTIALS (S3/MinIO Example) ---
|
||||
# If your S3/MinIO credentials are NOT in the .env file, uncomment and set them here:
|
||||
# - AWS_ACCESS_KEY_ID=...
|
||||
# - AWS_SECRET_ACCESS_KEY=...
|
||||
|
||||
# --- 5. MOUNTED DATA ---
|
||||
volumes:
|
||||
# Mount the Docker data path from the host (read-only for safety)
|
||||
@@ -48,6 +47,7 @@ services:
|
||||
- rustic_cache:/root/.cache/rustic
|
||||
|
||||
# Include the .env file if it contains S3 secrets or other shared variables
|
||||
# Note: Variables in this file will be overridden by the 'environment' section above.
|
||||
env_file:
|
||||
- .env
|
||||
|
||||
|
||||
@@ -4,27 +4,65 @@
|
||||
# Exit immediately if any command fails
|
||||
set -e
|
||||
|
||||
# --- 1. Validate Schedule Variable ---
|
||||
# Ensure the required CRON_SCHEDULE variable is set by the user
|
||||
# --- 1. Validate Core Variables ---
|
||||
if [ -z "$CRON_SCHEDULE" ]; then
|
||||
echo "ERROR: CRON_SCHEDULE environment variable is not set."
|
||||
echo "Please set it (e.g., '0 3 * * *' for 3 AM daily)."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# --- 2. Create Dynamic Crontab ---
|
||||
# Create the crontab file based on the user-defined schedule.
|
||||
# The job calls the backup executor script. Logs are redirected to cron.log.
|
||||
if [ -z "$RUSTIC_PASSWORD" ]; then
|
||||
echo "ERROR: RUSTIC_PASSWORD environment variable is not set."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# --- 2. S3 Configuration & Bucket Check ---
|
||||
# Check for S3 variables. If they exist, configure rustic and check the bucket.
|
||||
if [ -n "$S3_ENDPOINT" ] && [ -n "$S3_BUCKET" ] && [ -n "$AWS_ACCESS_KEY_ID" ] && [ -n "$AWS_SECRET_ACCESS_KEY" ]; then
|
||||
echo "S3 environment variables detected. Configuring rustic and checking bucket..."
|
||||
|
||||
# Set a default region if not provided
|
||||
S3_REGION=${S3_REGION:-"us-east-1"}
|
||||
|
||||
# --- Create rustic config file ---
|
||||
mkdir -p /etc/rustic
|
||||
cat <<EOF > /etc/rustic/rustic.toml
|
||||
[repository]
|
||||
repository = "opendal:s3"
|
||||
password = "${RUSTIC_PASSWORD}"
|
||||
|
||||
[repository.options]
|
||||
endpoint = "${S3_ENDPOINT}"
|
||||
bucket = "${S3_BUCKET}"
|
||||
region = "${S3_REGION}"
|
||||
access_key_id = "${AWS_ACCESS_KEY_ID}"
|
||||
secret_access_key = "${AWS_SECRET_ACCESS_KEY}"
|
||||
EOF
|
||||
echo "Rustic config created at /etc/rustic/rustic.toml"
|
||||
|
||||
# --- Check and Create S3 Bucket ---
|
||||
echo "Configuring MinIO client for endpoint: ${S3_ENDPOINT}"
|
||||
mc alias set s3_storage "${S3_ENDPOINT}" "${AWS_ACCESS_KEY_ID}" "${AWS_SECRET_ACCESS_KEY}" --api S3v4
|
||||
|
||||
if mc ls "s3_storage/${S3_BUCKET}" > /dev/null 2>&1; then
|
||||
echo "Bucket '${S3_BUCKET}' already exists."
|
||||
else
|
||||
echo "Bucket '${S3_BUCKET}' not found. Creating it..."
|
||||
mc mb "s3_storage/${S3_BUCKET}"
|
||||
echo "Bucket '${S3_BUCKET}' created successfully."
|
||||
fi
|
||||
else
|
||||
echo "WARNING: S3 environment variables (S3_ENDPOINT, S3_BUCKET, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY) are not fully set."
|
||||
echo "Skipping S3 configuration and bucket creation. Rustic might fail if not configured otherwise."
|
||||
fi
|
||||
|
||||
|
||||
# --- 3. Create Dynamic Crontab ---
|
||||
CRONTAB_FILE="/var/spool/cron/crontabs/root"
|
||||
echo "Creating crontab entry: ${CRON_SCHEDULE} /usr/local/bin/backup.sh"
|
||||
|
||||
# Note: The absolute path to the script is required by cron.
|
||||
echo "${CRON_SCHEDULE} /usr/local/bin/backup.sh" > ${CRONTAB_FILE}
|
||||
|
||||
# Ensure the crontab file has the correct permissions (not strictly needed for root, but good practice)
|
||||
chmod 600 ${CRONTAB_FILE}
|
||||
|
||||
# --- 3. Start Daemon ---
|
||||
# --- 4. Start Daemon ---
|
||||
echo "Starting cron daemon in foreground..."
|
||||
exec /usr/sbin/cron -f -L 8
|
||||
echo "Cron daemon is running. Container is now in daemon mode."
|
||||
Reference in new issue
Block a user