35 lines
990 B
Bash
Executable File
35 lines
990 B
Bash
Executable File
#!/bin/bash
|
|
|
|
echo "Creating postgres database dumps..."
|
|
|
|
CURRENTDATETIME=`date +"%Y-%m-%d_%H_%M_%S"`
|
|
|
|
FILENAME_WITH_DIR="/home/ubuntu/backups/postgres/dump_"$CURRENTDATETIME
|
|
|
|
FILENAME="dump_"$CURRENTDATETIME
|
|
|
|
/usr/bin/docker exec -t postgres pg_dumpall -c -U one800 > $FILENAME_WITH_DIR.sql
|
|
|
|
if [ $? -eq 0 ]; then
|
|
echo "dump created successfully!"
|
|
else
|
|
echo "dump failed!"
|
|
fi
|
|
|
|
echo "Uploading to b2..."
|
|
|
|
/usr/local/bin/b2 upload-file one800-backups $FILENAME_WITH_DIR.sql postgres/db-dumps/$FILENAME.sql --noProgress --quiet
|
|
|
|
if [ $? -eq 0 ]; then
|
|
echo "dump uploaded to b2 successfully!"
|
|
echo "removing the local dump file..."
|
|
sleep 2
|
|
rm $FILENAME_WITH_DIR.sql
|
|
echo "removed the local dump file successfully!"
|
|
else
|
|
echo "dump upload to b2 failed!"
|
|
fi
|
|
|
|
# you can schedule this script to run every day at a certain hour via the following crontab entry
|
|
# 1 10 * * * /bin/bash /home/ubuntu/backups/scripts/postgres-dump-backup.sh >> /home/ubuntu/logs/cronlogs/postgres-dump-backup.log
|