#!/bin/bash [ -z "$BACKUP_LOC" ] && BACKUP_LOC="$HOME/backups" [ ! -e "$BACKUP_LOC" ] && mkdir -p $BACKUP_LOC [ -z "$COMPOSE" ] && COMPOSE="$(command -v docker-compose)" [ -z "$COMPOSE" ] && COMPOSE="/usr/local/bin/docker-compose" [ -z "$YML_LOC" ] && YML_LOC="$HOME/docker-compose.yml" COMPOSE="$COMPOSE -f $YML_LOC" if [ "$1" == 'daily' ]; then find $BACKUP_LOC -type f -name postgres-daily.* -mtime +7 -delete $COMPOSE exec -T -u postgres db sh -c "umask 0377 && /usr/local/bin/pg_dump -Fc -h db -d postgres -U postgres" > "$BACKUP_LOC/postgres-daily.$(date -Iseconds).pgsql" $COMPOSE run -T --rm rails rake mastodon:media:remove_remote fi if [ "$1" == 'hourly' ]; then find $BACKUP_LOC -type f -name postgres-hourly.* -mmin +360 -delete $COMPOSE exec -T -u postgres db sh -c "umask 0377 && /usr/local/bin/pg_dump -Fc -h db -d postgres -U postgres" > "$BACKUP_LOC/postgres-hourly.$(date -Iseconds).pgsql" fi