diff --git a/Dockerfile b/Dockerfile index 0fcf1e2..7770873 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM restic/restic -RUN apk add --no-cache mysql-client rclone bash fuse +RUN apk add --no-cache mysql-client rclone bash fuse postgresql-client RUN mkdir /app && mkdir /config diff --git a/README.md b/README.md index 2906971..7e83a62 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,16 @@ Use [restic](https://restic.net/) together with rclone for a poor mans backup solution. +# Configuration + Environment variables: `RCLONE_REMOTE` remote for rclone e.g. `gdrive:/backup` `RCLONE_CONFIG` file path for the rclone config file e.g. `/config/rclone.conf` -`ENC_PASSWORD` or `ENC_PASSWORD_FILE` password for the repo +`RESTIC_PASSWORD` or `RESTIC_PASSWORD_FILE` password for the repo + +`RCLONE_CONFIG_FILE` content of the rclone config. For the database: @@ -18,4 +22,44 @@ For the database: `MYSQL_PASSWORD` or `MYSQL_PASSWORD_FILE` -Use the `/app/init.sh` script to init a new remote. \ No newline at end of file +`POSTGRES_DUMP_DB` all databases comma sperated: `db1,db2` + +`POSTGRES_HOST` + +`POSTGRES_USERNAME` + +`POSTGRES_PASSWORD` or `POSTGRES_PASSWORD_FILE` + +Use the `/app/init.sh` script to init a new remote. + +# Directorys + +`/config` Contains the rclone config. +`/backup` Contains the mounted volumes as read only +`/restore` Contains volumes to restore + +# Usage + +Here is an example of the script i use to backup my volumes: + +```sh +#!/usr/bin/env sh +set -e + +# get all volumes with the "backup.enable" lable on it +BACKUP_VOL=$(docker volume ls --filter "label=backup.enable" --format '-v {{ .Name }}:/backup/{{ .Name }}:ro ') + +docker run \ + --rm \ + -e "RCLONE_REMOTE=gdrive:/backup" \ + -e "RCLONE_CONFIG=/config/rclone.conf" \ + -e "ENC_PASSWORD=MyPassword" \ + -e "MYSQL_USERNAME=root" \ + -e "MYSQL_PASSWORD=dbPassword" \ + -e "MYSQL_DUMP_DB=db1,db2" \ + -e "MYSQL_HOST=databaseHost" \ + --network "dbNet" \ + -v "/var/docker/backup:/config" \ + $BACKUP_VOL \ + djeeberjr/backup +``` diff --git a/backup.sh b/backup.sh index a791634..dd3e002 100755 --- a/backup.sh +++ b/backup.sh @@ -9,7 +9,13 @@ mkdir -p /backup/sqlDump for db in $(echo "$MYSQL_DUMP_DB" | sed 's/,/\n/g') do echo "Dumping db: $db" - mysqldump --compact -P 3306 --host "$MYSQL_HOST" -u "$MYSQL_USERNAME" "-p$MYSQL_PASSWORD_ACTUAL" "$db" > "/backup/sqlDump/$db.sql" + mysqldump --compact -P 3306 --host "$MYSQL_HOST" -u "$MYSQL_USERNAME" "-p$MYSQL_PASSWORD_ACTUAL" "$db" > "/backup/sqlDump/$db-mysql.sql" +done + +for db in $(echo "$POSTGRES_DUMP_DB" | sed 's/,/\n/g') +do + echo "Dumping db: $db" + pg_dump -U "$POSTGRES_USERNAME" --host "$POSTGRES_HOST" "$db" > "/backup/sqlDump/$db-postgres.sql" done restic --verbose backup "/backup" diff --git a/setup.sh b/setup.sh index 1a9f62f..23ca20b 100755 --- a/setup.sh +++ b/setup.sh @@ -31,7 +31,14 @@ elif [ -n "${MYSQL_PASSWORD_FILE}" ]; then MYSQL_PASSWORD_ACTUAL=$(cat "$MYSQL_PASSWORD_FILE") fi +if [ -n "$POSTGRES_PASSWORD" ];then + PGPASSWORD="$POSTGRES_PASSWORD" +elif [ -n "$POSTGRES_PASSWORD_FILE" ]; then + PGPASSWORD=$(cat "$POSTGRES_PASSWORD_FILE") +fi + export RCLONE_REMOTE export RESTIC_PASSWORD export MYSQL_PASSWORD_ACTUAL export RESTIC_REPOSITORY +export PGPASSWORD