feat: support email notification when backup succeeds and fails
This commit is contained in:
1 parent
299fe93b9d
commit
89e45af55a
6 files changed
+141
-3
No files matched your search
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
FROM rclone/rclone:1.52.0
|
FROM rclone/rclone:1.52.1
|
||||||
|
|
||||||
LABEL "repository"="https://github.com/ttionya/BitwardenRS-Backup" \
|
LABEL "repository"="https://github.com/ttionya/BitwardenRS-Backup" \
|
||||||
"homepage"="https://github.com/ttionya/BitwardenRS-Backup" \
|
"homepage"="https://github.com/ttionya/BitwardenRS-Backup" \
|
||||||
@@ -7,6 +7,6 @@ LABEL "repository"="https://github.com/ttionya/BitwardenRS-Backup" \
|
|||||||
COPY scripts/*.sh /app/
|
COPY scripts/*.sh /app/
|
||||||
|
|
||||||
RUN chmod +x /app/*.sh \
|
RUN chmod +x /app/*.sh \
|
||||||
&& apk add --no-cache sqlite zip
|
&& apk add --no-cache sqlite zip heirloom-mailx
|
||||||
|
|
||||||
ENTRYPOINT ["/app/entrypoint.sh"]
|
ENTRYPOINT ["/app/entrypoint.sh"]
|
||||||
@@ -112,6 +112,62 @@ Only keep last a few days backup files in the storage system. Set to `0` to keep
|
|||||||
|
|
||||||
Default: `0`
|
Default: `0`
|
||||||
|
|
||||||
|
#### MAIL_SMTP_ENABLE
|
||||||
|
|
||||||
|
The tool uses [heirloom-mailx](https://www.systutorials.com/docs/linux/man/1-heirloom-mailx/) to send mail.
|
||||||
|
|
||||||
|
Default: `FALSE`
|
||||||
|
|
||||||
|
#### MAIL_SMTP_VARIABLES
|
||||||
|
|
||||||
|
Because the configuration for sending emails is too complicated, we allow you to configure it yourself.
|
||||||
|
|
||||||
|
**We will set the subject according to the usage scenario, so you should not use the `-s` option.**
|
||||||
|
|
||||||
|
When testing, we will add the `-v` option to display detailed information.
|
||||||
|
|
||||||
|
```text
|
||||||
|
# My example:
|
||||||
|
|
||||||
|
# For Zoho
|
||||||
|
-S smtp-use-starttls \
|
||||||
|
-S smtp=smtp://smtp.zoho.com:587 \
|
||||||
|
-S smtp-auth=login \
|
||||||
|
-S smtp-auth-user=<my-email-address> \
|
||||||
|
-S smtp-auth-password=<my-email-password> \
|
||||||
|
-S from=<my-email-address>
|
||||||
|
```
|
||||||
|
|
||||||
|
See [here](https://www.systutorials.com/sending-email-from-mailx-command-in-linux-using-gmails-smtp/) for more information.
|
||||||
|
|
||||||
|
#### MAIL_TO
|
||||||
|
|
||||||
|
Who will receive the notification email.
|
||||||
|
|
||||||
|
#### MAIL_WHEN_SUCCESS
|
||||||
|
|
||||||
|
Send email when backup is successful.
|
||||||
|
|
||||||
|
Default: `TRUE`
|
||||||
|
|
||||||
|
#### MAIL_WHEN_FAILURE
|
||||||
|
|
||||||
|
Send email when backup fails.
|
||||||
|
|
||||||
|
Default: `TRUE`
|
||||||
|
|
||||||
|
## Mail Test
|
||||||
|
|
||||||
|
You can use the following command to test the mail sending. Remember to replace your smtp variables.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
docker run --rm -it -e MAIL_SMTP_VARIABLES='<your smtp variables>' ttionya/bitwardenrs-backup:latest mail <mail send to>
|
||||||
|
|
||||||
|
# Or
|
||||||
|
|
||||||
|
docker run --rm -it -e MAIL_SMTP_VARIABLES='<your smtp variables>' -e MAIL_TO='<mail send to>' ttionya/bitwardenrs-backup:latest mail
|
||||||
|
```
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
MIT
|
MIT
|
||||||
+6
-1
@@ -3,7 +3,7 @@ version: '3'
|
|||||||
services:
|
services:
|
||||||
|
|
||||||
bitwardenrs:
|
bitwardenrs:
|
||||||
image: bitwardenrs/server:1.15.0
|
image: bitwardenrs/server:1.15.1
|
||||||
restart: always
|
restart: always
|
||||||
# environment:
|
# environment:
|
||||||
# SIGNUPS_ALLOWED: 'false'
|
# SIGNUPS_ALLOWED: 'false'
|
||||||
@@ -23,6 +23,11 @@ services:
|
|||||||
# ZIP_ENABLE: 'TRUE'
|
# ZIP_ENABLE: 'TRUE'
|
||||||
# ZIP_PASSWORD: 'WHEREISMYPASSWORD?'
|
# ZIP_PASSWORD: 'WHEREISMYPASSWORD?'
|
||||||
# BACKUP_KEEP_DAYS: 0
|
# BACKUP_KEEP_DAYS: 0
|
||||||
|
# MAIL_SMTP_ENABLE: 'FALSE'
|
||||||
|
# MAIL_SMTP_VARIABLES: ''
|
||||||
|
# MAIL_TO: ''
|
||||||
|
# MAIL_WHEN_SUCCESS: 'TRUE'
|
||||||
|
# MAIL_WHEN_FAILURE: 'TRUE'
|
||||||
volumes:
|
volumes:
|
||||||
- bitwardenrs-data:/bitwarden/data/
|
- bitwardenrs-data:/bitwarden/data/
|
||||||
- bitwardenrs-rclone-data:/config/
|
- bitwardenrs-rclone-data:/config/
|
||||||
|
|||||||
@@ -94,6 +94,11 @@ function upload() {
|
|||||||
rclone copy ${UPLOAD_FILE} ${RCLONE_REMOTE}
|
rclone copy ${UPLOAD_FILE} ${RCLONE_REMOTE}
|
||||||
if [[ $? != 0 ]]; then
|
if [[ $? != 0 ]]; then
|
||||||
color red "upload failed"
|
color red "upload failed"
|
||||||
|
|
||||||
|
if [[ "${MAIL_SMTP_ENABLE}" == "TRUE" && "${MAIL_WHEN_FAILURE}" == "TRUE" ]]; then
|
||||||
|
send_mail "BitwardenRS Backup Failed" "File upload failed at $(date +"%Y-%m-%d %H:%M:%S")."
|
||||||
|
fi
|
||||||
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@@ -128,4 +133,8 @@ upload
|
|||||||
clear_dir
|
clear_dir
|
||||||
clear_history
|
clear_history
|
||||||
|
|
||||||
|
if [[ "${MAIL_SMTP_ENABLE}" == "TRUE" && "${MAIL_WHEN_SUCCESS}" == "TRUE" ]]; then
|
||||||
|
send_mail "BitwardenRS Backup Success" "The file was successfully uploaded at $(date +"%Y-%m-%d %H:%M:%S")."
|
||||||
|
fi
|
||||||
|
|
||||||
color none ""
|
color none ""
|
||||||
@@ -9,6 +9,22 @@ if [[ "$1" == "rclone" ]]; then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# mailx test
|
||||||
|
if [[ "$1" == "mail" ]]; then
|
||||||
|
MAIL_SMTP_ENABLE="TRUE"
|
||||||
|
MAIL_DEBUG="TRUE"
|
||||||
|
|
||||||
|
if [[ -n "$2" ]]; then
|
||||||
|
MAIL_TO="$2"
|
||||||
|
fi
|
||||||
|
|
||||||
|
init_env
|
||||||
|
|
||||||
|
send_mail "BitwardenRS Backup Test" "Your SMTP looks configured correctly."
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
function configure_cron() {
|
function configure_cron() {
|
||||||
echo "${CRON} sh /app/backup.sh > /dev/stdout" >> /etc/crontabs/root
|
echo "${CRON} sh /app/backup.sh > /dev/stdout" >> /etc/crontabs/root
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,27 @@ function check_rclone_connection() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
########################################
|
||||||
|
# Send mail by mailx.
|
||||||
|
# Arguments:
|
||||||
|
# mail subject
|
||||||
|
# mail content
|
||||||
|
# Outputs:
|
||||||
|
# send mail result
|
||||||
|
########################################
|
||||||
|
function send_mail() {
|
||||||
|
if [[ "${MAIL_DEBUG}" == "TRUE" ]]; then
|
||||||
|
local MAIL_VERBOSE="-v"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$2" | mailx ${MAIL_VERBOSE} -s "$1" ${MAIL_SMTP_VARIABLES} ${MAIL_TO}
|
||||||
|
if [[ $? != 0 ]]; then
|
||||||
|
color red "mail sending failed"
|
||||||
|
else
|
||||||
|
color blue "mail send was successfully"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
########################################
|
########################################
|
||||||
# Initialization environment variables.
|
# Initialization environment variables.
|
||||||
# Arguments:
|
# Arguments:
|
||||||
@@ -80,6 +101,31 @@ function init_env() {
|
|||||||
BACKUP_KEEP_DAYS="${BACKUP_KEEP_DAYS_DEFAULT}"
|
BACKUP_KEEP_DAYS="${BACKUP_KEEP_DAYS_DEFAULT}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# MAIL_SMTP_ENABLE
|
||||||
|
# MAIL_TO
|
||||||
|
MAIL_SMTP_ENABLE=$(echo "${MAIL_SMTP_ENABLE}" | tr '[a-z]' '[A-Z]')
|
||||||
|
if [[ "${MAIL_SMTP_ENABLE}" == "TRUE" && -n "${MAIL_TO}" ]]; then
|
||||||
|
MAIL_SMTP_ENABLE="TRUE"
|
||||||
|
else
|
||||||
|
MAIL_SMTP_ENABLE="FALSE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# MAIL_WHEN_SUCCESS
|
||||||
|
MAIL_WHEN_SUCCESS=$(echo "${MAIL_WHEN_SUCCESS}" | tr '[a-z]' '[A-Z]')
|
||||||
|
if [[ "${MAIL_WHEN_SUCCESS}" == "FALSE" ]]; then
|
||||||
|
MAIL_WHEN_SUCCESS="FALSE"
|
||||||
|
else
|
||||||
|
MAIL_WHEN_SUCCESS="TRUE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# MAIL_WHEN_FAILURE
|
||||||
|
MAIL_WHEN_FAILURE=$(echo "${MAIL_WHEN_FAILURE}" | tr '[a-z]' '[A-Z]')
|
||||||
|
if [[ "${MAIL_WHEN_FAILURE}" == "FALSE" ]]; then
|
||||||
|
MAIL_WHEN_FAILURE="FALSE"
|
||||||
|
else
|
||||||
|
MAIL_WHEN_FAILURE="TRUE"
|
||||||
|
fi
|
||||||
|
|
||||||
color yellow "========================================"
|
color yellow "========================================"
|
||||||
color yellow "CRON: ${CRON}"
|
color yellow "CRON: ${CRON}"
|
||||||
color yellow "RCLONE_REMOTE_NAME: ${RCLONE_REMOTE_NAME}"
|
color yellow "RCLONE_REMOTE_NAME: ${RCLONE_REMOTE_NAME}"
|
||||||
@@ -88,5 +134,11 @@ function init_env() {
|
|||||||
color yellow "ZIP_ENABLE: ${ZIP_ENABLE}"
|
color yellow "ZIP_ENABLE: ${ZIP_ENABLE}"
|
||||||
color yellow "ZIP_PASSWORD: ${#ZIP_PASSWORD} Chars"
|
color yellow "ZIP_PASSWORD: ${#ZIP_PASSWORD} Chars"
|
||||||
color yellow "BACKUP_KEEP_DAYS: ${BACKUP_KEEP_DAYS}"
|
color yellow "BACKUP_KEEP_DAYS: ${BACKUP_KEEP_DAYS}"
|
||||||
|
color yellow "MAIL_SMTP_ENABLE: ${MAIL_SMTP_ENABLE}"
|
||||||
|
if [[ "${MAIL_SMTP_ENABLE}" == "TRUE" ]]; then
|
||||||
|
color yellow "MAIL_TO: ${MAIL_TO}"
|
||||||
|
color yellow "MAIL_WHEN_SUCCESS: ${MAIL_WHEN_SUCCESS}"
|
||||||
|
color yellow "MAIL_WHEN_FAILURE: ${MAIL_WHEN_FAILURE}"
|
||||||
|
fi
|
||||||
color yellow "========================================"
|
color yellow "========================================"
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user