Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion example-playbooks/restore_scylla_manager_backup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ It requires Scylla Manager 2.4 or newer.
1. New cluster with the same number of nodes as the source cluster.
1. Scylla Manager Agent installed on all the nodes.
1. Access to the backup location from all the nodes.
1. New cluster is registered in ScyllaDB Manager.


## Parameters

Expand Down Expand Up @@ -62,7 +64,8 @@ The snapshot ID must be put into `snapshot_tag` variable in `vars.yaml` file.

## Inventory

Put public IP addresses of all nodes to `hosts` file.
Put public IP addresses of all nodes to scylla_hosts section in `hosts` file.
Put public IP addresses of Scylla Manager host to scylla_manager section in `hosts` file.

## Running

Expand Down
4 changes: 4 additions & 0 deletions example-playbooks/restore_scylla_manager_backup/hosts.example
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
Expand Down
65 changes: 32 additions & 33 deletions example-playbooks/restore_scylla_manager_backup/restore.yaml
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:
Expand Down Expand Up @@ -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
Copy link
Collaborator

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-agent because its API has change apparently.

The patch description should be adjusted accordingly.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added description

become_user: scylla
register: _tables_list
vars:
ansible_pipelining: true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is pipelining needed?
According to Ansible documentation using pipelining conflicts with a privilege escalation (become) which you use in this task.

Copy link
Author

Choose a reason for hiding this comment

The 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).

Copy link
Collaborator

Choose a reason for hiding this comment

The 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 }}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about audit keyspace?

Copy link
Author

@kendrick-ren kendrick-ren Oct 21, 2025

Choose a reason for hiding this comment

The 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
hosts: all
hosts: scylla_hosts
become: true
gather_facts: false
tags:
Expand Down Expand Up @@ -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
Expand All @@ -127,9 +133,8 @@
port: 9042
host: "{{ listen_address }}"


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleanups should be part of a separate commit.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, isolated the cleanups related change to a separate commit.

Copy link
Collaborator

Choose a reason for hiding this comment

The 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:
Expand All @@ -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
10 changes: 10 additions & 0 deletions example-playbooks/restore_scylla_manager_backup/vars.yaml.example
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
# Cluster name to restore schema to. This is the name of the target cluster which
# is registered in ScyllaDB Manager
#
scylla_manager_cluster_name: <target_cluster_name_registered_in_scylla_manager>

# backup_location specifies the location parameter used in Scylla Manager
# when scheduling a backup of a cluster.
backup_location: s3:manager-test-demo1

# snapshot_tag specifies the Scylla Manager snapshot tag you want to restore.
snapshot_tag: sm_20210422133609UTC

# data_dir is the path to dump sstables during scylla-manager-agent download-files
#
data_dir: <scylla_data_dir, e.g. /var/lib/scylla/data/>

# host_id specifies a mapping from the clone cluster node IP to the source
# cluster host IDs.
host_id:
Expand All @@ -14,3 +23,4 @@ host_id:
3.125.251.43: 82f0f486-370d-4cfd-90ac-46464c8012cb
3.66.176.252: 9ee92c19-5f78-4865-a287-980218963d96
3.66.25.100: aff05f79-7c69-4ecf-a827-5ea790a0fdc6