all_backups=($(find /mnt/save -not -path '*/\.*' -type f | sort -r)) for ((i=${#all_backups[@]}-1; i>50; i--)); do echo rm old backpu ${all_backups[i]} >&2 rm -f ${all_backups[i]} || true done for b in "${all_backups[@]}"; do if [ -n "$b" ]; then du -sh "$b" if ! du -sh "$b" | grep -Ei "^[ \t]*[0-9][0-9]*[0-9]?(.0)?[mg]"; then echo would rm empty backup $b >&2 set -x mv "$b" "${b%/*}/.${b##*/}" set +x continue fi echo restoring $b >&2 if psql $DATABASE_URL < "$b"; then break fi fi done service postgresql start