Created
April 27, 2024 22:58
-
-
Save alexmazaltov/7dc8ae036bd3d7fb78add10e316a9d4a to your computer and use it in GitHub Desktop.
In case anyone needs a script to get a backup from directus instance using postgres database here it is.
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
#backup.sh | |
#!/bin/bash | |
# Define variables | |
LABEL="DBASH" | |
REMOTE_USER="root" | |
REMOTE_HOST="15.15.15.1" | |
POSTGRES_CONTAINER_NAME="postgresql-s0g8css" | |
POSTGRES_USER="LKDoajsdhjkj123" # Replace with your PostgreSQL username | |
POSTGRES_DB="directus" # Replace with your PostgreSQL database name | |
REMOTE_DUMP_FOLDER="/root/" # Replace with the path to the remote dump folder | |
LOCAL_DUMP_FOLDER="/home/Camo/Documents/backups/directus_drama/" # Replace with the path to the local dump folder | |
# Create a dated filename for the dump | |
DUMP_FILENAME="$LABEL-$POSTGRES_DB-$(date +"%Y-%m-%d_%H-%M-%S").dump" | |
# Create the dump under the specified user | |
ssh $REMOTE_USER@$REMOTE_HOST "docker exec $POSTGRES_CONTAINER_NAME pg_dump -U $POSTGRES_USER -d $POSTGRES_DB > $REMOTE_DUMP_FOLDER/$DUMP_FILENAME" | |
# Copy the dump file from the remote server to localhost | |
scp $REMOTE_USER@$REMOTE_HOST:$REMOTE_DUMP_FOLDER/$DUMP_FILENAME $LOCAL_DUMP_FOLDER/ | |
# Optional: Delete the dump file from the remote server after transfer | |
ssh $REMOTE_USER@$REMOTE_HOST "rm $REMOTE_DUMP_FOLDER/$DUMP_FILENAME" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment