Loading src/scripts/transfer +66 −14 Original line number Diff line number Diff line Loading @@ -341,6 +341,15 @@ go() { # Verify source verify_source "$SERVER_NAME" # Determine if we are living in a docker container or if we are on hardware.. #!/bin/bash if [ ! -f /.dockerenv ]; then DOCKER=0 info "Detected non-docker run." else DOCKER=1 info "Detected docker-based run." fi # Verify we have everything we need to move forward if [ "$SERVER_NAME" == "" ]; then warn "Failed to supply server name!" Loading Loading @@ -378,9 +387,16 @@ go() if [ "$PUSH" == 0 ] && [ "$TABLE" == 1 ]; then # if we are pulling a table echo "pg_dump --host $SERVER_IP --port $SERVER_PORT -U $SERVER_USER -d $SERVER_DB_NAME --verbose --table $SOURCE_NAME -Fp > $SOURCE_NAME.sql" if [ "$DOCKER" == 0 ]; then # If we aren't in a docker container docker run -i -e PGPASSWORD="$SERVER_PASS" postgres:alpine \ pg_dump --host "$SERVER_IP" --port "$SERVER_PORT" -U "$SERVER_USER" -d "$SERVER_DB_NAME"\ --verbose --table "$SOURCE_NAME" -Fp > "$SOURCE_NAME".sql else # If we are in a docker container export PGPASSWORD="$SERVER_PASS" pg_dump --host "$SERVER_IP" --port "$SERVER_PORT"\ -U "$SERVER_USER" -d "$SERVER_DB_NAME"\ --verbose --table "$SOURCE_NAME" -Fp > "$SOURCE_NAME".sql fi if [ "$?" == 0 ]; then info "Successfully retrieved table dump for '$GREEN$SOURCE_NAME$NORM'" Loading @@ -392,11 +408,18 @@ go() if [ "$PUSH" == 0 ] && [ "$TABLE" == 0 ]; then # if we are pulling a database echo "pg_dump --host $SERVER_IP --port $SERVER_PORT -U $SERVER_USER -d $SOURCE_NAME --verbose --format=custom > $SOURCE_NAME$(date +%F).backup" echo "pg_dump --create --host $SERVER_IP --port $SERVER_PORT -U $SERVER_USER -d $SOURCE_NAME --verbose --format=custom > $SOURCE_NAME$(date +%F).backup" if [ "$DOCKER" == 0 ]; then # If we aren't in a docker container docker run -i -e PGPASSWORD="$SERVER_PASS" postgres:alpine \ pg_dump --host "$SERVER_IP" --port "$SERVER_PORT" -U "$SERVER_USER" -d "$SOURCE_NAME"\ pg_dump --create --host "$SERVER_IP" --port "$SERVER_PORT" -U "$SERVER_USER" -d "$SOURCE_NAME"\ --verbose --format=custom > "$SOURCE_NAME"_"$(date +%F)".backup else export PGPASSWORD="$SERVER_PASS" pg_dump --create --host "$SERVER_IP" --port \ "$SERVER_PORT" -U "$SERVER_USER" -d "$SOURCE_NAME"\ --verbose --format=custom > "$SOURCE_NAME"_"$(date +%F)".backup fi if [ "$?" == 0 ]; then info "Successfully retrieved database dump for '$GREEN$SOURCE_NAME$NORM'" Loading @@ -419,10 +442,17 @@ go() file=$(ls ./"$SOURCE_NAME"*.*) echo "pg_restore --host $SERVER_IP --port $SERVER_PORT -U $SERVER_USER -d $SERVER_DB_NAME --verbose --clean --if-exists $file" echo "pg_restore --create --host $SERVER_IP --port $SERVER_PORT -U $SERVER_USER -d $SERVER_DB_NAME --verbose --clean --if-exists $file" if [ "$DOCKER" == 0 ]; then # If we aren't in a docker container docker run -i -e PGPASSWORD="$SERVER_PASS" --mount type=bind,source="$(pwd)"/"$file",target=/"$file" postgres:alpine \ pg_restore --host $SERVER_IP --port "$SERVER_PORT" -U "$SERVER_USER" -d "$SOURCE_NAME"\ pg_restore --create --host $SERVER_IP --port "$SERVER_PORT" -U "$SERVER_USER" -d "$SERVER_DB_NAME"\ --verbose --clean --if-exists "$file" else export PGPASSWORD="$SERVER_PASS" pg_restore --create --host $SERVER_IP --port \ "$SERVER_PORT" -U "$SERVER_USER" -d "$SERVER_DB_NAME"\ --verbose --clean --if-exists "$file" fi if [ "$?" == 0 ]; then info "Successfully pushed database dump for '$GREEN$SOURCE_NAME$NORM'" Loading @@ -444,9 +474,18 @@ go() file=$(ls ./"$SOURCE_NAME"*.*) echo "pg_restore --host $SERVER_IP --port $SERVER_PORT -U $SERVER_USER -d $SERVER_DB_NAME --verbose --clean --if-exists $file" if [ "$DOCKER" == 0 ]; then # If we aren't in a docker container docker run -i -e PGPASSWORD="$SERVER_PASS" --mount type=bind,source="$(pwd)"/"$file",target=/"$file" postgres:alpine \ psql --host $SERVER_IP --port "$SERVER_PORT" -U "$SERVER_USER" -d "$SERVER_DB_NAME"\ -f "$file" else export PGPASSWORD="$SERVER_PASS" psql --host $SERVER_IP \ --port "$SERVER_PORT" -U "$SERVER_USER" \ -d "$SERVER_DB_NAME" -f "$file" fi if [ "$?" == 0 ]; then info "Successfully pushed table '$GREEN$SOURCE_NAME$NORM'" Loading @@ -457,4 +496,17 @@ go() } banner # Check for dependencies if ! pg_restore --version &> /dev/null; then warn "'pg_restore' is not installed. Please install pg_restore and try again." exit 3 fi if ! pg_dump --version &> /dev/null; then warn "'pg_dump' is not installed. Please install pg_dump and try again." exit 3 fi if ! psql --version &> /dev/null; then warn "'psql' is not installed. Please install psql and try again." exit 3 fi parse_args "$@" Loading
src/scripts/transfer +66 −14 Original line number Diff line number Diff line Loading @@ -341,6 +341,15 @@ go() { # Verify source verify_source "$SERVER_NAME" # Determine if we are living in a docker container or if we are on hardware.. #!/bin/bash if [ ! -f /.dockerenv ]; then DOCKER=0 info "Detected non-docker run." else DOCKER=1 info "Detected docker-based run." fi # Verify we have everything we need to move forward if [ "$SERVER_NAME" == "" ]; then warn "Failed to supply server name!" Loading Loading @@ -378,9 +387,16 @@ go() if [ "$PUSH" == 0 ] && [ "$TABLE" == 1 ]; then # if we are pulling a table echo "pg_dump --host $SERVER_IP --port $SERVER_PORT -U $SERVER_USER -d $SERVER_DB_NAME --verbose --table $SOURCE_NAME -Fp > $SOURCE_NAME.sql" if [ "$DOCKER" == 0 ]; then # If we aren't in a docker container docker run -i -e PGPASSWORD="$SERVER_PASS" postgres:alpine \ pg_dump --host "$SERVER_IP" --port "$SERVER_PORT" -U "$SERVER_USER" -d "$SERVER_DB_NAME"\ --verbose --table "$SOURCE_NAME" -Fp > "$SOURCE_NAME".sql else # If we are in a docker container export PGPASSWORD="$SERVER_PASS" pg_dump --host "$SERVER_IP" --port "$SERVER_PORT"\ -U "$SERVER_USER" -d "$SERVER_DB_NAME"\ --verbose --table "$SOURCE_NAME" -Fp > "$SOURCE_NAME".sql fi if [ "$?" == 0 ]; then info "Successfully retrieved table dump for '$GREEN$SOURCE_NAME$NORM'" Loading @@ -392,11 +408,18 @@ go() if [ "$PUSH" == 0 ] && [ "$TABLE" == 0 ]; then # if we are pulling a database echo "pg_dump --host $SERVER_IP --port $SERVER_PORT -U $SERVER_USER -d $SOURCE_NAME --verbose --format=custom > $SOURCE_NAME$(date +%F).backup" echo "pg_dump --create --host $SERVER_IP --port $SERVER_PORT -U $SERVER_USER -d $SOURCE_NAME --verbose --format=custom > $SOURCE_NAME$(date +%F).backup" if [ "$DOCKER" == 0 ]; then # If we aren't in a docker container docker run -i -e PGPASSWORD="$SERVER_PASS" postgres:alpine \ pg_dump --host "$SERVER_IP" --port "$SERVER_PORT" -U "$SERVER_USER" -d "$SOURCE_NAME"\ pg_dump --create --host "$SERVER_IP" --port "$SERVER_PORT" -U "$SERVER_USER" -d "$SOURCE_NAME"\ --verbose --format=custom > "$SOURCE_NAME"_"$(date +%F)".backup else export PGPASSWORD="$SERVER_PASS" pg_dump --create --host "$SERVER_IP" --port \ "$SERVER_PORT" -U "$SERVER_USER" -d "$SOURCE_NAME"\ --verbose --format=custom > "$SOURCE_NAME"_"$(date +%F)".backup fi if [ "$?" == 0 ]; then info "Successfully retrieved database dump for '$GREEN$SOURCE_NAME$NORM'" Loading @@ -419,10 +442,17 @@ go() file=$(ls ./"$SOURCE_NAME"*.*) echo "pg_restore --host $SERVER_IP --port $SERVER_PORT -U $SERVER_USER -d $SERVER_DB_NAME --verbose --clean --if-exists $file" echo "pg_restore --create --host $SERVER_IP --port $SERVER_PORT -U $SERVER_USER -d $SERVER_DB_NAME --verbose --clean --if-exists $file" if [ "$DOCKER" == 0 ]; then # If we aren't in a docker container docker run -i -e PGPASSWORD="$SERVER_PASS" --mount type=bind,source="$(pwd)"/"$file",target=/"$file" postgres:alpine \ pg_restore --host $SERVER_IP --port "$SERVER_PORT" -U "$SERVER_USER" -d "$SOURCE_NAME"\ pg_restore --create --host $SERVER_IP --port "$SERVER_PORT" -U "$SERVER_USER" -d "$SERVER_DB_NAME"\ --verbose --clean --if-exists "$file" else export PGPASSWORD="$SERVER_PASS" pg_restore --create --host $SERVER_IP --port \ "$SERVER_PORT" -U "$SERVER_USER" -d "$SERVER_DB_NAME"\ --verbose --clean --if-exists "$file" fi if [ "$?" == 0 ]; then info "Successfully pushed database dump for '$GREEN$SOURCE_NAME$NORM'" Loading @@ -444,9 +474,18 @@ go() file=$(ls ./"$SOURCE_NAME"*.*) echo "pg_restore --host $SERVER_IP --port $SERVER_PORT -U $SERVER_USER -d $SERVER_DB_NAME --verbose --clean --if-exists $file" if [ "$DOCKER" == 0 ]; then # If we aren't in a docker container docker run -i -e PGPASSWORD="$SERVER_PASS" --mount type=bind,source="$(pwd)"/"$file",target=/"$file" postgres:alpine \ psql --host $SERVER_IP --port "$SERVER_PORT" -U "$SERVER_USER" -d "$SERVER_DB_NAME"\ -f "$file" else export PGPASSWORD="$SERVER_PASS" psql --host $SERVER_IP \ --port "$SERVER_PORT" -U "$SERVER_USER" \ -d "$SERVER_DB_NAME" -f "$file" fi if [ "$?" == 0 ]; then info "Successfully pushed table '$GREEN$SOURCE_NAME$NORM'" Loading @@ -457,4 +496,17 @@ go() } banner # Check for dependencies if ! pg_restore --version &> /dev/null; then warn "'pg_restore' is not installed. Please install pg_restore and try again." exit 3 fi if ! pg_dump --version &> /dev/null; then warn "'pg_dump' is not installed. Please install pg_dump and try again." exit 3 fi if ! psql --version &> /dev/null; then warn "'psql' is not installed. Please install psql and try again." exit 3 fi parse_args "$@"