From 8ace47e583758953bb3c2a1a9395a2f0861d2278 Mon Sep 17 00:00:00 2001 From: Rob Harrison Date: Thu, 27 Jun 2019 13:28:32 +0100 Subject: [PATCH 01/10] Create integration-tests.sh --- postgres-backup-s3/integration-tests.sh | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 postgres-backup-s3/integration-tests.sh diff --git a/postgres-backup-s3/integration-tests.sh b/postgres-backup-s3/integration-tests.sh new file mode 100644 index 0000000..388abd4 --- /dev/null +++ b/postgres-backup-s3/integration-tests.sh @@ -0,0 +1,5 @@ +#! /bin/sh + +set -e + +echo "This worked ok" From ce5f707ef766b93122ec72a87dfed95df4bccfe5 Mon Sep 17 00:00:00 2001 From: Rob Harrison Date: Thu, 27 Jun 2019 13:29:14 +0100 Subject: [PATCH 02/10] Update Dockerfile --- postgres-backup-s3/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/postgres-backup-s3/Dockerfile b/postgres-backup-s3/Dockerfile index d5eed1c..2c44b23 100644 --- a/postgres-backup-s3/Dockerfile +++ b/postgres-backup-s3/Dockerfile @@ -21,5 +21,6 @@ ENV SCHEDULE **None** ADD run.sh run.sh ADD backup.sh backup.sh +ADD integration-tests.sh integration-tests.sh CMD ["sh", "run.sh"] From c4c1b1041f796f322c79bb2939fa6ffa548ae29a Mon Sep 17 00:00:00 2001 From: Rob Harrison Date: Thu, 27 Jun 2019 13:31:25 +0100 Subject: [PATCH 03/10] Rename integration-tests.sh to integration-tests.test.yml --- postgres-backup-s3/integration-tests.test.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 postgres-backup-s3/integration-tests.test.yml diff --git a/postgres-backup-s3/integration-tests.test.yml b/postgres-backup-s3/integration-tests.test.yml new file mode 100644 index 0000000..7d1a2de --- /dev/null +++ b/postgres-backup-s3/integration-tests.test.yml @@ -0,0 +1,3 @@ +sut: + build: . + command: integration-tests.sh From 85a310a47076f30ec9a36f3978746d37575076c4 Mon Sep 17 00:00:00 2001 From: Rob Harrison Date: Thu, 27 Jun 2019 13:44:36 +0100 Subject: [PATCH 04/10] Update integration-tests.test.yml Testing having fixed command --- postgres-backup-s3/integration-tests.test.yml | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/postgres-backup-s3/integration-tests.test.yml b/postgres-backup-s3/integration-tests.test.yml index 7d1a2de..e9d2447 100644 --- a/postgres-backup-s3/integration-tests.test.yml +++ b/postgres-backup-s3/integration-tests.test.yml @@ -1,3 +1,20 @@ +version: '3.7' +services: + msuk_db: + image: camptocamp/postgres:9.6 + deploy: + replicas: 1 + environment: + - POSTGRES_PASSWORD=12345 + - POSTGRES_USER=user + - PGDATA=/var/lib/postgresql/data/pgdata + configs: + - source: master-db-config_2 + target: /etc/postgresql/postgresql.conf + command: -c 'config_file=/etc/postgresql/postgresql.conf' +configs: + master-db-config: + file: ./config/master.conf sut: build: . - command: integration-tests.sh + command: 'sh integration-tests.sh' From 9b57e4926e450ded0e1f1d5366661f4e43106044 Mon Sep 17 00:00:00 2001 From: Rob Harrison Date: Thu, 27 Jun 2019 13:47:09 +0100 Subject: [PATCH 05/10] Create master.conf --- postgres-backup-s3/config/master.conf | 627 ++++++++++++++++++++++++++ 1 file changed, 627 insertions(+) create mode 100644 postgres-backup-s3/config/master.conf diff --git a/postgres-backup-s3/config/master.conf b/postgres-backup-s3/config/master.conf new file mode 100644 index 0000000..6b414aa --- /dev/null +++ b/postgres-backup-s3/config/master.conf @@ -0,0 +1,627 @@ +# ----------------------------- +# PostgreSQL configuration file +# ----------------------------- +# +# This file consists of lines of the form: +# +# name = value +# +# (The "=" is optional.) Whitespace may be used. Comments are introduced with +# "#" anywhere on a line. The complete list of parameter names and allowed +# values can be found in the PostgreSQL documentation. +# +# The commented-out settings shown in this file represent the default values. +# Re-commenting a setting is NOT sufficient to revert it to the default value; +# you need to reload the server. +# +# This file is read on server startup and when the server receives a SIGHUP +# signal. If you edit the file on a running system, you have to SIGHUP the +# server for the changes to take effect, or use "pg_ctl reload". Some +# parameters, which are marked below, require a server shutdown and restart to +# take effect. +# +# Any parameter can also be given as a command-line option to the server, e.g., +# "postgres -c log_connections=on". Some parameters can be changed at run time +# with the "SET" SQL command. +# +# Memory units: kB = kilobytes Time units: ms = milliseconds +# MB = megabytes s = seconds +# GB = gigabytes min = minutes +# TB = terabytes h = hours +# d = days + + +#------------------------------------------------------------------------------ +# FILE LOCATIONS +#------------------------------------------------------------------------------ + +# The default values of these variables are driven from the -D command-line +# option or PGDATA environment variable, represented here as ConfigDir. + +#data_directory = 'ConfigDir' # use data in another directory + # (change requires restart) +#hba_file = 'ConfigDir/pg_hba.conf' # host-based authentication file + # (change requires restart) +#ident_file = 'ConfigDir/pg_ident.conf' # ident configuration file + # (change requires restart) + +# If external_pid_file is not explicitly set, no extra PID file is written. +#external_pid_file = '' # write an extra PID file + # (change requires restart) + + +#------------------------------------------------------------------------------ +# CONNECTIONS AND AUTHENTICATION +#------------------------------------------------------------------------------ + +# - Connection Settings - + +listen_addresses = '*' + # comma-separated list of addresses; + # defaults to 'localhost'; use '*' for all + # (change requires restart) +#port = 5432 # (change requires restart) +max_connections = 500 # (change requires restart) +#superuser_reserved_connections = 3 # (change requires restart) +#unix_socket_directories = '/tmp' # comma-separated list of directories + # (change requires restart) +#unix_socket_group = '' # (change requires restart) +#unix_socket_permissions = 0777 # begin with 0 to use octal notation + # (change requires restart) +#bonjour = off # advertise server via Bonjour + # (change requires restart) +#bonjour_name = '' # defaults to the computer name + # (change requires restart) + +# - Security and Authentication - + +#authentication_timeout = 1min # 1s-600s +#ssl = off # (change requires restart) +#ssl_ciphers = 'HIGH:MEDIUM:+3DES:!aNULL' # allowed SSL ciphers + # (change requires restart) +#ssl_prefer_server_ciphers = on # (change requires restart) +#ssl_ecdh_curve = 'prime256v1' # (change requires restart) +#ssl_cert_file = 'server.crt' # (change requires restart) +#ssl_key_file = 'server.key' # (change requires restart) +#ssl_ca_file = '' # (change requires restart) +#ssl_crl_file = '' # (change requires restart) +#password_encryption = on +#db_user_namespace = off +#row_security = on + +# GSSAPI using Kerberos +#krb_server_keyfile = '' +#krb_caseins_users = off + +# - TCP Keepalives - +# see "man 7 tcp" for details + +#tcp_keepalives_idle = 0 # TCP_KEEPIDLE, in seconds; + # 0 selects the system default +#tcp_keepalives_interval = 0 # TCP_KEEPINTVL, in seconds; + # 0 selects the system default +#tcp_keepalives_count = 0 # TCP_KEEPCNT; + # 0 selects the system default + + +#------------------------------------------------------------------------------ +# RESOURCE USAGE (except WAL) +#------------------------------------------------------------------------------ + +# - Memory - + +shared_buffers = 160MB # min 128kB + # (change requires restart) +#huge_pages = try # on, off, or try + # (change requires restart) +#temp_buffers = 8MB # min 800kB +#max_prepared_transactions = 0 # zero disables the feature + # (change requires restart) +# Caution: it is not advisable to set max_prepared_transactions nonzero unless +# you actively intend to use prepared transactions. +#work_mem = 4MB # min 64kB +#maintenance_work_mem = 64MB # min 1MB +#autovacuum_work_mem = -1 # min 1MB, or -1 to use maintenance_work_mem +#max_stack_depth = 2MB # min 100kB +#dynamic_shared_memory_type = posix # the default is the first option + # supported by the operating system: + # posix + # sysv + # windows + # mmap + # use none to disable dynamic shared memory + # (change requires restart) + +# - Disk - + +#temp_file_limit = -1 # limits per-session temp file space + # in kB, or -1 for no limit + +# - Kernel Resource Usage - + +#max_files_per_process = 1000 # min 25 + # (change requires restart) +shared_preload_libraries = 'pg_stat_statements' # (change requires restart) +pg_stat_statements.max = 10000 +pg_stat_statements.track = all + +# - Cost-Based Vacuum Delay - + +#vacuum_cost_delay = 0 # 0-100 milliseconds +#vacuum_cost_page_hit = 1 # 0-10000 credits +#vacuum_cost_page_miss = 10 # 0-10000 credits +#vacuum_cost_page_dirty = 20 # 0-10000 credits +#vacuum_cost_limit = 200 # 1-10000 credits + +# - Background Writer - + +#bgwriter_delay = 200ms # 10-10000ms between rounds +#bgwriter_lru_maxpages = 100 # 0-1000 max buffers written/round +#bgwriter_lru_multiplier = 2.0 # 0-10.0 multipler on buffers scanned/round + +# - Asynchronous Behavior - + +#effective_io_concurrency = 1 # 1-1000; 0 disables prefetching +#max_worker_processes = 8 + + +#------------------------------------------------------------------------------ +# WRITE AHEAD LOG +#------------------------------------------------------------------------------ + +# - Settings - + +wal_level = hot_standby # minimal, archive, hot_standby, or logical + # (change requires restart) +#fsync = on # turns forced synchronization on or off +#synchronous_commit = on # synchronization level; + # off, local, remote_write, or on +#wal_sync_method = fsync # the default is the first option + # supported by the operating system: + # open_datasync + # fdatasync (default on Linux) + # fsync + # fsync_writethrough + # open_sync +#full_page_writes = on # recover from partial page writes +#wal_compression = off # enable compression of full-page writes +#wal_log_hints = off # also do full page writes of non-critical updates + # (change requires restart) +#wal_buffers = -1 # min 32kB, -1 sets based on shared_buffers + # (change requires restart) +#wal_writer_delay = 200ms # 1-10000 milliseconds + +#commit_delay = 0 # range 0-100000, in microseconds +#commit_siblings = 5 # range 1-1000 + +# - Checkpoints - + +#checkpoint_timeout = 5min # range 30s-1h +#max_wal_size = 1GB +#min_wal_size = 80MB +#checkpoint_completion_target = 0.5 # checkpoint target duration, 0.0 - 1.0 +#checkpoint_warning = 30s # 0 disables + +# - Archiving - + +#archive_mode = off # enables archiving; off, on, or always + # (change requires restart) +#archive_command = '' # command to use to archive a logfile segment + # placeholders: %p = path of file to archive + # %f = file name only + # e.g. 'test ! -f /mnt/server/archivedir/%f && cp %p /mnt/server/archivedir/%f' +#archive_timeout = 0 # force a logfile segment switch after this + # number of seconds; 0 disables + + +#------------------------------------------------------------------------------ +# REPLICATION +#------------------------------------------------------------------------------ + +# - Sending Server(s) - + +# Set these on the master and on any standby that will send replication data. + +max_wal_senders = 3 # max number of walsender processes + # (change requires restart) +wal_keep_segments = 8 # in logfile segments, 16MB each; 0 disables +#wal_sender_timeout = 60s # in milliseconds; 0 disables + +max_replication_slots = 10 # max number of replication slots + # (change requires restart) +#track_commit_timestamp = off # collect timestamp of transaction commit + # (change requires restart) + +# - Master Server - + +# These settings are ignored on a standby server. + +#synchronous_standby_names = '' # standby servers that provide sync rep + # comma-separated list of application_name + # from standby(s); '*' = all +#vacuum_defer_cleanup_age = 0 # number of xacts by which cleanup is delayed + +# - Standby Servers - + +# These settings are ignored on a master server. + +#hot_standby = off # "on" allows queries during recovery + # (change requires restart) +#max_standby_archive_delay = 30s # max delay before canceling queries + # when reading WAL from archive; + # -1 allows indefinite delay +#max_standby_streaming_delay = 30s # max delay before canceling queries + # when reading streaming WAL; + # -1 allows indefinite delay +#wal_receiver_status_interval = 10s # send replies at least this often + # 0 disables +#hot_standby_feedback = off # send info from standby to prevent + # query conflicts +#wal_receiver_timeout = 60s # time that receiver waits for + # communication from master + # in milliseconds; 0 disables +#wal_retrieve_retry_interval = 5s # time to wait before retrying to + # retrieve WAL after a failed attempt + + +#------------------------------------------------------------------------------ +# QUERY TUNING +#------------------------------------------------------------------------------ + +# - Planner Method Configuration - + +#enable_bitmapscan = on +#enable_hashagg = on +#enable_hashjoin = on +#enable_indexscan = on +#enable_indexonlyscan = on +#enable_material = on +#enable_mergejoin = on +#enable_nestloop = on +#enable_seqscan = on +#enable_sort = on +#enable_tidscan = on + +# - Planner Cost Constants - + +#seq_page_cost = 1.0 # measured on an arbitrary scale +#random_page_cost = 4.0 # same scale as above +#cpu_tuple_cost = 0.01 # same scale as above +#cpu_index_tuple_cost = 0.005 # same scale as above +#cpu_operator_cost = 0.0025 # same scale as above +#effective_cache_size = 4GB + +# - Genetic Query Optimizer - + +#geqo = on +#geqo_threshold = 12 +#geqo_effort = 5 # range 1-10 +#geqo_pool_size = 0 # selects default based on effort +#geqo_generations = 0 # selects default based on effort +#geqo_selection_bias = 2.0 # range 1.5-2.0 +#geqo_seed = 0.0 # range 0.0-1.0 + +# - Other Planner Options - + +#default_statistics_target = 100 # range 1-10000 +#constraint_exclusion = partition # on, off, or partition +#cursor_tuple_fraction = 0.1 # range 0.0-1.0 +#from_collapse_limit = 8 +#join_collapse_limit = 8 # 1 disables collapsing of explicit + # JOIN clauses + + +#------------------------------------------------------------------------------ +# ERROR REPORTING AND LOGGING +#------------------------------------------------------------------------------ + +# - Where to Log - + +#log_destination = 'stderr' # Valid values are combinations of + # stderr, csvlog, syslog, and eventlog, + # depending on platform. csvlog + # requires logging_collector to be on. + +# This is used when logging to stderr: +#logging_collector = off # Enable capturing of stderr and csvlog + # into log files. Required to be on for + # csvlogs. + # (change requires restart) + +# These are only used if logging_collector is on: +#log_directory = 'pg_log' # directory where log files are written, + # can be absolute or relative to PGDATA +#log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' # log file name pattern, + # can include strftime() escapes +#log_file_mode = 0600 # creation mode for log files, + # begin with 0 to use octal notation +#log_truncate_on_rotation = off # If on, an existing log file with the + # same name as the new log file will be + # truncated rather than appended to. + # But such truncation only occurs on + # time-driven rotation, not on restarts + # or size-driven rotation. Default is + # off, meaning append to existing files + # in all cases. +#log_rotation_age = 1d # Automatic rotation of logfiles will + # happen after that time. 0 disables. +#log_rotation_size = 10MB # Automatic rotation of logfiles will + # happen after that much log output. + # 0 disables. + +# These are relevant when logging to syslog: +#syslog_facility = 'LOCAL0' +#syslog_ident = 'postgres' + +# This is only relevant when logging to eventlog (win32): +# (change requires restart) +#event_source = 'PostgreSQL' + +# - When to Log - + +#client_min_messages = notice # values in order of decreasing detail: + # debug5 + # debug4 + # debug3 + # debug2 + # debug1 + # log + # notice + # warning + # error + +#log_min_messages = warning # values in order of decreasing detail: + # debug5 + # debug4 + # debug3 + # debug2 + # debug1 + # info + # notice + # warning + # error + # log + # fatal + # panic + +#log_min_error_statement = error # values in order of decreasing detail: + # debug5 + # debug4 + # debug3 + # debug2 + # debug1 + # info + # notice + # warning + # error + # log + # fatal + # panic (effectively off) + +#log_min_duration_statement = -1 # -1 is disabled, 0 logs all statements + # and their durations, > 0 logs only + # statements running at least this number + # of milliseconds + + +# - What to Log - + +#debug_print_parse = off +#debug_print_rewritten = off +#debug_print_plan = off +#debug_pretty_print = on +#log_checkpoints = off +#log_connections = off +#log_disconnections = off +#log_duration = off +#log_error_verbosity = default # terse, default, or verbose messages +#log_hostname = off +#log_line_prefix = '' # special values: + # %a = application name + # %u = user name + # %d = database name + # %r = remote host and port + # %h = remote host + # %p = process ID + # %t = timestamp without milliseconds + # %m = timestamp with milliseconds + # %i = command tag + # %e = SQL state + # %c = session ID + # %l = session line number + # %s = session start timestamp + # %v = virtual transaction ID + # %x = transaction ID (0 if none) + # %q = stop here in non-session + # processes + # %% = '%' + # e.g. '<%u%%%d> ' +#log_lock_waits = off # log lock waits >= deadlock_timeout +#log_statement = 'none' # none, ddl, mod, all +#log_replication_commands = off +#log_temp_files = -1 # log temporary files equal or larger + # than the specified size in kilobytes; + # -1 disables, 0 logs all temp files +#log_timezone = 'GMT' + + +# - Process Title - + +#cluster_name = '' # added to process titles if nonempty + # (change requires restart) +#update_process_title = on + + +#------------------------------------------------------------------------------ +# RUNTIME STATISTICS +#------------------------------------------------------------------------------ + +# - Query/Index Statistics Collector - + +#track_activities = on +#track_counts = on +#track_io_timing = off +#track_functions = none # none, pl, all +#track_activity_query_size = 1024 # (change requires restart) +#stats_temp_directory = 'pg_stat_tmp' + + +# - Statistics Monitoring - + +#log_parser_stats = off +#log_planner_stats = off +#log_executor_stats = off +#log_statement_stats = off + + +#------------------------------------------------------------------------------ +# AUTOVACUUM PARAMETERS +#------------------------------------------------------------------------------ + +#autovacuum = on # Enable autovacuum subprocess? 'on' + # requires track_counts to also be on. +#log_autovacuum_min_duration = -1 # -1 disables, 0 logs all actions and + # their durations, > 0 logs only + # actions running at least this number + # of milliseconds. +#autovacuum_max_workers = 3 # max number of autovacuum subprocesses + # (change requires restart) +#autovacuum_naptime = 1min # time between autovacuum runs +#autovacuum_vacuum_threshold = 50 # min number of row updates before + # vacuum +#autovacuum_analyze_threshold = 50 # min number of row updates before + # analyze +#autovacuum_vacuum_scale_factor = 0.2 # fraction of table size before vacuum +#autovacuum_analyze_scale_factor = 0.1 # fraction of table size before analyze +#autovacuum_freeze_max_age = 200000000 # maximum XID age before forced vacuum + # (change requires restart) +#autovacuum_multixact_freeze_max_age = 400000000 # maximum multixact age + # before forced vacuum + # (change requires restart) +#autovacuum_vacuum_cost_delay = 20ms # default vacuum cost delay for + # autovacuum, in milliseconds; + # -1 means use vacuum_cost_delay +#autovacuum_vacuum_cost_limit = -1 # default vacuum cost limit for + # autovacuum, -1 means use + # vacuum_cost_limit + + +#------------------------------------------------------------------------------ +# CLIENT CONNECTION DEFAULTS +#------------------------------------------------------------------------------ + +# - Statement Behavior - + +#search_path = '"$user", public' # schema names +#default_tablespace = '' # a tablespace name, '' uses the default +#temp_tablespaces = '' # a list of tablespace names, '' uses + # only default tablespace +#check_function_bodies = on +#default_transaction_isolation = 'read committed' +#default_transaction_read_only = off +#default_transaction_deferrable = off +#session_replication_role = 'origin' +#statement_timeout = 0 # in milliseconds, 0 is disabled +#lock_timeout = 0 # in milliseconds, 0 is disabled +#vacuum_freeze_min_age = 50000000 +#vacuum_freeze_table_age = 150000000 +#vacuum_multixact_freeze_min_age = 5000000 +#vacuum_multixact_freeze_table_age = 150000000 +#bytea_output = 'hex' # hex, escape +#xmlbinary = 'base64' +#xmloption = 'content' +#gin_fuzzy_search_limit = 0 +#gin_pending_list_limit = 4MB + +# - Locale and Formatting - + +#datestyle = 'iso, mdy' +#intervalstyle = 'postgres' +#timezone = 'GMT' +#timezone_abbreviations = 'Default' # Select the set of available time zone + # abbreviations. Currently, there are + # Default + # Australia (historical usage) + # India + # You can create your own file in + # share/timezonesets/. +#extra_float_digits = 0 # min -15, max 3 +#client_encoding = sql_ascii # actually, defaults to database + # encoding + +# These settings are initialized by initdb, but they can be changed. +#lc_messages = 'C' # locale for system error message + # strings +#lc_monetary = 'C' # locale for monetary formatting +#lc_numeric = 'C' # locale for number formatting +#lc_time = 'C' # locale for time formatting + +# default configuration for text search +#default_text_search_config = 'pg_catalog.simple' + +# - Other Defaults - + +#dynamic_library_path = '$libdir' +#local_preload_libraries = '' +#session_preload_libraries = '' + + +#------------------------------------------------------------------------------ +# LOCK MANAGEMENT +#------------------------------------------------------------------------------ + +#deadlock_timeout = 1s +#max_locks_per_transaction = 64 # min 10 + # (change requires restart) +#max_pred_locks_per_transaction = 64 # min 10 + # (change requires restart) + + +#------------------------------------------------------------------------------ +# VERSION/PLATFORM COMPATIBILITY +#------------------------------------------------------------------------------ + +# - Previous PostgreSQL Versions - + +#array_nulls = on +#backslash_quote = safe_encoding # on, off, or safe_encoding +#default_with_oids = off +#escape_string_warning = on +#lo_compat_privileges = off +#operator_precedence_warning = off +#quote_all_identifiers = off +#sql_inheritance = on +#standard_conforming_strings = on +#synchronize_seqscans = on + +# - Other Platforms and Clients - + +#transform_null_equals = off + + +#------------------------------------------------------------------------------ +# ERROR HANDLING +#------------------------------------------------------------------------------ + +#exit_on_error = off # terminate session on any error? +#restart_after_crash = on # reinitialize after backend crash? + + +#------------------------------------------------------------------------------ +# CONFIG FILE INCLUDES +#------------------------------------------------------------------------------ + +# These options allow settings to be loaded from files other than the +# default postgresql.conf. + +#include_dir = 'conf.d' # include files ending in '.conf' from + # directory 'conf.d' +#include_if_exists = 'exists.conf' # include file only if it exists +#include = 'special.conf' # include file + + +#------------------------------------------------------------------------------ +# CUSTOMIZED OPTIONS +#------------------------------------------------------------------------------ + +# Add settings for extensions here From 428d22384eaae01aaf1651adc735dc605af9367c Mon Sep 17 00:00:00 2001 From: Rob Harrison Date: Thu, 27 Jun 2019 13:49:11 +0100 Subject: [PATCH 06/10] Update integration-tests.test.yml Added depends on --- postgres-backup-s3/integration-tests.test.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/postgres-backup-s3/integration-tests.test.yml b/postgres-backup-s3/integration-tests.test.yml index e9d2447..3723e9b 100644 --- a/postgres-backup-s3/integration-tests.test.yml +++ b/postgres-backup-s3/integration-tests.test.yml @@ -1,6 +1,6 @@ version: '3.7' services: - msuk_db: + postgres: image: camptocamp/postgres:9.6 deploy: replicas: 1 @@ -18,3 +18,5 @@ configs: sut: build: . command: 'sh integration-tests.sh' + depends_on: + - postgres From d4ee93ab691bbdfd2cd2a477fc2cec2f272d96ac Mon Sep 17 00:00:00 2001 From: Rob Harrison Date: Thu, 27 Jun 2019 13:52:42 +0100 Subject: [PATCH 07/10] Update integration-tests.test.yml Oops. SUT System under test is a service not a top level object. --- postgres-backup-s3/integration-tests.test.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/postgres-backup-s3/integration-tests.test.yml b/postgres-backup-s3/integration-tests.test.yml index 3723e9b..554333e 100644 --- a/postgres-backup-s3/integration-tests.test.yml +++ b/postgres-backup-s3/integration-tests.test.yml @@ -12,11 +12,11 @@ services: - source: master-db-config_2 target: /etc/postgresql/postgresql.conf command: -c 'config_file=/etc/postgresql/postgresql.conf' + sut: + build: . + command: 'sh integration-tests.sh' + depends_on: + - postgres configs: master-db-config: file: ./config/master.conf -sut: - build: . - command: 'sh integration-tests.sh' - depends_on: - - postgres From c822515b362b6ff3af14e9ed106496424f80fe15 Mon Sep 17 00:00:00 2001 From: Rob Harrison Date: Thu, 27 Jun 2019 14:03:03 +0100 Subject: [PATCH 08/10] Update integration-tests.test.yml Remove unsupported versioning. Doesn't use stack deploy, uses docker-compose to run tests. --- postgres-backup-s3/integration-tests.test.yml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/postgres-backup-s3/integration-tests.test.yml b/postgres-backup-s3/integration-tests.test.yml index 554333e..32ccd69 100644 --- a/postgres-backup-s3/integration-tests.test.yml +++ b/postgres-backup-s3/integration-tests.test.yml @@ -2,21 +2,11 @@ version: '3.7' services: postgres: image: camptocamp/postgres:9.6 - deploy: - replicas: 1 environment: - POSTGRES_PASSWORD=12345 - POSTGRES_USER=user - - PGDATA=/var/lib/postgresql/data/pgdata - configs: - - source: master-db-config_2 - target: /etc/postgresql/postgresql.conf - command: -c 'config_file=/etc/postgresql/postgresql.conf' sut: build: . command: 'sh integration-tests.sh' depends_on: - postgres -configs: - master-db-config: - file: ./config/master.conf From 37f28b7fddb228e648658f10e76d8492157ebf41 Mon Sep 17 00:00:00 2001 From: Rob Harrison Date: Thu, 27 Jun 2019 15:48:35 +0100 Subject: [PATCH 09/10] Added example test import and export --- postgres-backup-s3/Dockerfile | 1 + postgres-backup-s3/config/sample_sql_file.sql | 118 ++++++++++++++++++ postgres-backup-s3/integration-tests.sh | 65 ++++++++++ postgres-backup-s3/integration-tests.test.yml | 3 + 4 files changed, 187 insertions(+) create mode 100644 postgres-backup-s3/config/sample_sql_file.sql diff --git a/postgres-backup-s3/Dockerfile b/postgres-backup-s3/Dockerfile index 2c44b23..1be5bac 100644 --- a/postgres-backup-s3/Dockerfile +++ b/postgres-backup-s3/Dockerfile @@ -22,5 +22,6 @@ ENV SCHEDULE **None** ADD run.sh run.sh ADD backup.sh backup.sh ADD integration-tests.sh integration-tests.sh +ADD config/sample_sql_file.sql sample_sql_file.sql CMD ["sh", "run.sh"] diff --git a/postgres-backup-s3/config/sample_sql_file.sql b/postgres-backup-s3/config/sample_sql_file.sql new file mode 100644 index 0000000..3bb03ad --- /dev/null +++ b/postgres-backup-s3/config/sample_sql_file.sql @@ -0,0 +1,118 @@ +-- +-- PostgreSQL database dump +-- + +-- Dumped from database version 9.6.13 +-- Dumped by pg_dump version 10.8 + +SET statement_timeout = 0; +SET lock_timeout = 0; +SET idle_in_transaction_session_timeout = 0; +SET client_encoding = 'UTF8'; +SET standard_conforming_strings = on; +SELECT pg_catalog.set_config('search_path', '', false); +SET check_function_bodies = false; +SET xmloption = content; +SET client_min_messages = warning; +SET row_security = off; + +-- +-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: +-- + +CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog; + + +-- +-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: +-- + +COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language'; + + +SET default_tablespace = ''; + +SET default_with_oids = false; + +-- +-- Name: user_details; Type: TABLE; Schema: public; Owner: user +-- + +CREATE TABLE public.user_details ( + user_id integer NOT NULL, + username character varying(255) DEFAULT NULL::character varying, + first_name character varying(50) DEFAULT NULL::character varying, + last_name character varying(50) DEFAULT NULL::character varying, + gender character varying(10) DEFAULT NULL::character varying, + password character varying(50) DEFAULT NULL::character varying, + status integer +); + + +ALTER TABLE public.user_details OWNER TO "user"; + +-- +-- Name: user_details_user_id_seq; Type: SEQUENCE; Schema: public; Owner: user +-- + +CREATE SEQUENCE public.user_details_user_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE public.user_details_user_id_seq OWNER TO "user"; + +-- +-- Name: user_details_user_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: user +-- + +ALTER SEQUENCE public.user_details_user_id_seq OWNED BY public.user_details.user_id; + + +-- +-- Name: user_details user_id; Type: DEFAULT; Schema: public; Owner: user +-- + +ALTER TABLE ONLY public.user_details ALTER COLUMN user_id SET DEFAULT nextval('public.user_details_user_id_seq'::regclass); + + +-- +-- Data for Name: user_details; Type: TABLE DATA; Schema: public; Owner: user +-- + +COPY public.user_details (user_id, username, first_name, last_name, gender, password, status) FROM stdin; +1 rogers63 david john Female asdfa 1 +2 mike28 rogers paul Male afda 1 +3 rivera92 david john Male asdf 1 +4 ross95 maria sanders Male asdf 1 +5 paul85 morris miller Female asdf 1 +6 smith34 daniel michael Female sa 1 +7 james84 sanders paul Female fds 1 +8 daniel53 mark mike Male sdfa 1 +9 brooks80 morgan maria Female fasdf 1 +10 morgan65 paul miller Female fdsa 1 +\. + + +-- +-- Name: user_details_user_id_seq; Type: SEQUENCE SET; Schema: public; Owner: user +-- + +SELECT pg_catalog.setval('public.user_details_user_id_seq', 1, false); + + +-- +-- Name: user_details user_details_pkey; Type: CONSTRAINT; Schema: public; Owner: user +-- + +ALTER TABLE ONLY public.user_details + ADD CONSTRAINT user_details_pkey PRIMARY KEY (user_id); + + +-- +-- PostgreSQL database dump complete +-- + diff --git a/postgres-backup-s3/integration-tests.sh b/postgres-backup-s3/integration-tests.sh index 388abd4..7039bc9 100644 --- a/postgres-backup-s3/integration-tests.sh +++ b/postgres-backup-s3/integration-tests.sh @@ -2,4 +2,69 @@ set -e +RETRIES=60 + +until psql -h postgres -U user -c "select 1" > /dev/null 2>&1 || [ $RETRIES -eq 0 ]; do + echo "Waiting for postgres server, $((RETRIES--)) remaining attempts..." + sleep 3 +done + +OUT=$(psql -h postgres -U user -v ON_ERROR_STOP=1 -1 -f sample_sql_file.sql) + +EXPECTED="SET +SET +SET +SET +SET + set_config +------------ + +(1 row) + +SET +SET +SET +SET +CREATE EXTENSION +COMMENT +SET +SET +CREATE TABLE +ALTER TABLE +CREATE SEQUENCE +ALTER TABLE +ALTER SEQUENCE +ALTER TABLE +COPY 10 + setval +-------- + 1 +(1 row) + +ALTER TABLE" + +if [ "$OUT" != "$EXPECTED" ]; then + echo "OUT = '$OUT'" + echo "Not '$EXPECTED'" + exit 1 +fi + +pg_dump -h postgres -U user > sample_output.sql + +DIFF=$(diff sample_sql_file.sql sample_output.sql) + +if [ "$DIFF" != "" ]; then + echo "Expected output from diff was ''" + echo "Actual output was '$DIFF'" + exit 1 +fi + +# apt-get update && apt-get install -y wget + +# wget "https://sample-videos.com/sql/Sample-SQL-File-10rows.sql" + + +# echo "Cleaning Up..." +# rm Sample-SQL-File-10rows.sql echo "This worked ok" + diff --git a/postgres-backup-s3/integration-tests.test.yml b/postgres-backup-s3/integration-tests.test.yml index 32ccd69..841454a 100644 --- a/postgres-backup-s3/integration-tests.test.yml +++ b/postgres-backup-s3/integration-tests.test.yml @@ -5,8 +5,11 @@ services: environment: - POSTGRES_PASSWORD=12345 - POSTGRES_USER=user + - PGDATA=/var/lib/postgresql/data/pgdata sut: build: . command: 'sh integration-tests.sh' + environment: + - PGPASSWORD=12345 depends_on: - postgres From f1a4d408e99a359f2762311b3cb0e572101abe10 Mon Sep 17 00:00:00 2001 From: Rob Harrison Date: Thu, 27 Jun 2019 16:24:22 +0100 Subject: [PATCH 10/10] Added upload to the unit tests --- postgres-backup-s3/.#README.md | 1 + postgres-backup-s3/integration-tests.sh | 15 +++++++++++++++ postgres-backup-s3/integration-tests.test.yml | 14 ++++++++++++-- 3 files changed, 28 insertions(+), 2 deletions(-) create mode 120000 postgres-backup-s3/.#README.md diff --git a/postgres-backup-s3/.#README.md b/postgres-backup-s3/.#README.md new file mode 120000 index 0000000..a0ebd8e --- /dev/null +++ b/postgres-backup-s3/.#README.md @@ -0,0 +1 @@ +robwithhair@Robs-MacBook.local.5737 \ No newline at end of file diff --git a/postgres-backup-s3/integration-tests.sh b/postgres-backup-s3/integration-tests.sh index 7039bc9..dca4f03 100644 --- a/postgres-backup-s3/integration-tests.sh +++ b/postgres-backup-s3/integration-tests.sh @@ -59,6 +59,21 @@ if [ "$DIFF" != "" ]; then exit 1 fi + +if [ "${S3_S3V4}" = "yes" ]; then + aws configure set default.s3.signature_version s3v4 +fi + +OUT=$(sh backup.sh) +EXPECTED="Creating dump of user database from postgres... +Uploading dump to flowmoco-s3-backup-test +SQL backup uploaded successfully" + +if [ "$OUT" != "$EXPECTED" ]; then + echo "Output '$OUT' does not equal expected '$EXPECTED'" + exit 1 +fi + # apt-get update && apt-get install -y wget # wget "https://sample-videos.com/sql/Sample-SQL-File-10rows.sql" diff --git a/postgres-backup-s3/integration-tests.test.yml b/postgres-backup-s3/integration-tests.test.yml index 841454a..727e4ca 100644 --- a/postgres-backup-s3/integration-tests.test.yml +++ b/postgres-backup-s3/integration-tests.test.yml @@ -9,7 +9,17 @@ services: sut: build: . command: 'sh integration-tests.sh' - environment: - - PGPASSWORD=12345 depends_on: - postgres + environment: + PGPASSWORD: 12345 + S3_REGION: "eu-west-2" + S3_ACCESS_KEY_ID: "AKIASAH3OBJUZI7R3KIM" + S3_SECRET_ACCESS_KEY: "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" + S3_BUCKET: flowmoco-s3-backup-test + S3_PREFIX: "postgres-test" + POSTGRES_HOST: postgres + POSTGRES_DATABASE: user + POSTGRES_USER: user + POSTGRES_PASSWORD: 12345 + POSTGRES_EXTRA_OPTS: '--schema=public --blobs'