#!/bin/bash

nb_bk=$(ls ~gitea/*dump*.zip 2>/dev/null| wc -l)

if [ $nb_bk != 0 ]; then
	echo "EXISTING GITEA BACKUP!"
	exit
fi

sudo -u gitea sh -c "cd ~gitea; gitea dump -c /etc/gitea/app.ini > /dev/null"

backup_file=$(ls ~gitea/*dump*.zip)

#echo "backup file $backup_file"
sudo chown mathieu:mathieu "${backup_file}"
sudo chmod 777 "${backup_file}"

scp "${backup_file}" mathieu@bk.mathux.org:/srv/share/backup/
sudo rm $backup_file
