Skip to content

Commit

Permalink
fixed array
Browse files Browse the repository at this point in the history
  • Loading branch information
keithhubner committed May 9, 2024
1 parent 2895956 commit b986dea
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions backup_script.sh
@@ -1,8 +1,9 @@
#!/bin/bash
# Cleanup function

env_vars = ["DB_HOST", "DB_USER", "DB_PASSWORD", "DB_NAME", "BUCKET", "S3_PATH", "AWS_HOST", "PUB_PRIV", "OLDER_THAN_DAYS"]

# Array of environment variables
env_vars=("DB_HOST" "DB_USER" "DB_PASSWORD" "DB_NAME" "BUCKET" "S3_PATH" "AWS_HOST" "PUB_PRIV" "OLDER_THAN_DAYS")
for var in "${env_vars[@]}"
do
if [ -z "${!var}" ]; then
Expand Down Expand Up @@ -32,24 +33,21 @@ trap 'err' ERR
TIMESTAMP=$(date +"%Y%m%d%H%M%S")
LOG_TIMESTAMP=$(date +"%Y-%m-%d %H:%M:%S")

echo "Creating backup directory..."
mkdir -p "$APP_DIR"
mkdir -p "$APP_DIR/backups"
mkdir -p "$APP_DIR/logs"
echo "Backup directory created successfully."
# create log file
touch "$LOGFILE" || { echo "Cannot write to $LOGFILE"; exit 1; }
echo "Log file: $LOGFILE"

LOGFILE="$APP_DIR/logs/backup-$TIMESTAMP.log"
BACKUP_FILE="$APP_DIR/backups/$DB_NAME-$TIMESTAMP.sql"

# Current date in seconds
CURRENT_DATE=$(date +%s)

function create_directorys() {
echo "Creating backup directory..."
mkdir -p "$APP_DIR"
mkdir -p "$APP_DIR/backups"
mkdir -p "$APP_DIR/logs"
echo "Backup directory created successfully."
# create log file
touch "$LOGFILE" || { echo "Cannot write to $LOGFILE"; exit 1; }
echo "Log file: $LOGFILE"

}

function run_backup() {
echo "Backup file: $BACKUP_FILE"
echo "[$LOG_TIMESTAMP] Starting backup..."
Expand Down Expand Up @@ -91,13 +89,12 @@ function cleanup() {
}

function main() {
create_directorys 2>&1 | tee -a $LOGFILE
run_backup 2>&1 | tee -a $LOGFILE
run_s3_backup 2>&1 | tee -a $LOGFILE
cleanup 2>&1 | tee -a $LOGFILE
run_backup
run_s3_backup
cleanup
}

main
main | 2>&1 tee -a $LOGFILE



Expand Down

0 comments on commit b986dea

Please sign in to comment.