22 lines
597 B
Bash
Executable File
22 lines
597 B
Bash
Executable File
#! /bin/bash
|
|
|
|
set -e
|
|
set -x
|
|
service postgresql start
|
|
thisback="/mnt/back/$(date -u +%Y%m%d%H%M%S).dump"
|
|
rm -rf "$thisback" || true
|
|
mkdir -p "$(dirname "$thisback")"
|
|
pg_dump postgres://ffly:pwd@localhost/fireflyiii --clean > "$thisback"
|
|
service postgresql start
|
|
n=$(ls /mnt/back | wc -l)
|
|
if ((n<=25)); then
|
|
echo "No old backups to purge" >&2
|
|
exit 0
|
|
fi
|
|
((m=n-25))
|
|
stale=($(find /mnt/back/ -mindepth 1 -maxdepth 1 | sort | head -n $m))
|
|
echo "Purging: rm -rf ${stale[@]}" >&2
|
|
rm -rf "${stale[@]}"
|
|
remaining=($(find /mnt/back/ -mindepth 1 -maxdepth 1 | sort))
|
|
echo "Remains: ${remaining[@]}" >&2
|