-
Notifications
You must be signed in to change notification settings - Fork 0
postgres: add support for restoring backups #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
c6588f6
to
9e0efb0
Compare
@@ -96,8 +104,28 @@ jobs: | |||
|
|||
- name: Run the playbook | |||
run: | | |||
read -r -d '' extra_vars << 'EOF' || true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dark magic. 🪄 Apparently this is a shell builtin, and in fish
it's different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah... I was just struggling to find a different way how to pass that many variables to ansible w/o creating a temporary YAML file :( We could do that instead to make this portable across different shells.
register: existing_tables | ||
|
||
- name: Copy and restore a database backup | ||
when: existing_tables.rowcount == 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this to prevent restoration when the database is not empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct! Let me add a comment.
- name: Check if we need to restore a database backup | ||
community.postgresql.postgresql_query: | ||
db: "{{ item.database }}" | ||
query: "SELECT * FROM pg_catalog.pg_tables WHERE tableowner = %s" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the user we have owns multiple databases? Is there any way to check if there are any tables in the database instead of checking owned tables number across the server?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, it's grand: pg_catalog.pg_tables
is a magical system view that exists in all databases, and all the information is local to a particular database.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... and we connect to the database above.
Only the "custom" format of pg_restore is supported, and the backup file must be located on the host where the ansible playbook is executed. The intended use cases are: * Migrating to new PostgreSQL/Ubuntu versions in production (the former notoriously requires downtime and either restoring a database backup, or running the migration tool to update the storage format offline). * Testing of database backups that we create today.
d2e207a
to
3534b63
Compare
Only the "custom" format of pg_restore is supported, and the backup file must be located on the host where the ansible playbook is executed.
The intended use cases are: