-
Notifications
You must be signed in to change notification settings - Fork 43
Exclude system tables and only restore user's schema #486
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| [scylla_manager] | ||
| 3.65.230.31 | ||
|
|
||
| [scylla_hosts] | ||
| 3.65.230.34 | ||
| 3.66.75.209 | ||
| 3.65.102.133 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| --- | ||
|
|
||
| - name: Gather important facts about Scylla nodes and a snapshot | ||
| hosts: all | ||
| hosts: scylla_hosts | ||
| become: true | ||
| gather_facts: false | ||
| tags: | ||
|
|
@@ -31,21 +31,27 @@ | |
|
|
||
| - name: Get names of the tables in the snapshot {{ snapshot_tag }} | ||
| shell: | | ||
| scylla-manager-agent download-files -L {{ backup_location }} -n {{ host_id[inventory_hostname] }} -T {{ snapshot_tag }} -d /var/lib/scylla/data/ --dry-run | grep "^\s*\-" | cut -d"-" -f2 | cut -d"(" -f1 | ||
| scylla-manager-agent download-files -L {{ backup_location }} -n {{ host_id[inventory_hostname] }} -T {{ snapshot_tag }} --dump-manifest | ||
| become_user: scylla | ||
| register: _tables_list | ||
| vars: | ||
| ansible_pipelining: true | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is pipelining needed?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is to avoid Ansible to write a temp file under a temp directory for the step, while it only conflicts when "become" is used along with requiretty enabled (which is usually disabled for Ansible automation on systems).
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we care if Ansible is going to write a temp file? |
||
| register: _manifest_output | ||
|
|
||
| - name: Save tables names list as a fact | ||
| - name: Parse table names from manifest | ||
| set_fact: | ||
| tables_to_restore: "{{ _tables_list.stdout.split('\n') }}" | ||
| _tables_list: | ||
| stdout_lines: "{{ (_manifest_output.stdout | from_json).index | map(attribute='keyspace') | zip((_manifest_output.stdout | from_json).index | map(attribute='table')) | map('join', '.') | list }}" | ||
|
|
||
| - name: Save system_schema tables names as a fact | ||
| - name: Save tables names list as a fact | ||
| set_fact: | ||
| system_schema_tables: "{{ tables_to_restore | select('search', '^\\s*system_schema\\.') | list }}" | ||
| all_tables: "{{ _tables_list.stdout_lines }}" | ||
|
|
||
| - name: Save names of tables to restore as a fact | ||
| set_fact: | ||
| tables_to_restore: "{{ all_tables | reject('search', '^system(_|\\.)') | list }}" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. audit keyspace is also kept here, this variable is only used in node refresh step. In the steps later, audit keyspace table content is also restored. |
||
|
|
||
| - name: Restore a token ring - cluster's data is going to be wiped | ||
vladzcloudius marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| hosts: all | ||
| hosts: scylla_hosts | ||
| become: true | ||
| gather_facts: false | ||
| tags: | ||
|
|
@@ -110,7 +116,7 @@ | |
| when: inventory_hostname != groups.all[0] | ||
|
|
||
| - name: Start all nodes serially | ||
| hosts: all | ||
| hosts: scylla_hosts | ||
| become: true | ||
| gather_facts: false | ||
| serial: 1 | ||
|
|
@@ -127,9 +133,8 @@ | |
| port: 9042 | ||
| host: "{{ listen_address }}" | ||
|
|
||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cleanups should be part of a separate commit.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay, isolated the cleanups related change to a separate commit.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still see it in the first commit. |
||
| - name: Cleanup - restore the original cluster's configuration | ||
| hosts: all | ||
| hosts: scylla_hosts | ||
| become: true | ||
| gather_facts: false | ||
| tags: | ||
|
|
@@ -149,38 +154,32 @@ | |
| \g<1> - seeds: {{ old_seeds }} | ||
| backrefs: yes | ||
|
|
||
| - name: Restore schema from a backup snapshot {{ snapshot_tag }} | ||
| hosts: scylla_manager | ||
| become: true | ||
| gather_facts: false | ||
| tags: | ||
| - restore_schema_from_backup | ||
| tasks: | ||
| - name: Run sctool restore command to restore schema only | ||
| ansible.builtin.command: | ||
| cmd: "sctool restore --cluster {{ scylla_manager_cluster_name }} -L {{ backup_location }} --snapshot-tag {{ snapshot_tag }} --restore-schema" | ||
|
|
||
| - name: Upload data from a backup snapshot {{ snapshot_tag }} | ||
| hosts: all | ||
| hosts: scylla_hosts | ||
| become: true | ||
| gather_facts: false | ||
| tags: | ||
| - upload_snapshot | ||
| tasks: | ||
| - name: Download data from {{ snapshot_tag }} | ||
| - name: Download data | ||
| shell: | | ||
| scylla-manager-agent download-files -L {{ backup_location }} -n {{ host_id[inventory_hostname] }} -T {{ snapshot_tag }} -d /var/lib/scylla/data/ --mode upload | ||
| scylla-manager-agent download-files -L {{ backup_location }} -n {{ host_id[inventory_hostname] }} -T {{ snapshot_tag }} -d {{ data_dir }} -K '*,!system_*,!!system.*' --mode upload | ||
| become_user: scylla | ||
| async: 604800 # a week 7*24*60*60 seconds | ||
| async: 604800 | ||
| poll: 5 | ||
|
|
||
| - name: Load system_schema tables data from the upload directory | ||
| shell: | | ||
| nodetool refresh {{ item.split('.') | join(' ') }} | ||
| with_items: "{{ system_schema_tables }}" | ||
|
|
||
| - name: Restart Scylla service to force a new schema to be picked up | ||
| service: | ||
| name: scylla-server | ||
| state: restarted | ||
|
|
||
| - name: Wait for CQL port | ||
| wait_for: | ||
| port: 9042 | ||
| host: "{{ listen_address }}" | ||
|
|
||
| - name: Load the rest of tables data from the upload directory | ||
| - name: refresh nodes with the restored data | ||
| shell: | | ||
| nodetool refresh {{ item.split('.') | join(' ') }} | ||
| nodetool refresh {{ item.split('.') | join(' ') }} | ||
| with_items: "{{ tables_to_restore }}" | ||
| when: item not in system_schema_tables | ||
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.
This (first) commit does a lot more than changes just the way schema is restored.
It refactors all places that use
scylla-manager-agentbecause its API has change apparently.The patch description should be adjusted accordingly.
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.
Added description