archive
This commit is contained in:
21
firefly/postgres/backup.sh
Executable file
21
firefly/postgres/backup.sh
Executable file
@@ -0,0 +1,21 @@
|
||||
#! /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
|
||||
Reference in New Issue
Block a user