Initial commit
This commit is contained in:
commit
40c5f5bc26
2
README.md
Normal file
2
README.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
# backup-containers
|
||||
Dockerfile used to perform automatic backups on volumes
|
1
backup/Crontab
Normal file
1
backup/Crontab
Normal file
|
@ -0,0 +1 @@
|
|||
0 0 * * * * /backup.sh
|
10
backup/Dockerfile
Normal file
10
backup/Dockerfile
Normal 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
11
backup/backup.sh
Normal 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
33
backup/init.sh
Normal 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
|
Loading…
Reference in a new issue