Skip to content

Commit

Permalink
added function
Browse files Browse the repository at this point in the history
  • Loading branch information
keithhubner committed May 2, 2024
1 parent 00d6f5b commit bf1afd9
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions backup_script.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
#!/bin/bash

function create_directorys() {
echo "Creating backup directory..."
mkdir -p "$APP_DIR"
mkdir -p "$APP_DIR/backups"
mkdir -p "$APP_DIR/logs"
}

create_directorys 2>&1 | tee -a $APP_DIR/logs/event.log

# # Create the backup directory if it doesn't exist
# echo "Creating backup directory..." >> $APP_DIR/logs/event.log
# mkdir -p "$APP_DIR"
# mkdir -p "$APP_DIR/backups"
# mkdir -p "$APP_DIR/logs"


# Cleanup function
cleanup() {
# Perform cleanup tasks here
echo "Cleaning up before exit..."
echo "Cleaning up before exit..." >> $APP_DIR/logs/event.log
# Example: Close file descriptors, remove temporary files, etc.
exit 0
}
Expand All @@ -12,12 +28,6 @@ trap 'cleanup' SIGINT SIGTERM

set -e

# Create the backup directory if it doesn't exist
echo "Creating backup directory..."
mkdir -p "$APP_DIR"
mkdir -p "$APP_DIR/backups"
mkdir -p "$APP_DIR/logs"

echo "Backup directory created successfully."

echo "Starting backup..."
Expand All @@ -29,25 +39,24 @@ LOG_TIMESTAMP=$(date +"%Y-%m-%d %H:%M:%S")
echo "[$LOG_TIMESTAMP] Starting backup..." >> $APP_DIR/logs/event.log

BACKUP_FILE="$APP_DIR/backups/$DB_NAME-$TIMESTAMP.sql"
echo "Backup file: $BACKUP_FILE"

echo "Backup file: $BACKUP_FILE" >> $APP_DIR/logs/event.log


# Perform the backup using mysqldump
# mariadb-dump --ssl -h "$DB_HOST" -u "$DB_USER" -p"$DB_PASSWORD" "$DB_NAME" > $BACKUP_FILE
echo "Running mysqldump..." >> $APP_DIR/logs/event.log
mariadb-dump -h "$DB_HOST" -u "$DB_USER" -p"$DB_PASSWORD" "$DB_NAME" > $BACKUP_FILE

# cat $BACKUP_FILE
echo "Running S3 Backup...."
echo "Running S3 Backup...." >> $APP_DIR/logs/event.log
s3cmd --host=${AWS_HOST} --host-bucket=s3://${BUCKET} put --acl-${PUB_PRIV} ${BACKUP_FILE} s3://${S3_PATH}

# Adding a change to test

echo "Running Cleanup...."
echo "Running Cleanup...." >> $APP_DIR/logs/event.log

# Cleanup

#!/bin/bash

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

Expand All @@ -67,9 +76,10 @@ s3cmd --host=${AWS_HOST} --host-bucket=s3://${BUCKET} ls --recursive s3://${S3_

# Check the file name and age
if [[ $FILE_NAME != *"CLI"* && $AGE -gt $OLDER_THAN_DAYS ]]; then
echo "Deleting $FILE_NAME which is $AGE days old."
echo "Deleting $FILE_NAME which is $AGE days old." >> $APP_DIR/logs/event.log
s3cmd --host=${AWS_HOST} --host-bucket=s3://${BUCKET} del "$FILE_NAME"
else
echo "Skipping $FILE_NAME"
echo "Skipping $FILE_NAME" >> $APP_DIR/logs/event.log
fi
done

0 comments on commit bf1afd9

Please sign in to comment.