Updated restic password
parent
3b5ab6e98b
commit
9879f18833
|
@ -35,21 +35,24 @@ function check_backup_repo(){
|
|||
# Create the backup repository path if it does not exist
|
||||
[ -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
|
||||
stored_password=$(cat "$password_file")
|
||||
if [ "$stored_password" != "$ENV_NAME" ]; then
|
||||
echo "$(date) Password mismatch detected. Updating password to ${ENV_NAME}" | tee -a "${BACKUP_LOG_FILE}"
|
||||
echo "$ENV_NAME" > "$password_file"
|
||||
if [ -z "$stored_password" ] || [[ ${#stored_password} -lt 10 ]]; then
|
||||
# Generate a new password if the existing one is less than 10 characters
|
||||
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
|
||||
else
|
||||
# Create the password file if it doesn't exist
|
||||
echo "$ENV_NAME" > "$password_file"
|
||||
echo "$(date) Password file created with password: ${ENV_NAME}" | tee -a "${BACKUP_LOG_FILE}"
|
||||
# Generate and save a random 10-character password
|
||||
stored_password=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 10)
|
||||
echo "$stored_password" > "$password_file"
|
||||
echo "$(date) Password file created with password: ${stored_password}" | tee -a "${BACKUP_LOG_FILE}"
|
||||
fi
|
||||
|
||||
# Export the repository password
|
||||
export RESTIC_PASSWORD="$ENV_NAME"
|
||||
export RESTIC_PASSWORD="$stored_password"
|
||||
export RESTIC_REPOSITORY="$backup_repo_path"
|
||||
export FILES_COUNT=$(find "${backup_repo_path}" -mindepth 1 | wc -l)
|
||||
|
||||
|
@ -73,6 +76,7 @@ function check_backup_repo(){
|
|||
fi
|
||||
}
|
||||
|
||||
|
||||
function sendEmailNotification() {
|
||||
if [ -e "/usr/lib/jelastic/modules/api.module" ]; then
|
||||
[ -e "/var/run/jem.pid" ] && return 0;
|
||||
|
|
Loading…
Reference in New Issue