1
0
Fork 0

regular backup with restic

This commit is contained in:
Tobias Brunner 2018-08-05 12:27:38 +00:00
parent 46c0276086
commit 6ddfa344c8
6 changed files with 77 additions and 1 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
backup.env

View File

@ -17,3 +17,24 @@ compatible, the image needs to be rebuilt on arm.
Corresponding issue on GitHub: [Support for ARM64v8 #195](https://github.com/odoo/docker/issues/195).
## Backup configuration
Example contents of `backup.env`:
```
RESTIC_REPOSITORY=rclone:myremote:posbackup
RESTIC_PASSWORD=extremelysecurepassword
RCLONE_CONFIG_FWUCLOUD_TYPE=webdav
RCLONE_CONFIG_FWUCLOUD_URL=https://nextcloud.example.com/remote.php/webdav/
RCLONE_CONFIG_FWUCLOUD_VENDOR=nextcloud
RCLONE_CONFIG_FWUCLOUD_USER=backupuser
RCLONE_CONFIG_FWUCLOUD_PASS=encryptedpassword
PGDATABASE=odoodbname
```
Restore of DB:
```
createdb -T template0 restoretest
pg_restore -d restoretest /data/odoo_data.dump
```

View File

@ -12,4 +12,14 @@ RUN set -x; wget -O /tmp/rclone.zip https://downloads.rclone.org/v${RCLONE_VERSI
unzip /tmp/rclone.zip && \
mv rclone-v${RCLONE_VERSION}-linux-arm/rclone /usr/local/bin/rclone && \
chmod +x /usr/local/bin/rclone && \
rm -rf rclone-* /tmp/rclone.zip
rm -rf rclone-* /tmp/rclone.zip && \
mkdir -p /root/.config/rclone && \
touch /root/.config/rclone/rclone.conf
RUN apk add --no-cache bash ca-certificates postgresql && \
mkfifo -m 0666 /var/log/cron.log && \
ln -s /var/log/cron.log /var/log/crond.log
ADD crondwrapper.sh resticbackup.sh /usr/local/bin/
ENTRYPOINT ["crondwrapper.sh"]

16
backup/crondwrapper.sh Executable file
View File

@ -0,0 +1,16 @@
#!/usr/bin/env bash
echo "${BACKUP_SCHEDULE} resticbackup.sh >> /var/log/cron.log 2>&1" > /etc/crontabs/root
# start cron
default_crontabs_dir=/etc/crontabs
crond -L /var/log/cron.log -c ${CRONTABS_DIR:-$default_crontabs_dir}
# trap SIGINT and SIGTERM signals and gracefully exit
trap "echo \"stopping cron\"; kill \$!; exit" SIGINT SIGTERM
# start "daemon"
while true
do
cat /var/log/cron.log & wait $!
done

14
backup/resticbackup.sh Executable file
View File

@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -x
echo "[$(date)] Starting backup"
# Dump Postgres DB - parameters are read from env vars
pg_dump -Fc > /data/odoo_data.dump
# Backup data with restic
restic backup --hostname posbox /data
restic forget --prune --keep-last 10
echo "[$(date)] Backup ended"

View File

@ -33,6 +33,20 @@ services:
networks:
localnet:
ipv4_address: 10.5.0.4
backup:
build: ./backup
environment:
- PGHOST=db
- PGUSER=odoo
- PGPASSWORD=odoo
- BACKUP_SCHEDULE=0 19 * * *
env_file: backup.env
volumes:
- odoo-db-data:/data/pg_raw:ro
- /home/pi:/data/home-pi:ro
networks:
localnet:
ipv4_address: 10.5.0.5
volumes:
odoo-web-data:
odoo-db-data: