#!/bin/sh

echo "########################################################"
echo "INFO: Starting backups on:" $(LC_ALL=C date)

echo "Running /usr/sbin/ymc-mysql-bu-run-automysqlbackup..."
/usr/sbin/ymc-mysql-bu-run-automysqlbackup > /var/log/ymc-mysql-backup/ymc-mysql-bu-run-automysqlbackup.current 2>&1
if [ $? -eq 0 ]; then
  echo "...DONE"
else
  echo "...FAILED"
fi

echo "Running /usr/sbin/ymc-mysql-bu-run-structure-backup..."
/usr/sbin/ymc-mysql-bu-run-structure-backup > /var/log/ymc-mysql-backup/ymc-mysql-bu-run-structure-backup.current 2>&1
if [ $? -eq 0 ]; then
  echo "...DONE"
else
  echo "...FAILED"
fi

echo "Running /usr/sbin/ymc-mysql-bu-run-maatkit-backup..."
/usr/sbin/ymc-mysql-bu-run-maatkit-backup > /var/log/ymc-mysql-backup/ymc-mysql-bu-run-maatkit-backup.current 2>&1
if [ $? -eq 0 ]; then
  echo "...DONE"
else
  echo "...FAILED"
fi

echo "Appending '.current'-logs to the appropriate '.log'-files..."
for file in $(ls /var/log/ymc-mysql-backup/*.current)
do
  echo "Processing '$file'..."
  cat $file >> $(echo $file | sed -r 's/\.current$/.log/')
  if [ $? -eq 0 ]; then
    echo "...DONE"
  else
    echo "...FAILED"
  fi
done

echo "INFO: Finished with backups on:" $(LC_ALL=C date)
echo "########################################################"
echo ""

