Skip to content

Commit

Permalink
feat: add timezone support
Browse files Browse the repository at this point in the history
  • Loading branch information
ttionya committed Oct 7, 2020
1 parent dc91efc commit e70e10d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ LABEL "repository"="https://github.com/ttionya/BitwardenRS-Backup" \
COPY scripts/*.sh /app/

RUN chmod +x /app/*.sh \
&& apk add --no-cache sqlite zip heirloom-mailx
&& apk add --no-cache sqlite zip heirloom-mailx tzdata

ENTRYPOINT ["/app/entrypoint.sh"]
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ Only keep last a few days backup files in the storage system. Set to `0` to keep

Default: `0`

#### TIMEZONE

You should set the available timezone name. Currently only used in mail.

Here is timezone list at [wikipedia](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).

Default: `UTC`

#### MAIL_SMTP_ENABLE

The tool uses [heirloom-mailx](https://www.systutorials.com/docs/linux/man/1-heirloom-mailx/) to send mail.
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ services:
# MAIL_TO: ''
# MAIL_WHEN_SUCCESS: 'TRUE'
# MAIL_WHEN_FAILURE: 'TRUE'
# TIMEZONE: 'UTC'
volumes:
- bitwardenrs-data:/bitwarden/data/
- bitwardenrs-rclone-data:/config/
Expand Down
6 changes: 3 additions & 3 deletions scripts/backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function upload() {
if [[ ! -f ${UPLOAD_FILE} ]]; then
color red "upload file not found"

send_mail_content "FALSE" "File upload failed at $(date +"%Y-%m-%d %H:%M:%S"). Reason: Upload file not found."
send_mail_content "FALSE" "File upload failed at $(date +"%Y-%m-%d %H:%M:%S %Z"). Reason: Upload file not found."

exit 1
fi
Expand All @@ -104,7 +104,7 @@ function upload() {
if [[ $? != 0 ]]; then
color red "upload failed"

send_mail_content "FALSE" "File upload failed at $(date +"%Y-%m-%d %H:%M:%S")."
send_mail_content "FALSE" "File upload failed at $(date +"%Y-%m-%d %H:%M:%S %Z")."

exit 1
fi
Expand Down Expand Up @@ -140,6 +140,6 @@ upload
clear_dir
clear_history

send_mail_content "TRUE" "The file was successfully uploaded at $(date +"%Y-%m-%d %H:%M:%S")."
send_mail_content "TRUE" "The file was successfully uploaded at $(date +"%Y-%m-%d %H:%M:%S %Z")."

color none ""
8 changes: 8 additions & 0 deletions scripts/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ if [[ "$1" == "mail" ]]; then
exit 0
fi

function configure_timezone() {
if [[ ! -f /etc/localtime || ! -f /etc/timezone ]]; then
cp -f /usr/share/zoneinfo/${TIMEZONE} /etc/localtime
echo "${TIMEZONE}" > /etc/timezone
fi
}

function configure_cron() {
local FIND_CRON_COUNT=$(crontab -l | grep -c 'backup.sh')
if [[ ${FIND_CRON_COUNT} -eq 0 ]]; then
Expand All @@ -34,6 +41,7 @@ function configure_cron() {

init_env
check_rclone_connection
configure_timezone
configure_cron

# foreground run crond
Expand Down
7 changes: 7 additions & 0 deletions scripts/includes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ function init_env() {
MAIL_WHEN_FAILURE="TRUE"
fi

# TIMEZONE
local TIMEZONE_MATCHED_COUNT=$(ls "/usr/share/zoneinfo/${TIMEZONE}" 2> /dev/null | wc -l)
if [[ ${TIMEZONE_MATCHED_COUNT} -ne 1 ]]; then
TIMEZONE="UTC"
fi

color yellow "========================================"
color yellow "CRON: ${CRON}"
color yellow "RCLONE_REMOTE_NAME: ${RCLONE_REMOTE_NAME}"
Expand All @@ -162,5 +168,6 @@ function init_env() {
color yellow "MAIL_WHEN_SUCCESS: ${MAIL_WHEN_SUCCESS}"
color yellow "MAIL_WHEN_FAILURE: ${MAIL_WHEN_FAILURE}"
fi
color yellow "TIMEZONE: ${TIMEZONE}"
color yellow "========================================"
}

0 comments on commit e70e10d

Please sign in to comment.