#!/bin/bash hour=$(date +%H) day=$(date +%d) month=$(date +%m) year=$(date +%Y) dbdir=/srv/nextcloud/database dbname=nextcloud dbuser=ncadmin mkdir -p $dbdir cd $dbdir if [[ -z "$1" ]]; then echo "[$year-$month-$day] Error: called with missing hour parameter. Script exited without running." | tee error.log exit 1 fi if [[ $hour == "$1" ]]; then nc-occ maintenance:mode --on fi pg_dump -U $dbuser -d $dbname > $dbname-hourly-$hour.sql 2>> error.log if [[ $hour == "$1" ]]; then nc-occ maintenance:mode --off mv $dbname-hourly-$hour.sql $dbname-daily-$day.sql 2>> error.log fi if [[ $day == "01" ]]; then mv $dbname-daily-$day.sql $dbname-$year-$month-$day.sql 2>> error.log fi # If error.log is size 0, erase it because I don't like seeing it if [[ ! -s ./error.log ]]; then rm error.log fi