#!/bin/bash

USER=vmrcre

# tasks for regular maintenance of the NTVMR

echo "***" `date` Cleaning up GIT repository 'NT', committing any uncommitted stragglers floating out in the repo
su - -s /bin/bash $USER -c "cd /home/$USER/repos/NT && git commit -a -m 'committing weekly stragglers'"

echo "***" `date` Cleaning up GIT repository 'NT', garbage collecting and compressing
su - -s /bin/bash $USER -c "cd /home/$USER/repos/NT && ./cleanup.sh"

echo "***" `date` pushing GIT repository 'NT' to remote origin "(http://git.crosswire.org/www)"
su - -s /bin/bash $USER -c "cd /home/$USER/repos/NT && git push"

echo "***" `date` starting NTVMR full backaup
cd /data/backups && ./mkbackup.sh

#move latest full backup out of weekly rotation to monthly rotation and keep at most 4 monthly backups
cd /data/backups
OLDEST=`ls -t full-backup-*.tar.gz|tail -1`
if [ `ls full-backup-*.tar.gz|wc -l` -gt 4 ]; then rm -f $OLDEST && echo "***" `date` Removing old backup: $OLDEST; fi
