From a2a19a86aaa507f919c01429da03d7a723d67544 Mon Sep 17 00:00:00 2001 From: Alexis Lefebvre Date: Thu, 12 Nov 2020 18:15:43 +0100 Subject: [PATCH 1/6] =?UTF-8?q?Fix=20typo:=20arugment=20=E2=86=92=20argume?= =?UTF-8?q?nt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 94ac795..c2a9363 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -17,7 +17,7 @@ fi # For compatibility reasons if [ "$1" = "/backup.sh" ]; then - >&2 echo "Using /backup.sh is deprecated and will be removed in future versions! Please use \`manual\` as arugment instead" + >&2 echo "Using /backup.sh is deprecated and will be removed in future versions! Please use \`manual\` as argument instead" $BACKUP_CMD fi From adac5d7d59216cd401de3227cf4bc5b0b372afc2 Mon Sep 17 00:00:00 2001 From: 1O <2408212-1O@users.noreply.gitlab.com> Date: Sun, 22 Nov 2020 11:42:11 +0100 Subject: [PATCH 2/6] Added auto-lock to github mirror --- .github/workflows/lockdown.yml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/lockdown.yml diff --git a/.github/workflows/lockdown.yml b/.github/workflows/lockdown.yml new file mode 100644 index 0000000..f11d812 --- /dev/null +++ b/.github/workflows/lockdown.yml @@ -0,0 +1,34 @@ +name: 'Lock down repository' + +on: + issues: + types: opened + pull_request: + types: opened + +jobs: + lockdown: + runs-on: ubuntu-latest + steps: + - uses: dessant/repo-lockdown@v2 + with: + github-token: ${{ github.token }} + issue-labels: 'off-topic' + issue-comment: > + Thanks for your contribution! + + However, this repository does not accept bug reports, + since this is only a mirror of + https://gitlab.com/1O/bitwarden_rs-backup. + + Please feel free to open the issue there. + skip-closed-issue-comment: true + pr-comment: > + Thanks for your contribution! + + However, this repository does not accept pull requests, + since this is only a mirror of + https://gitlab.com/1O/bitwarden_rs-backup. + + Please feel free to open the pull request there. + skip-closed-pr-comment: true \ No newline at end of file From a86966bbe9b8c33774b7d5e7fc55a3ec93359f52 Mon Sep 17 00:00:00 2001 From: pierre perso Date: Wed, 24 Mar 2021 14:20:08 +0000 Subject: [PATCH 3/6] Update Dockerfile, entrypoint.sh, backup.sh files --- Dockerfile | 2 ++ backup.sh | 6 ++++++ entrypoint.sh | 7 +++++++ 3 files changed, 15 insertions(+) diff --git a/Dockerfile b/Dockerfile index dfc498a..57db04c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,6 +11,8 @@ RUN apk add --no-cache \ ENV DB_FILE /data/db.sqlite3 ENV BACKUP_FILE /data/db_backup/backup.sqlite3 +ENV ATTACHMENT_BACKUP_FILE=/data/attachments_backup/attachments +ENV ATTACHMENT_DIR=/data/attachments ENV BACKUP_FILE_PERMISSIONS 700 ENV CRON_TIME "0 5 * * *" ENV TIMESTAMP false diff --git a/backup.sh b/backup.sh index a76607d..cd65391 100644 --- a/backup.sh +++ b/backup.sh @@ -10,10 +10,13 @@ fi if [ $TIMESTAMP = true ] then FINAL_BACKUP_FILE="$(echo "$BACKUP_FILE")_$(date "+%F-%H%M%S")" + FINAL_BACKUP_ATTACHMENT="$(echo "$ATTACHMENT_BACKUP_FILE")_$(date "+%F-%H%M%S")" else FINAL_BACKUP_FILE=$BACKUP_FILE + FINAL_BACKUP_ATTACHMENT=$ATTACHMENT_BACKUP_FILE fi + /usr/bin/sqlite3 $DB_FILE ".backup $FINAL_BACKUP_FILE" if [ $? -eq 0 ] then @@ -22,7 +25,10 @@ else echo "$(date "+%F %T") - Backup unsuccessfull" fi +/bin/tar -cvzf ${FINAL_BACKUP_ATTACHMENT}.tgz ${ATTACHMENT_DIR} + if [ ! -z $DELETE_AFTER ] && [ $DELETE_AFTER -gt 0 ] then find $(dirname "$BACKUP_FILE") -name "$(basename "$BACKUP_FILE")*" -type f -mtime +$DELETE_AFTER -exec rm -f {} \; -exec echo "Deleted {} after $DELETE_AFTER days" \; + find $(dirname "$ATTACHMENT_BACKUP_FILE") -name "$(basename "$ATTACHMENT_BACKUP_FILE")*" -type f -mtime +$DELETE_AFTER -exec rm -f {} \; -exec echo "Deleted {} after $DELETE_AFTER days" \; fi diff --git a/entrypoint.sh b/entrypoint.sh index 452a908..4fe0238 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -15,6 +15,13 @@ then install -o $UID -g $GID -m $BACKUP_FILE_PERMISSIONS -d $BACKUP_DIR fi +ATTACHMENT_BACKUP_DIR=$(dirname "$ATTACHMENT_BACKUP_FILE") +if [ ! -d "$ATTACHMENT_BACKUP_DIR" ] +then + echo "$ATTACHMENT_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 $ATTACHMENT_BACKUP_DIR +fi + # For compatibility reasons if [ "$1" = "/backup.sh" ]; then >&2 echo "Using /backup.sh is deprecated and will be removed in future versions! Please use \`manual\` as argument instead" From 2ddc097df557727921d88a3da4a152b5b2b11caa Mon Sep 17 00:00:00 2001 From: pierre perso Date: Sun, 4 Apr 2021 08:05:17 +0000 Subject: [PATCH 4/6] Check ATTACHMENT_BACKUP_FILE define :microscope: --- Dockerfile | 2 +- README.md | 30 ++++++++++++++++-------------- backup.sh | 26 ++++++++++++++++++++++---- 3 files changed, 39 insertions(+), 19 deletions(-) diff --git a/Dockerfile b/Dockerfile index 57db04c..7bce58c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,7 @@ RUN apk add --no-cache \ ENV DB_FILE /data/db.sqlite3 ENV BACKUP_FILE /data/db_backup/backup.sqlite3 -ENV ATTACHMENT_BACKUP_FILE=/data/attachments_backup/attachments +#ENV ATTACHMENT_BACKUP_FILE=/data/attachments_backup/attachments ENV ATTACHMENT_DIR=/data/attachments ENV BACKUP_FILE_PERMISSIONS 700 ENV CRON_TIME "0 5 * * *" diff --git a/README.md b/README.md index 4ba8763..58c95c6 100644 --- a/README.md +++ b/README.md @@ -46,19 +46,21 @@ docker run --rm --volumes-from=bitwarden -e UID=0 -e BACKUP_FILE=/myBackup/backu ``` ## Environment variables -| ENV | Description | -| ----------------------- | ------------------------------------------------------------------------ | -| 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 (**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 | -| GID | Group ID to run the cron job with | -| LOGFILE | Path to the logfile *inside* the container | -| CRONFILE | Path to the cron file *inside* the container | -| DELETE_AFTER | Delete old backups after X many days | -| TZ | Set the timezone inside the container [^2] +| ENV | Description | +| ----------------------- | -------------------------------------------------------------------------------------- | +| 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 (**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 | +| GID | Group ID to run the cron job with | +| LOGFILE | Path to the logfile *inside* the container | +| CRONFILE | Path to the cron file *inside* the container | +| DELETE_AFTER | Delete old backups after X many days | +| TZ | Set the timezone inside the container [^2] | +| ATTACHMENT_BACKUP_FILE | If present, the directory `ATTACHMENT_DIR` are backup in path `ATTACHMENT_BACKUP_FILE` | +| ATTACHMENT_DIR | Path to the Bitwarden attachement file *inside* the container | [^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. [^2]: see for more information @@ -75,4 +77,4 @@ If you need timestamps in your local timezone you should mount `/etc/timezone:/e like it's done in the [docker-compose.yml](docker-compose.yml). An other possible solution is to set the environment variable accordingly (like `TZ=Europe/Berlin`) (see for more information). -**Attention** if you are on an ARM based platform please note that [alpine](https://alpinelinux.org/) is used as base image for this project to keep things small. Since alpine 3.13 and above it's possible that you will end up with a container with broken time and date settings (i.e. year 1900). This is a known problem in the alpine project (see [Github issue](https://github.com/alpinelinux/docker-alpine/issues/141) and [solution](https://wiki.alpinelinux.org/wiki/Release_Notes_for_Alpine_3.13.0#time64_requirements)) and there is nothing I can do about it. However in the [alpine wiki](https://wiki.alpinelinux.org/wiki/Release_Notes_for_Alpine_3.13.0#time64_requirements) a solution is being proposed which I also tested tested on my raspberry pi. After following the described process it started working again as expected. If you still experience issues or could for some reason not apply the aforementioned fixes please feel free to open an issue. \ No newline at end of file +**Attention** if you are on an ARM based platform please note that [alpine](https://alpinelinux.org/) is used as base image for this project to keep things small. Since alpine 3.13 and above it's possible that you will end up with a container with broken time and date settings (i.e. year 1900). This is a known problem in the alpine project (see [Github issue](https://github.com/alpinelinux/docker-alpine/issues/141) and [solution](https://wiki.alpinelinux.org/wiki/Release_Notes_for_Alpine_3.13.0#time64_requirements)) and there is nothing I can do about it. However in the [alpine wiki](https://wiki.alpinelinux.org/wiki/Release_Notes_for_Alpine_3.13.0#time64_requirements) a solution is being proposed which I also tested tested on my raspberry pi. After following the described process it started working again as expected. If you still experience issues or could for some reason not apply the aforementioned fixes please feel free to open an issue. diff --git a/backup.sh b/backup.sh index cd65391..f192f88 100644 --- a/backup.sh +++ b/backup.sh @@ -7,13 +7,23 @@ then exit 1; fi + +# Chef if ATTACHMENT_BACKUP_FILE exist. If it's true, attechment are backup. We define var with or without TIMESTAMP +# In anycase, we define var LOCALVAR_ATTACHMENT_BACKUP_FILE to limit the complexity of code (the number of if-else) +LOCALVAR_ATTACHMENT_BACKUP_FILE = "" +if [ -v ATTACHMENT_BACKUP_FILE ] +then + LOCALVAR_ATTACHMENT_BACKUP_FILE = ${ATTACHMENT_BACKUP_FILE} +fi + + if [ $TIMESTAMP = true ] then FINAL_BACKUP_FILE="$(echo "$BACKUP_FILE")_$(date "+%F-%H%M%S")" - FINAL_BACKUP_ATTACHMENT="$(echo "$ATTACHMENT_BACKUP_FILE")_$(date "+%F-%H%M%S")" + FINAL_BACKUP_ATTACHMENT="$(echo "$LOCALVAR_ATTACHMENT_BACKUP_FILE")_$(date "+%F-%H%M%S")" else FINAL_BACKUP_FILE=$BACKUP_FILE - FINAL_BACKUP_ATTACHMENT=$ATTACHMENT_BACKUP_FILE + FINAL_BACKUP_ATTACHMENT=$LOCALVAR_ATTACHMENT_BACKUP_FILE fi @@ -25,10 +35,18 @@ else echo "$(date "+%F %T") - Backup unsuccessfull" fi -/bin/tar -cvzf ${FINAL_BACKUP_ATTACHMENT}.tgz ${ATTACHMENT_DIR} + +if [ -v ATTACHMENT_BACKUP_FILE ] +then + /bin/tar -cvzf ${FINAL_BACKUP_ATTACHMENT}.tgz ${ATTACHMENT_DIR} +fi if [ ! -z $DELETE_AFTER ] && [ $DELETE_AFTER -gt 0 ] then find $(dirname "$BACKUP_FILE") -name "$(basename "$BACKUP_FILE")*" -type f -mtime +$DELETE_AFTER -exec rm -f {} \; -exec echo "Deleted {} after $DELETE_AFTER days" \; - find $(dirname "$ATTACHMENT_BACKUP_FILE") -name "$(basename "$ATTACHMENT_BACKUP_FILE")*" -type f -mtime +$DELETE_AFTER -exec rm -f {} \; -exec echo "Deleted {} after $DELETE_AFTER days" \; + + if [ -v ATTACHMENT_BACKUP_FILE ] + then + find $(dirname "$FINAL_BACKUP_ATTACHMENT") -name "$(basename "$FINAL_BACKUP_ATTACHMENT")*" -type f -mtime +$DELETE_AFTER -exec rm -f {} \; -exec echo "Deleted {} after $DELETE_AFTER days" \; + fi fi From ed158d7406a6aa6f9d61893a738fc0e87cad526e Mon Sep 17 00:00:00 2001 From: pierre perso Date: Sun, 4 Apr 2021 08:18:58 +0000 Subject: [PATCH 5/6] fix: check ATTACHMENT_BACKUP_FILE :bulb: --- backup.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backup.sh b/backup.sh index f192f88..656dff4 100644 --- a/backup.sh +++ b/backup.sh @@ -11,7 +11,7 @@ fi # Chef if ATTACHMENT_BACKUP_FILE exist. If it's true, attechment are backup. We define var with or without TIMESTAMP # In anycase, we define var LOCALVAR_ATTACHMENT_BACKUP_FILE to limit the complexity of code (the number of if-else) LOCALVAR_ATTACHMENT_BACKUP_FILE = "" -if [ -v ATTACHMENT_BACKUP_FILE ] +if [ ! -z "${ATTACHMENT_BACKUP_FILE}" ] then LOCALVAR_ATTACHMENT_BACKUP_FILE = ${ATTACHMENT_BACKUP_FILE} fi @@ -36,7 +36,7 @@ else fi -if [ -v ATTACHMENT_BACKUP_FILE ] +if [ ! -z "${ATTACHMENT_BACKUP_FILE}" ] then /bin/tar -cvzf ${FINAL_BACKUP_ATTACHMENT}.tgz ${ATTACHMENT_DIR} fi @@ -45,7 +45,7 @@ if [ ! -z $DELETE_AFTER ] && [ $DELETE_AFTER -gt 0 ] then find $(dirname "$BACKUP_FILE") -name "$(basename "$BACKUP_FILE")*" -type f -mtime +$DELETE_AFTER -exec rm -f {} \; -exec echo "Deleted {} after $DELETE_AFTER days" \; - if [ -v ATTACHMENT_BACKUP_FILE ] + if [ ! -z "${ATTACHMENT_BACKUP_FILE}" ] then find $(dirname "$FINAL_BACKUP_ATTACHMENT") -name "$(basename "$FINAL_BACKUP_ATTACHMENT")*" -type f -mtime +$DELETE_AFTER -exec rm -f {} \; -exec echo "Deleted {} after $DELETE_AFTER days" \; fi From ec3d2621204bdf14897ac333d64a5cc981a9aec3 Mon Sep 17 00:00:00 2001 From: pierre perso Date: Sun, 4 Apr 2021 08:31:52 +0000 Subject: [PATCH 6/6] fix : difference between bash and shell --- backup.sh | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/backup.sh b/backup.sh index 656dff4..6e7a083 100644 --- a/backup.sh +++ b/backup.sh @@ -8,15 +8,15 @@ then fi -# Chef if ATTACHMENT_BACKUP_FILE exist. If it's true, attechment are backup. We define var with or without TIMESTAMP +# Check if ATTACHMENT_BACKUP_FILE exist. If it's true, attechment are backup. We define var with or without TIMESTAMP # In anycase, we define var LOCALVAR_ATTACHMENT_BACKUP_FILE to limit the complexity of code (the number of if-else) -LOCALVAR_ATTACHMENT_BACKUP_FILE = "" -if [ ! -z "${ATTACHMENT_BACKUP_FILE}" ] +if [ ! -z $ATTACHMENT_BACKUP_FILE ] then - LOCALVAR_ATTACHMENT_BACKUP_FILE = ${ATTACHMENT_BACKUP_FILE} + LOCALVAR_ATTACHMENT_BACKUP_FILE="$ATTACHMENT_BACKUP_FILE" +else + LOCALVAR_ATTACHMENT_BACKUP_FILE="" fi - if [ $TIMESTAMP = true ] then FINAL_BACKUP_FILE="$(echo "$BACKUP_FILE")_$(date "+%F-%H%M%S")" @@ -36,16 +36,17 @@ else fi -if [ ! -z "${ATTACHMENT_BACKUP_FILE}" ] +if [ ! -z $ATTACHMENT_BACKUP_FILE ] then - /bin/tar -cvzf ${FINAL_BACKUP_ATTACHMENT}.tgz ${ATTACHMENT_DIR} + echo "Create tar ${FINAL_BACKUP_ATTACHMENT}.tgz\n" + /bin/tar -czf ${FINAL_BACKUP_ATTACHMENT}.tgz ${ATTACHMENT_DIR} fi if [ ! -z $DELETE_AFTER ] && [ $DELETE_AFTER -gt 0 ] then find $(dirname "$BACKUP_FILE") -name "$(basename "$BACKUP_FILE")*" -type f -mtime +$DELETE_AFTER -exec rm -f {} \; -exec echo "Deleted {} after $DELETE_AFTER days" \; - if [ ! -z "${ATTACHMENT_BACKUP_FILE}" ] + if [ ! -z $ATTACHMENT_BACKUP_FILE ] then find $(dirname "$FINAL_BACKUP_ATTACHMENT") -name "$(basename "$FINAL_BACKUP_ATTACHMENT")*" -type f -mtime +$DELETE_AFTER -exec rm -f {} \; -exec echo "Deleted {} after $DELETE_AFTER days" \; fi