Skip to main content

Posts

Showing posts with the label backup

Secure login to PostgreSQL via bash script

Introduction In this blog we will generate a PostgreSQL db backup of kong db which is running inside a docker container. We have a bash script which will be running on a host machine but it will execute the pg_dump command inside the docker container. All we need to ensure is we do not expose the password for the user we will be using to generate the db backup. Steps The high level steps are documented below: Create a backup_user for the db dump backup Create a .pgpass file for the backup_user Generate a db_dump using the pgpass file Create a backup_user Use below commands for the same Connect to kong docker container  Use below command to connect to kong container, assuming the container name is 'kong' docker exec -it kong /bin/bash Login to PostgreSQL db as admin user Use below command to connect to postgresql db as admin user for creating a new user for db export.  psql -d kong -U admin Create new user Use the sql query below for the same. Define some strong password as men...

Secure login to MySQL for bash scripts

Introduction In this blog we will connect to a mysql via CLI from a bash script for generating a db dump. A cleaner approach for the same is using mysql config editor. In this blog we are taking an example of a mysql container running inside docker and we have a script for taking a db backup using  mysqldump . We will not use a password as a parameter to  mysqldump  command instead we will use something called as login path. MySQL config editor It is a utility to store authentication credentials in a obfuscated login path file named as  .mylogin.cnf . How to do it ? View existing configurations To view existing configurations if there are any use below command. The command will output existing configurations if there are otherwise it won't print anything. mysql_config_editor print --all Sample output In the output below you can see that the password is obfuscated and is not readable directly. It is handled by the mysql utilities to use this password as per the flags ...