#!/bin/bash

# Set the date format, filename and the directories where your backup files will be placed and which directory will be archived.
NOW=$(date +"%Y-%m-%d-%H%M")
FILE="slc.$NOW.tar"
BACKUP_DIR="backup"
WWW_DIR="slc"

# MySQL database credentials
DB_USER="psassheaodslc"
DB_PASS="e29zW64Nc8"
DB_NAME="psassheaodslc"
DB_FILE="psassheaodslc.$NOW.sql"

# Tar transforms for better archive structure.
WWW_TRANSFORM='s,^slc,www,'
DB_TRANSFORM='s,^backups,database,'

# Create the archive and the MySQL dump
tar -cvf $BACKUP_DIR/$FILE --transform $WWW_TRANSFORM $WWW_DIR

# Append the dump to the archive, remove the dump and compress the whole archive.
tar --append --file=$BACKUP_DIR/$FILE --transform $DB_TRANSFORM $BACKUP_DIR/$DB_FILE
rm $BACKUP_DIR/$DB_FILE
gzip -9 $BACKUP_DIR/$FILE
