1
0
mirror of https://github.com/xzeldon/vwdump.git synced 2025-06-28 06:58:15 +03:00

Added more logging and use install instead of mkdir

fixes #12
This commit is contained in:
10 2020-10-18 19:17:27 +02:00
parent 3f0bd862f7
commit 51889d3be3
3 changed files with 13 additions and 8 deletions

View File

@ -9,7 +9,7 @@ RUN apk add --no-cache \
ENV DB_FILE /data/db.sqlite3 ENV DB_FILE /data/db.sqlite3
ENV BACKUP_FILE /data/db_backup/backup.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 CRON_TIME "0 5 * * *"
ENV TIMESTAMP false ENV TIMESTAMP false
ENV UID 100 ENV UID 100

View File

@ -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 | | DB_FILE | Path to the Bitwarden sqlite3 database *inside* the container |
| BACKUP_FILE | Path to the desired backup location *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" | | 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` | | TIMESTAMP | Set to `true` to append timestamp to the `BACKUP_FILE` |
| UID | User ID to run the cron job with | | 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 | | CRONFILE | Path to the cron file *inside* the container |
| DELETE_AFTER | Delete old backups after X many days | | 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 ## Common erros
### Wrong permissions ### Wrong permissions
`Error: unable to open database file` is most likely caused by permission errors. `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 ### Wrong timestamp
If you need timestamps in your local timezone you should mount `/etc/timezone:/etc/timezone:ro` and `/etc/localtime:/etc/localtime:ro` 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). like it's done in the [docker-compose.yml](docker-compose.yml).

View File

@ -5,12 +5,14 @@
BACKUP_CMD="/sbin/su-exec ${UID}:${GID} /app/backup.sh" BACKUP_CMD="/sbin/su-exec ${UID}:${GID} /app/backup.sh"
echo "Running $(basename "$0") as $(id)"
# Preparation # Preparation
if [ ! -d $(dirname "$BACKUP_FILE") ] BACKUP_DIR=$(dirname "$BACKUP_FILE")
if [ ! -d "$BACKUP_DIR" ]
then then
mkdir -p $(dirname "$BACKUP_FILE") echo "$BACKUP_DIR not exists. Creating it with owner $UID:$GID and permissions $BACKUP_FILE_PERMISSIONS."
chown -R $UID:$GID $(dirname "$BACKUP_FILE") install -o $UID -g $GID -m $BACKUP_FILE_PERMISSIONS -d $BACKUP_DIR
chmod -R "$BACKUP_FILE_PERMISSIONS" $(dirname "$BACKUP_FILE")
fi fi
# For compatibility reasons # For compatibility reasons
@ -25,9 +27,9 @@ if [ "$1" = "manual" ]; then
fi fi
# Initialize cron # Initialize cron
echo "Running as $(id)"
if [ "$(id -u)" -eq 0 ] && [ "$(grep -c "$BACKUP_CMD" "$CRONFILE")" -eq 0 ]; then if [ "$(id -u)" -eq 0 ] && [ "$(grep -c "$BACKUP_CMD" "$CRONFILE")" -eq 0 ]; then
echo "Initalizing..." echo "Initalizing..."
echo "Writing backup command \"$BACKUP_CMD\" to cron."
echo "$CRON_TIME $BACKUP_CMD >> $LOGFILE 2>&1" | crontab - echo "$CRON_TIME $BACKUP_CMD >> $LOGFILE 2>&1" | crontab -
fi fi
@ -40,6 +42,7 @@ fi
# Restart script as user "app:app" # Restart script as user "app:app"
if [ "$(id -u)" -eq 0 ]; then if [ "$(id -u)" -eq 0 ]; then
echo "Restarting $(basename "$0") as app:app"
exec su-exec app:app "$0" "$@" exec su-exec app:app "$0" "$@"
fi fi