diff --git a/Dockerfile b/Dockerfile index e923b32..93c6564 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,7 @@ RUN apk add --no-cache \ ENV DB_FILE /data/db.sqlite3 ENV BACKUP_FILE /data/db_backup/backup.sqlite3 -ENV BACKUP_FILE_PERMISSIONS 600 +ENV BACKUP_FILE_PERMISSIONS 700 ENV CRON_TIME "0 5 * * *" ENV TIMESTAMP false ENV UID 100 diff --git a/README.md b/README.md index 788aad1..8e99b01 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ docker run --rm --volumes-from=bitwarden -v /tmp/myBackup:/myBackup --entrypoint | ----- | ----- | | DB_FILE | Path to the Bitwarden sqlite3 database *inside* the container | | BACKUP_FILE | Path to the desired backup location *inside* the container | -| BACKUP_FILE_PERMISSIONS | Sets the permissions of the backup file | +| BACKUP_FILE_PERMISSIONS | Sets the permissions of the backup file (**CAUTION** [^1] | | CRON_TIME | Cronjob format "Minute Hour Day_of_month Month_of_year Day_of_week Year" | | TIMESTAMP | Set to `true` to append timestamp to the `BACKUP_FILE` | | UID | User ID to run the cron job with | @@ -53,6 +53,8 @@ docker run --rm --volumes-from=bitwarden -v /tmp/myBackup:/myBackup --entrypoint | CRONFILE | Path to the cron file *inside* the container | | DELETE_AFTER | Delete old backups after X many days | +[^1]: The permissions should at least be 700 since the backup folder itself gets the same permissions and with 600 it would not be accessible. + ## Common erros ### Wrong permissions `Error: unable to open database file` is most likely caused by permission errors. @@ -62,4 +64,4 @@ via the `UID` and `GID` environment variables like described above. ### Wrong timestamp If you need timestamps in your local timezone you should mount `/etc/timezone:/etc/timezone:ro` and `/etc/localtime:/etc/localtime:ro` -like it's done in the [docker-compose.yml](docker-compose.yml). \ No newline at end of file +like it's done in the [docker-compose.yml](docker-compose.yml). diff --git a/entrypoint.sh b/entrypoint.sh index 8a668e3..94ac795 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -5,12 +5,14 @@ BACKUP_CMD="/sbin/su-exec ${UID}:${GID} /app/backup.sh" +echo "Running $(basename "$0") as $(id)" + # Preparation -if [ ! -d $(dirname "$BACKUP_FILE") ] +BACKUP_DIR=$(dirname "$BACKUP_FILE") +if [ ! -d "$BACKUP_DIR" ] then - mkdir -p $(dirname "$BACKUP_FILE") - chown -R $UID:$GID $(dirname "$BACKUP_FILE") - chmod -R "$BACKUP_FILE_PERMISSIONS" $(dirname "$BACKUP_FILE") + echo "$BACKUP_DIR not exists. Creating it with owner $UID:$GID and permissions $BACKUP_FILE_PERMISSIONS." + install -o $UID -g $GID -m $BACKUP_FILE_PERMISSIONS -d $BACKUP_DIR fi # For compatibility reasons @@ -25,9 +27,9 @@ if [ "$1" = "manual" ]; then fi # Initialize cron -echo "Running as $(id)" if [ "$(id -u)" -eq 0 ] && [ "$(grep -c "$BACKUP_CMD" "$CRONFILE")" -eq 0 ]; then echo "Initalizing..." + echo "Writing backup command \"$BACKUP_CMD\" to cron." echo "$CRON_TIME $BACKUP_CMD >> $LOGFILE 2>&1" | crontab - fi @@ -40,6 +42,7 @@ fi # Restart script as user "app:app" if [ "$(id -u)" -eq 0 ]; then + echo "Restarting $(basename "$0") as app:app" exec su-exec app:app "$0" "$@" fi