#!/bin/bash

if [ -z "$RESTIC_REPOSITORY" ]; then
  echo "Please specify path for the restic repository"
  exit 0
fi

if [ -z "$RESTIC_PASSWORD" ]; then
  echo "Please input password for the archive"
  exit 0
fi

if [ -z "$MYSQL_USER" ]; then
  echo "Please specify user for the mysql"
  exit 0
fi

if [ -z "$MYSQL_PASSWORD" ]; then
  echo "Please input password for the mysql"
  exit 0
fi

mysqldump --opt --complete-insert --add-drop-database -u$MYSQL_USER -p$MYSQL_PASSWORD --databases gitea |
  restic backup --tag="gitea on mysql" --stdin --stdin-filename gitea.sql

restic backup --tag="source code" --exclude="lost+found" --one-file-system /mnt/data/gitea