feat: add timezone support
This commit is contained in:
@@ -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"]
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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/
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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 ""
|
||||
|
||||
@@ -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
|
||||
@@ -34,6 +41,7 @@ function configure_cron() {
|
||||
|
||||
init_env
|
||||
check_rclone_connection
|
||||
configure_timezone
|
||||
configure_cron
|
||||
|
||||
# foreground run crond
|
||||
|
||||
@@ -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}"
|
||||
@@ -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 "========================================"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user