Initial commit

This commit is contained in:
split / May 2024-07-02 22:13:03 -07:00
commit 40c5f5bc26
Signed by: split
GPG key ID: C325C61F0BF517C0
5 changed files with 57 additions and 0 deletions

2
README.md Normal file
View file

@ -0,0 +1,2 @@
# backup-containers
Dockerfile used to perform automatic backups on volumes

1
backup/Crontab Normal file
View file

@ -0,0 +1 @@
0 0 * * * * /backup.sh

10
backup/Dockerfile Normal file
View file

@ -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" ]

11
backup/backup.sh Normal file
View file

@ -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)/

33
backup/init.sh Normal file
View file

@ -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