From 40c5f5bc263bfbaf23396d257873f62c2c718d2f Mon Sep 17 00:00:00 2001 From: split Date: Tue, 2 Jul 2024 22:13:03 -0700 Subject: [PATCH] Initial commit --- README.md | 2 ++ backup/Crontab | 1 + backup/Dockerfile | 10 ++++++++++ backup/backup.sh | 11 +++++++++++ backup/init.sh | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 57 insertions(+) create mode 100644 README.md create mode 100644 backup/Crontab create mode 100644 backup/Dockerfile create mode 100644 backup/backup.sh create mode 100644 backup/init.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..6cdaa3e --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# backup-containers +Dockerfile used to perform automatic backups on volumes \ No newline at end of file diff --git a/backup/Crontab b/backup/Crontab new file mode 100644 index 0000000..f87e630 --- /dev/null +++ b/backup/Crontab @@ -0,0 +1 @@ +0 0 * * * * /backup.sh \ No newline at end of file diff --git a/backup/Dockerfile b/backup/Dockerfile new file mode 100644 index 0000000..3e37041 --- /dev/null +++ b/backup/Dockerfile @@ -0,0 +1,10 @@ +# god i suck at docker +FROM debian AS base +RUN apt update && apt install tar cron openssh-client rsync -y +COPY Crontab /etc/cron.d/autorun +COPY backup.sh /backup.sh +COPY init.sh /init.sh +RUN chmod +x /backup.sh /init.sh +RUN mkdir -p /tmp /volumes + +CMD [ "/bin/bash", "/init.sh" ] \ No newline at end of file diff --git a/backup/backup.sh b/backup/backup.sh new file mode 100644 index 0000000..8fc0f6c --- /dev/null +++ b/backup/backup.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +source /.env + +FILENAME="$NAME $(date +%Y-%m-%d\ %H-%M).tgz" + +# tar volumes +tar -aczf /tmp/$FILENAME -C /volumes . + +# ship to host +rsync -R -e "ssh -i /id" /tmp/$FILENAME $NAME@$HOST:/home/$NAME/$(date +%Y\/%m)/ \ No newline at end of file diff --git a/backup/init.sh b/backup/init.sh new file mode 100644 index 0000000..630bdc7 --- /dev/null +++ b/backup/init.sh @@ -0,0 +1,33 @@ +startup_check() { + + if [[ -z "$(ls /volumes)" ]]; then + echo "Nothing in /volumes" + exit 1 + fi + + if [[ ! -e "/.env" ]]; then + echo Missing .env file + exit 1 + else + source /.env + if [[ -z "$NAME" ]]; then + echo Missing NAME in .env + exit 1 + fi + if [[ -z "$HOST" ]]; then + echo Missing HOST in .env + exit 1 + fi + fi + + if [[ ! -e "/id" ]]; then + echo Missing ssh identity file + exit 1 + fi + + echo Startup check passed +} + +startup_check +/usr/sbin/cron & +sleep infinity \ No newline at end of file