#!/bin/sh

# Script to backup jovian web platform locally

echo 'Backing up jovian platform ...'

# Backup all postgres just in case
echo 'Backing up PostgreSQL ...'
sudo -u postgres pg_dumpall > /home/jovian/Local/Backup/Postgres/dumpfile
echo 'PostgreSQL done.'

echo 'Backing up GOGS ...'
sudo -u gituser /home/gituser/gogs/gogs backup --target /home/gituser/
sudo mv /home/gituser/gogs-backup-2* /home/jovian/Local/Backup/Gogs/
sudo chown jovian:jovian /home/jovian/Local/Backup/Gogs/gogs-backup-2*
echo 'GOGS done.'

echo 'Backing up KANBOARD ...'
sudo -u postgres pg_dump kanboard_db > /home/jovian/Local/Backup/Postgres/kanboard_dumpfile
echo 'KANBOARD done.'

echo 'Backing up WIKI ...'
echo '> wiki db ...'
sudo -u postgres pg_dump wiki_db > /home/jovian/Local/Backup/Postgres/wiki_dumpfile

echo '> wiki files ...'
tar chf /home/jovian/Local/Backup/Wiki/mediawiki.tar /var/www/mediawiki
echo 'WIKI done.'

echo 'Platform saved.'
