Browse Source

initial commit

main
Will Webberley 7 months ago
commit
b55ab2be42
  1. 24
      Dockerfile
  2. 14
      backup.sh
  3. 7
      entry.sh

24
Dockerfile

@ -0,0 +1,24 @@
FROM ubuntu:18.04
# See: https://unix.stackexchange.com/questions/433942/how-to-specify-extra-tz-info-for-apt-get-install-y-awscli
RUN export TZ=Europe/London
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
# Prepare apt repos
RUN apt-get update
RUN apt-get install -y cron awscli
# Create needed dirs and add files
RUN mkdir /backup
COPY backup.sh /usr/local/bin/backup
COPY entry.sh /entry.sh
# Prepare cron job
RUN echo '0 3 * * * /usr/local/bin/backup >> /var/log/backup.log 2>&1\n' > /etc/cron.d/backup-cron
RUN chmod 0644 /etc/cron.d/backup-cron
RUN crontab /etc/cron.d/backup-cron
RUN touch /var/log/backup.log
# Entry file tails cron job log to ensure container keeps running
CMD ["/entry.sh"]

14
backup.sh

@ -0,0 +1,14 @@
#!/bin/bash
set -e
filename="backup.tar.gz"
cd /backup
echo "Creating archive..."
echo $BACKUP_DIRS | tr " " "\n" > files.txt
rm $filename 2>&1 || true
tar --warning=no-file-changed -czf $filename -T files.txt 2>&1 || true
echo "Uploading to Backblaze..."
aws s3 cp $filename "s3://$BUCKET/$filename" --endpoint-url "$ENDPOINT"

7
entry.sh

@ -0,0 +1,7 @@
#!/bin/sh
# Ensure cron jobs get access to environment variables set on the container
printenv | grep -v "no_proxy" >> /etc/environment
# start cron
cron && tail -f /var/log/backup.log
Loading…
Cancel
Save