Created
October 20, 2021 13:12
-
-
Save criess/94f21bffde5ecc0c4eeede46a6ae1c45 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## | |
# needs these env: | |
# FILENAME_PREFIX: prefix on basename of file to iterate over | |
# DBNAME: psql database name on local machine (or uri) | |
# default: 40 | |
KEEP_BACKUPS=${KEEP_BACKUPS:-40} | |
pg_dump $DBNAME | gzip -9 > "$HOME/$FILENAME_PREFIX-`date +%d%m%YT%H%M`.sql.gz" | |
DELETE_BACKUPS=$(ls -t "$HOME/" | tac | grep "$FILENAME_PREFIX" | grep ".sql.gz" | head -n"-$KEEP_BACKUPS") | |
if [ -n "$DELETE_BACKUPS" ]; then | |
rm $DELETE_BACKUPS | |
fi | |
exec ./diff_to_gsutil.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment