Skip to content
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

Add new parameter to allow overriding the fqdn for new cluster #310

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
23 changes: 17 additions & 6 deletions medusa/restore_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@


def restore_node(config, temp_dir, backup_name, in_place, keep_auth, seeds, verify, keyspaces, tables,
use_sstableloader=False):
use_sstableloader=False, backup_fqdn=None):

if in_place and keep_auth:
logging.error('Cannot keep system_auth when restoring in-place. It would be overwritten')
Expand All @@ -47,7 +47,7 @@ def restore_node(config, temp_dir, backup_name, in_place, keep_auth, seeds, veri

if not use_sstableloader:
restore_node_locally(config, temp_dir, backup_name, in_place, keep_auth, seeds, storage,
keyspaces, tables)
keyspaces, tables, backup_fqdn)
else:
restore_node_sstableloader(config, temp_dir, backup_name, in_place, keep_auth, seeds, storage,
keyspaces, tables)
Expand All @@ -57,13 +57,17 @@ def restore_node(config, temp_dir, backup_name, in_place, keep_auth, seeds, veri
verify_restore([hostname_resolver.resolve_fqdn()], config)


def restore_node_locally(config, temp_dir, backup_name, in_place, keep_auth, seeds, storage, keyspaces, tables):
def get_node_backup(config, storage, backup_name, backup_fqdn):
storage.storage_driver.prepare_download()
differential_blob = storage.storage_driver.get_blob(
os.path.join(config.storage.fqdn, backup_name, 'meta', 'differential'))

fqdn = config.storage.fqdn
if backup_fqdn is not None:
fqdn = backup_fqdn

node_backup = storage.get_node_backup(
fqdn=config.storage.fqdn,
fqdn=fqdn,
name=backup_name,
differential_mode=True if differential_blob is not None else False
)
Expand All @@ -72,6 +76,13 @@ def restore_node_locally(config, temp_dir, backup_name, in_place, keep_auth, see
logging.error('No such backup')
sys.exit(1)

return node_backup


def restore_node_locally(config, temp_dir, backup_name, in_place, keep_auth, seeds, storage, keyspaces, tables,
backup_fqdn=None):
node_backup = get_node_backup(config, storage, backup_name, backup_fqdn)

fqtns_to_restore, ignored_fqtns = filter_fqtns(keyspaces, tables, node_backup.manifest)
for fqtns in ignored_fqtns:
logging.info('Skipping restore of {}'.format(fqtns))
Expand All @@ -80,13 +91,13 @@ def restore_node_locally(config, temp_dir, backup_name, in_place, keep_auth, see
logging.error('There is nothing to restore')
sys.exit(0)

cassandra = Cassandra(config)

# Download the backup
download_dir = temp_dir / 'medusa-restore-{}'.format(uuid.uuid4())
logging.info('Downloading data from backup to {}'.format(download_dir))
download_data(config.storage, node_backup, fqtns_to_restore, destination=download_dir)

cassandra = Cassandra(config)

if not medusa.utils.evaluate_boolean(config.kubernetes.enabled):
logging.info('Stopping Cassandra')
cassandra.shutdown()
Expand Down
6 changes: 5 additions & 1 deletion medusa/service/grpc/restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def configure_console_logging(config):
configure_console_logging(config.logging)

backup_name = os.environ["BACKUP_NAME"]
override_fqdn = os.environ["BACKUP_FQDN"]
tmp_dir = Path("/tmp")
in_place = True
keep_auth = False
Expand All @@ -65,9 +66,12 @@ def configure_console_logging(config):
tables = {}
use_sstableloader = False

if override_fqdn is not None and len(override_fqdn) == 0:
override_fqdn = None

logging.info("Starting restore of backup {}".format(backup_name))

medusa.restore_node.restore_node(config, tmp_dir, backup_name, in_place, keep_auth, seeds, verify, keyspaces, tables,
use_sstableloader)
use_sstableloader, override_fqdn)

logging.info("Finished restore of backup {}".format(backup_name))