fix: check upload file is exist before upload

(fixed #2)
This commit is contained in:
ttionya
2020-10-07 22:37:18 +08:00
parent 7e437a1884
commit dc91efcbc4
2 changed files with 33 additions and 6 deletions
+11 -6
View File
@@ -91,13 +91,20 @@ function backup_package() {
function upload() {
color blue "upload backup file to storage system"
# upload file not exist
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."
exit 1
fi
rclone copy ${UPLOAD_FILE} ${RCLONE_REMOTE}
if [[ $? != 0 ]]; then
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
send_mail_content "FALSE" "File upload failed at $(date +"%Y-%m-%d %H:%M:%S")."
exit 1
fi
@@ -133,8 +140,6 @@ upload
clear_dir
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
send_mail_content "TRUE" "The file was successfully uploaded at $(date +"%Y-%m-%d %H:%M:%S")."
color none ""
+22
View File
@@ -53,6 +53,28 @@ function send_mail() {
fi
}
########################################
# Send mail.
# Arguments:
# backup successful
# mail content
########################################
function send_mail_content() {
if [[ "${MAIL_SMTP_ENABLE}" == "FALSE" ]]; then
return
fi
# successful
if [[ "$1" == "TRUE" && "${MAIL_WHEN_SUCCESS}" == "TRUE" ]]; then
send_mail "BitwardenRS Backup Success" "$2"
fi
# failed
if [[ "$1" == "FALSE" && "${MAIL_WHEN_FAILURE}" == "TRUE" ]]; then
send_mail "BitwardenRS Backup Failed" "$2"
fi
}
########################################
# Initialization environment variables.
# Arguments: