File "postgres_local_restore_bash_script.txt"

Full path: /home/auuge/domains/files.auu.ge/public_html/dev/postgres_local_restore_bash_script.txt
File size: 1.57 KB
MIME-type: text/x-shellscript
Charset: utf-8

Download   Open   Back

#!/bin/bash

# To backup the script, use this
#PGPASSWORD='password' pg_dumpall \
#    --host=pgsql \
#    --port=5432 \
#    --username=sail \
#    --clean \
#    --if-exists \
#    --file=pgsql-full.sql


# To restore the script, use this
#PGPASSWORD='password' psql \
#    --host=pgsql \
#    --port=5432 \
#    --username=sail \
#    --dbname=postgres \
#    --file=pgsql-full.sql

./vendor/bin/sail down -v
./vendor/bin/sail up -d
sleep 1
./vendor/bin/sail exec laravel.test bash -lc "PGPASSWORD='password' psql --host=pgsql --port=5432 --username=sail --dbname=postgres --file=pgsql-full.sql"
./vendor/bin/sail artisan migrate

echo "Creating default bucket..."
curl --fail-with-body \
  --request PUT \
  --aws-sigv4 "aws:amz:us-east-1:s3" \
  --user "sail:password" \
  "http://localhost:9000/local"
echo "Bucket created!"



echo "Setting all users password to \"password\"... "

./vendor/bin/sail exec laravel.test bash -lc "
export PGPASSWORD='password';

psql \
  --host=pgsql \
  --port=5432 \
  --username=sail \
  --dbname=postgres \
  -A -t \
  -c \"SELECT datname
      FROM pg_database
      WHERE datallowconn = true
        AND datistemplate = false
        AND datname NOT IN ('postgres', 'template1', 'testing')
      ORDER BY datname;\" |
while IFS= read -r db; do
  [ -z \"\$db\" ] && continue;

  echo \"Updating users in database: \$db\";

  psql \
    --host=pgsql \
    --port=5432 \
    --username=sail \
    --dbname=\"\$db\" \
    --set=ON_ERROR_STOP=1 \
    --command='UPDATE users SET password = '\''\$2y\$10\$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi'\'';';
done
"