Last active
January 9, 2025 03:57
-
-
Save rbudiharso/a1e63fa7a4557585e8bfc8c0b0f0f46b to your computer and use it in GitHub Desktop.
This file contains hidden or 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/sh | |
# @describe Backup postgresql database | |
# @meta version v1.0.0 | |
# @env DB_URI | |
# @option -d --database $DB_URI database name | |
# @option -f --filename=. folder name to store the backup | |
# @option -r --recipient pgp public key used for encrypting the backup file | |
eval "$(argc --argc-eval "$0" "$@")" | |
backup_dir="$argc_filename/backup" | |
summary_file="$argc_filename/dbsize_origin" | |
backup_zip="$argc_filename/loyalty-backup-$(date --iso-8601).tar" | |
database_name=$(echo $argc_database | awk -F"/" '{print $4}') | |
mkdir -p $backup_dir | |
echo "back up database" | |
echo | |
pg_dump -Fd -OCcxv -d $argc_database -f $backup_dir | |
echo "generate summary" | |
echo | |
psql -d $argc_database -f summary.sql >$summary_file | |
echo "archiving" | |
echo | |
tar -cvf $backup_zip $backup_dir $summary_file | |
echo "encrypting" | |
gpg --encrypt --armor --recipient $argc_recipient $backup_zip | |
echo "done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment