
#!/bin/bash

### User params ###############

# Number of days to keep old Domoticz databases
DAYS=31

# Directory where Domoticz databases are saved with trailing separator
SAVE_DIR=/home/becky/DomoticzBackups/

# Rmote SSH account on computer hosting Domoticz
REMOTE_USER=woopi@goldserver.local

# Path to the upload script on the computer hosting Domoticz
UPLOAD_PATH=/home/woopi/.local/bin/upload

###############################


COUNT=$(find $SAVE_DIR -name "domoticz*db.gz" -mtime -$DAYS | wc -l)

if [ $COUNT -gt 0 ]
then
  echo "$COUNT files younger than $DAYS days, deleting older files (if any)"
  find $SAVE_DIR -name "domoticz*db.gz" -mtime +$DAYS -delete
else
  echo "No files younger than $DAYS days, older files (if any) not deleted"
fi

ssh $REMOTE_USER  $UPLOAD_PATH

