Files
pwcli/bin/README.md
T
2024-02-01 13:23:29 +01:00

2.0 KiB

Infra-Tools-n-Stuff

pwdb

A script that simplifies:

  • Dumping the production database
  • Restore a dump to local development server or stage
Prerequisites
  • ~/.pgpass with password set for the user root is required for this script to run. User root must have super privileges.
  • Prior using this script, the super-user root must be present.
  • For stage: Set the timezone of the database to Europe/Paris in RDS-config. (Europe/Stockholm is not yet supported by Aurora)
  • Before deploying to stage, the following users must be present.
    • funnel
    • datastudio
Configure user root as super user
CREATE ROLE root WITH PASSWORD 'secret' LOGIN;

-- For Amazon RDS
GRANT rds_superuser TO root;

-- For other instances
ALTER USER root WITH SUPERUSER;
Usage
    Usage: pwdb [OPTION]... [COMMAND] [SOURCE] <TARGET>

    Commands:
        dump <source>           dump database photowall from SOURCE
        sync <source> <target>  sync database photowall from SOURCE database to TARGET database

    Options:
        -d, --dry-run           don't actually run any commands, just print them
        -h, --help              display this help message
        -j, --jobs <num>        (DEFAULT: 1) number of processes to use when restoring the dump
        -p, --production        tells if the restored database is production like (stage or prod).
                                If set, additional grants will be handled
Examples
# Create a fresh backup of production database and restore to local development environment
$ pwdb sync url.to.production.server localhost

# Create a fresh backup of production database and restore to the staging environment
$ pwdb sync url.to.production.server url.to.local.server

# Create a fresh backup of production server.
$ pwdb dump url.to.production.server

Location of the downloaded database dump is ~/photowall.sql. If the file already exists when trying to sync, you are asked if you want to use the existing file or create a new.