# required settings
DB_USERNAME=''
DB_PASSWORD=''
DB_NAME=''
REDMINE_ROOT='' # e.g. /home/peter/rails/redmine.commanigy.com'
BACKUP_ROOT='' # e.g. /home/peter/backups (will be created)
# optional settings
GS_ROOT='gs://redmine-backup'
GS_FILENAME='backup_'`date +%Y%m%d`'.tar.gz'
echo 'Setting up directories'
mkdir $BACKUP_ROOT/redmine/db -p
mkdir $BACKUP_ROOT/redmine/files -p
echo 'Backing up database'
/usr/bin/mysqldump -u $DB_USERNAME --password=$DB_PASSWORD $DB_NAME | gzip > $BACKUP_ROOT/redmine/db/`date +%Y%m%d`.gz
echo 'Backing up attachments'
rsync -a $REDMINE_ROOT/files/ $BACKUP_ROOT/redmine/files/
echo 'Packing into single archive'
tar -czPf $GS_FILENAME $BACKUP_ROOT/redmine/
echo 'Creating bucket on Google Storage (if not already created)'
gsutil mb $GS_ROOT
echo 'Copying backup archive to Google Storage'
gsutil cp $GS_FILENAME $GS_ROOT
echo 'Cleanup by removing archive'
rm $GS_FILENAME
echo 'Backup complete'