Updated restic password

main
Anthony 2024-11-13 01:13:53 +08:00
parent 3b5ab6e98b
commit 9879f18833
1 changed files with 14 additions and 10 deletions

View File

@ -35,21 +35,24 @@ function check_backup_repo(){
# Create the backup repository path if it does not exist # Create the backup repository path if it does not exist
[ -d "${backup_repo_path}" ] || mkdir -p "${backup_repo_path}" [ -d "${backup_repo_path}" ] || mkdir -p "${backup_repo_path}"
# Check if the password file exists and if it matches the ENV_NAME # Check if the password file exists, otherwise create a new random password
if [ -f "$password_file" ]; then if [ -f "$password_file" ]; then
stored_password=$(cat "$password_file") stored_password=$(cat "$password_file")
if [ "$stored_password" != "$ENV_NAME" ]; then if [ -z "$stored_password" ] || [[ ${#stored_password} -lt 10 ]]; then
echo "$(date) Password mismatch detected. Updating password to ${ENV_NAME}" | tee -a "${BACKUP_LOG_FILE}" # Generate a new password if the existing one is less than 10 characters
echo "$ENV_NAME" > "$password_file" echo "$(date) Password is invalid or too short. Generating a new password." | tee -a "${BACKUP_LOG_FILE}"
stored_password=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 10)
echo "$stored_password" > "$password_file"
fi fi
else else
# Create the password file if it doesn't exist # Generate and save a random 10-character password
echo "$ENV_NAME" > "$password_file" stored_password=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 10)
echo "$(date) Password file created with password: ${ENV_NAME}" | tee -a "${BACKUP_LOG_FILE}" echo "$stored_password" > "$password_file"
echo "$(date) Password file created with password: ${stored_password}" | tee -a "${BACKUP_LOG_FILE}"
fi fi
# Export the repository password # Export the repository password
export RESTIC_PASSWORD="$ENV_NAME" export RESTIC_PASSWORD="$stored_password"
export RESTIC_REPOSITORY="$backup_repo_path" export RESTIC_REPOSITORY="$backup_repo_path"
export FILES_COUNT=$(find "${backup_repo_path}" -mindepth 1 | wc -l) export FILES_COUNT=$(find "${backup_repo_path}" -mindepth 1 | wc -l)
@ -73,6 +76,7 @@ function check_backup_repo(){
fi fi
} }
function sendEmailNotification() { function sendEmailNotification() {
if [ -e "/usr/lib/jelastic/modules/api.module" ]; then if [ -e "/usr/lib/jelastic/modules/api.module" ]; then
[ -e "/var/run/jem.pid" ] && return 0; [ -e "/var/run/jem.pid" ] && return 0;