Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 689ac2a54c | |||
| 6602090c45 | |||
| 5e4a181ea9 | |||
| 466f837533 | |||
| ec34b374c7 | |||
| dc23173e2d | |||
| cf02cd0829 |
@@ -1,28 +0,0 @@
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: build-control-container
|
||||
|
||||
steps:
|
||||
- name: build and push
|
||||
image: plugins/docker
|
||||
settings:
|
||||
repo: git.kolspace.cc/victor.kolomin/docker-rustic-backup
|
||||
registry: git.kolspace.cc
|
||||
tags:
|
||||
- ${DRONE_TAG}
|
||||
- latest
|
||||
dockerfile: Dockerfile
|
||||
context: .
|
||||
platforms: linux/amd64
|
||||
username:
|
||||
from_secret: registry_user
|
||||
password:
|
||||
from_secret: registry_pass
|
||||
buildkit: true
|
||||
cache_from:
|
||||
- git.kolspace.cc/victor.kolomin/docker-rustic-backup:latest
|
||||
cache_to:
|
||||
- type=inline
|
||||
trigger:
|
||||
event:
|
||||
- tag
|
||||
@@ -18,4 +18,4 @@ steps:
|
||||
|
||||
when:
|
||||
event:
|
||||
- tag
|
||||
- tag
|
||||
+6
-5
@@ -2,7 +2,7 @@
|
||||
FROM debian:bookworm-slim
|
||||
|
||||
# Define the version of Rustic to install as a build argument
|
||||
ARG RUSTIC_VERSION=v0.10.2
|
||||
ARG RUSTIC_VERSION=v0.11.2
|
||||
|
||||
# Set DEBIAN_FRONTEND to noninteractive to suppress warnings
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
@@ -11,11 +11,11 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
cron bash curl tzdata ca-certificates && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# RUN curl -L https://github.com/rustic-rs/rustic/releases/download/${RUSTIC_VERSION}/rustic-${RUSTIC_VERSION}-x86_64-unknown-linux-musl.tar.gz \
|
||||
RUN curl -L https://github.com/rustic-rs/rustic/releases/download/v0.10.2/rustic-v0.10.2-1-g189b17c-x86_64-unknown-linux-musl.tar.gz \
|
||||
RUN curl -L https://github.com/rustic-rs/rustic/releases/download/${RUSTIC_VERSION}/rustic-${RUSTIC_VERSION}-x86_64-unknown-linux-musl.tar.gz \
|
||||
# RUN curl -L https://github.com/rustic-rs/rustic/releases/download/v0.10.2/rustic-v0.10.2-1-g189b17c-x86_64-unknown-linux-musl.tar.gz \
|
||||
| tar -xvzf - -C /usr/local/bin rustic && \
|
||||
\
|
||||
curl -o /usr/local/bin/mc https://dl.min.io/client/mc/release/linux-amd64/mc && \
|
||||
curl -L -o /usr/local/bin/mc https://dl.min.io/client/mc/release/linux-amd64/mc && \
|
||||
\
|
||||
chmod +x /usr/local/bin/rustic /usr/local/bin/mc
|
||||
|
||||
@@ -28,6 +28,7 @@ COPY backup.sh /usr/local/bin/backup.sh
|
||||
COPY restore.sh /usr/local/bin/restore.sh
|
||||
COPY start.sh /start.sh
|
||||
COPY prune.sh /usr/local/bin/prune.sh
|
||||
RUN chmod +x /usr/local/bin/backup.sh /usr/local/bin/restore.sh /start.sh /usr/local/bin/prune.sh
|
||||
COPY cache-cleanup.sh /usr/local/bin/cache-cleanup.sh
|
||||
RUN chmod +x /usr/local/bin/backup.sh /usr/local/bin/restore.sh /start.sh /usr/local/bin/prune.sh /usr/local/bin/cache-cleanup.sh
|
||||
|
||||
CMD ["/start.sh"]
|
||||
@@ -78,6 +78,13 @@ if [ $STATUS -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
echo "$(date): Backup successfully completed."
|
||||
|
||||
# --- Optional Cache Cleanup ---
|
||||
if [ -n "$CACHE_CLEANUP_DAYS" ] && [ "$CACHE_CLEANUP_DAYS" -gt 0 ]; then
|
||||
echo "$(date): --> Running cache cleanup..."
|
||||
/usr/local/bin/cache-cleanup.sh
|
||||
fi
|
||||
|
||||
echo "$(date): --- ALL BACKUP TASKS COMPLETED SUCCESSFULLY. ---"
|
||||
|
||||
# ----------------------------------------------------
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
#!/bin/bash
|
||||
# cache-cleanup.sh: Clean up old cache files to free disk space.
|
||||
|
||||
set -e
|
||||
|
||||
send_notification() {
|
||||
local status=$1
|
||||
local message=$2
|
||||
|
||||
if [ -n "$N8N_WEBHOOK_URL" ]; then
|
||||
curl -X POST -H "Content-Type: application/json" \
|
||||
-d "{\"hostname\": \"${HOSTNAME}\", \"status\": \"${status}\", \"message\": \"${message}\"}" \
|
||||
"${N8N_WEBHOOK_URL}" --silent --output /dev/null || echo "$(date): WARNING: Failed to send notification to n8n."
|
||||
fi
|
||||
}
|
||||
|
||||
trap 'send_notification "failure" "Cache cleanup script failed at line $LINENO. Check container logs for details."' ERR
|
||||
|
||||
# --- Configuration ---
|
||||
CACHE_DIR="/root/.cache/rustic"
|
||||
CLEANUP_DAYS=${CACHE_CLEANUP_DAYS:-7}
|
||||
|
||||
echo "$(date): --> Starting cache cleanup process..."
|
||||
echo "$(date): Cache directory: ${CACHE_DIR}"
|
||||
echo "$(date): Removing files not accessed for more than ${CLEANUP_DAYS} day(s)..."
|
||||
|
||||
# Check if cache directory exists
|
||||
if [ ! -d "${CACHE_DIR}" ]; then
|
||||
echo "$(date): Cache directory does not exist. Skipping cleanup."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Get initial size
|
||||
INITIAL_SIZE=$(du -sh "${CACHE_DIR}" 2>/dev/null | cut -f1)
|
||||
echo "$(date): Initial cache size: ${INITIAL_SIZE}"
|
||||
|
||||
# Find and delete files not accessed for more than CLEANUP_DAYS
|
||||
# Using -atime (access time) based on the user's successful command
|
||||
DELETED_COUNT=$(find "${CACHE_DIR}" -type f -atime +${CLEANUP_DAYS} -delete -print | wc -l)
|
||||
|
||||
# Get final size
|
||||
FINAL_SIZE=$(du -sh "${CACHE_DIR}" 2>/dev/null | cut -f1 || echo "0K")
|
||||
echo "$(date): Final cache size: ${FINAL_SIZE}"
|
||||
echo "$(date): Deleted ${DELETED_COUNT} old cache file(s)."
|
||||
|
||||
if [ ${DELETED_COUNT} -gt 0 ]; then
|
||||
CLEANUP_MESSAGE="Cache cleanup completed. Removed ${DELETED_COUNT} file(s). Final cache size: ${FINAL_SIZE}"
|
||||
echo "$(date): ${CLEANUP_MESSAGE}"
|
||||
send_notification "success" "${CLEANUP_MESSAGE}"
|
||||
else
|
||||
echo "$(date): No old cache files found to delete."
|
||||
fi
|
||||
@@ -35,6 +35,11 @@ services:
|
||||
# Optional: Max random delay in seconds to wait before starting the backup.
|
||||
- RANDOM_DELAY_SECONDS=3600
|
||||
|
||||
# Optional: Cache cleanup configuration (days to keep cache files).
|
||||
# Files not accessed for longer than this period will be deleted.
|
||||
# Set to 0 or leave empty to disable cache cleanup.
|
||||
- CACHE_CLEANUP_DAYS=7
|
||||
|
||||
# Optional: Webhook URL for n8n to send notifications (for success and failure).
|
||||
- N8N_WEBHOOK_URL="http://your-n8n-instance/webhook/your-id"
|
||||
|
||||
|
||||
@@ -42,5 +42,11 @@ rustic prune
|
||||
echo "$(date): --> Running integrity check (check)..."
|
||||
rustic check ${CHECK_ARGS}
|
||||
|
||||
# --- Optional Cache Cleanup ---
|
||||
if [ -n "$CACHE_CLEANUP_DAYS" ] && [ "$CACHE_CLEANUP_DAYS" -gt 0 ]; then
|
||||
echo "$(date): --> Running cache cleanup..."
|
||||
/usr/local/bin/cache-cleanup.sh
|
||||
fi
|
||||
|
||||
echo "$(date): --- MAINTENANCE COMPLETED SUCCESSFULLY. ---"
|
||||
send_notification "success" "Rustic maintenance (forget/prune/check) completed successfully."
|
||||
Reference in New Issue
Block a user