#!/bin/bash

install_dir=$1
date=`date +"%Y%m%d"`
backup_path="/home/GC/bgorges/cavalcade-backups/logs/$date.sql"

if [ '' = "$install_dir" ]; then
  echo 'You must provide a WordPress installation directory.'
  exit 1
fi

cd $install_dir
wp db export --tables=wp_cavalcade_logs $backup_path
gzip $backup_path
wp db query "DELETE FROM wp_cavalcade_logs WHERE timestamp < NOW() - INTERVAL 1 WEEK" 
