initial commit
This commit is contained in:
17
backupd/Dockerfile
Normal file
17
backupd/Dockerfile
Normal file
@@ -0,0 +1,17 @@
|
||||
FROM debian:bookworm-slim
|
||||
|
||||
RUN apt-get update \
|
||||
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
|
||||
xorriso tar zstd sqlite3 ca-certificates curl \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN curl -fsSL https://github.com/aptible/supercronic/releases/download/v0.2.29/supercronic-linux-amd64 \
|
||||
-o /usr/local/bin/supercronic \
|
||||
&& chmod +x /usr/local/bin/supercronic
|
||||
|
||||
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
|
||||
COPY backup.sh /usr/local/bin/backup.sh
|
||||
|
||||
RUN chmod +x /usr/local/bin/entrypoint.sh /usr/local/bin/backup.sh
|
||||
|
||||
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
|
||||
53
backupd/backup.sh
Normal file
53
backupd/backup.sh
Normal file
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
timestamp=$(date -u +"%Y%m%dT%H%M%SZ")
|
||||
workdir="/tmp/backup-${timestamp}"
|
||||
stagedir="${workdir}/backup-${timestamp}"
|
||||
data_tar="${stagedir}/data.tar.zst"
|
||||
db_path="${SQLITE_DB_PATH:-/var/lib/webui/app.db}"
|
||||
remote_path="${BACKUP_REMOTE_PATH:-/remote}"
|
||||
compression="${BACKUP_COMPRESSION:-zstd}"
|
||||
|
||||
mkdir -p "${stagedir}"
|
||||
|
||||
tar --xattrs --acls --numeric-owner -cpf - /data | zstd -19 -o "${data_tar}"
|
||||
|
||||
sqlite3 "${db_path}" ".backup '${stagedir}/app.db'"
|
||||
|
||||
data_size=$(stat -c %s "${stagedir}/data.tar.zst")
|
||||
data_sha=$(sha256sum "${stagedir}/data.tar.zst" | awk '{print $1}')
|
||||
db_size=$(stat -c %s "${stagedir}/app.db")
|
||||
db_sha=$(sha256sum "${stagedir}/app.db" | awk '{print $1}')
|
||||
|
||||
cat > "${stagedir}/manifest.json" <<EOF
|
||||
{
|
||||
"timestamp": "${timestamp}",
|
||||
"data_tar": "data.tar.zst",
|
||||
"database": "app.db",
|
||||
"sizes": {
|
||||
"data_tar": ${data_size},
|
||||
"database": ${db_size}
|
||||
},
|
||||
"sha256": {
|
||||
"data_tar": "${data_sha}",
|
||||
"database": "${db_sha}"
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
cd "${workdir}"
|
||||
xorriso -as mkisofs -o "${workdir}/backup-${timestamp}.iso" "backup-${timestamp}"
|
||||
|
||||
if [ "${compression}" = "gzip" ]; then
|
||||
gzip -9 "${workdir}/backup-${timestamp}.iso"
|
||||
archive="${workdir}/backup-${timestamp}.iso.gz"
|
||||
else
|
||||
zstd -19 "${workdir}/backup-${timestamp}.iso"
|
||||
archive="${workdir}/backup-${timestamp}.iso.zst"
|
||||
fi
|
||||
|
||||
mkdir -p "${remote_path}"
|
||||
mv "${archive}" "${remote_path}/"
|
||||
|
||||
rm -rf "${workdir}"
|
||||
10
backupd/entrypoint.sh
Normal file
10
backupd/entrypoint.sh
Normal file
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
CRON_EXPR="${BACKUP_CRON:-0 2 * * *}"
|
||||
|
||||
cat > /etc/backup-cron <<EOF
|
||||
${CRON_EXPR} /usr/local/bin/backup.sh
|
||||
EOF
|
||||
|
||||
exec /usr/local/bin/supercronic /etc/backup-cron
|
||||
Reference in New Issue
Block a user