Files
magnusandClaude Opus 4.6 ffdd8bb4b2 Fix backup permission denied by using docker cp instead of direct mount write
The git user inside the gitea container couldn't write to the NAS-mounted
/tmp/backup directory. Now dumps to /tmp first, then uses docker cp to
extract the file to the sidecar's backup directory.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-28 08:22:09 +01:00

61 lines
1.8 KiB
Bash
Executable File

#!/bin/sh
set -e
BACKUP_DIR="/backup"
RETAIN_DAYS="${BACKUP_RETAIN_DAYS:-7}"
TIMESTAMP="$(date +%Y-%m-%d_%H%M)"
BACKUP_FILE="gitea-dump-${TIMESTAMP}.zip"
echo "========================================"
echo "Gitea backup started at $(date)"
echo "========================================"
# Pre-flight check
if ! docker inspect gitea >/dev/null 2>&1; then
echo "ERROR: gitea container not found or not running."
exit 1
fi
# Run gitea dump to /tmp (writable by git user)
echo "Running gitea dump..."
docker exec -u git -w /tmp gitea \
/app/gitea/gitea dump \
-c /data/gitea/conf/app.ini \
--file "/tmp/${BACKUP_FILE}" \
--skip-log \
--type zip
# Copy dump out of gitea container into sidecar's backup dir
docker cp "gitea:/tmp/${BACKUP_FILE}" "${BACKUP_DIR}/${BACKUP_FILE}"
# Clean up temp file inside gitea container
docker exec gitea rm -f "/tmp/${BACKUP_FILE}"
# Verify backup was created
if [ ! -f "${BACKUP_DIR}/${BACKUP_FILE}" ]; then
echo "ERROR: Backup file not found at ${BACKUP_DIR}/${BACKUP_FILE}"
exit 1
fi
FILESIZE=$(stat -c%s "${BACKUP_DIR}/${BACKUP_FILE}" 2>/dev/null || stat -f%z "${BACKUP_DIR}/${BACKUP_FILE}" 2>/dev/null)
echo "Backup created: ${BACKUP_FILE} (${FILESIZE} bytes)"
# Retention: delete backups older than N days
echo "Cleaning up backups older than ${RETAIN_DAYS} days..."
DELETED=$(find "${BACKUP_DIR}" -name "gitea-dump-*.zip" -mtime "+${RETAIN_DAYS}" -print -delete)
if [ -n "${DELETED}" ]; then
echo "Deleted old backups:"
echo "${DELETED}"
else
echo "No old backups to delete."
fi
echo ""
echo "Current backups:"
ls -lh "${BACKUP_DIR}"/gitea-dump-*.zip 2>/dev/null || echo "(none)"
echo ""
echo "========================================"
echo "Gitea backup completed at $(date)"
echo "========================================"