Skip to content
Merged
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
37 changes: 31 additions & 6 deletions migration-tools/tts-backup-python/tts-backup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/python3
#
import os
import sys
import json
Expand All @@ -21,6 +19,7 @@
import getpass
import functools
from datetime import datetime
import re


print = functools.partial(print, flush=True)
Expand Down Expand Up @@ -105,6 +104,14 @@ def split_into_lines(items, to_upper=True, chunk_size=10):
item_list = ",\n".join(chunks)
return item_list

# Escape '$' in table names for shell safety (TABLE$1 --> TABLE\$1)
def escape_dollar(raw):
tables = []
for tbl in raw.split(','):
tbl = re.sub(r'(?<!\\)\$', r'\$', tbl.strip())
tables.append(tbl)
return ",".join(tables)

class ConsoleLogger:
"""
A class to send Python output simultaneously to the terminal and a log file.
Expand Down Expand Up @@ -281,6 +288,8 @@ def _load_env_variables(self):
value = self._defaults.get(var, '').strip()
if value and (var == 'TABLESPACES' or var == 'SCHEMAS'):
value = value.replace(" ", "")
if value and (var == 'EXCLUDE_TABLES'):
value = escape_dollar(value)
setattr(self, var, value)

if getattr(self, 'ZDM_BASED_TRANSPORT').strip():
Expand Down Expand Up @@ -642,10 +651,18 @@ def _get_schemas(self, template, user_type=None):
sql_script = template.get('get_common_schemas')
elif user_type == "required":
ts_list = split_into_lines(self._env.TABLESPACES)
if self._env.DB_VERSION == '11g':
l_user_list_clause = "username not in ('SYS','SYSTEM')"
else:
l_user_list_clause = "username not in ('SYS','SYSTEM') and common='NO'"
Configuration.substitutions = {
'ts_list': ts_list.upper(),
'l_user_list_clause': l_user_list_clause,
}
sql_script = template.get('owners_in_tablespaces')
if not self._env.SCHEMAS:
sql_script = template.get('owners_and_grantee_in_tablespaces')
else:
sql_script = template.get('owners_in_tablespaces')
else:
if not self._env.SCHEMAS:
print("No schemas provided. Returning a list of required users.")
Expand Down Expand Up @@ -1273,7 +1290,8 @@ def tts_src_export_tde_keys(self, template):
}

try:
if not sqlplus.run_sql(template.get('tts_src_export_tde_keys')) or not os.path.exists(tde_keys_path):
# if not sqlplus.run_sql(template.get('tts_src_export_tde_keys')) or not os.path.exists(tde_keys_path):
if not sqlplus.run_sql(template.get('tts_src_export_tde_keys')):
print("Export TDE Keys failed. \n")
raise RuntimeError("TDE key export command failed.")
print(f"TDE keys exported successfully to {tde_keys_path}.")
Expand Down Expand Up @@ -1458,9 +1476,13 @@ def tts_src_get_channel(self):
self.host_array = self._env.DB_PROPS_ARRAY[13].split(';')
self._env.CPU_COUNT = self.calculate_cpu_count()

if not self._env.DB_PROPS_ARRAY[13]:
print("Invalid DATABASE_NAME {0} or the PDB is not open in READ WRITE mode in any instance. Exiting...".format(self._env.DATABASE_NAME))
sys.exit(1)

if not self.host_array or self._env.CPU_COUNT <= 0:
print("No instances or CPUs to construct channel string. Exiting...")
return False
sys.exit(1)

rman_parms = ""
if self._env.STORAGE_TYPE == "FSS":
Expand Down Expand Up @@ -1581,6 +1603,9 @@ def tts_src_backup_tablespaces(self, backup_type, template):
if self._env.DB_VERSION != '11g':
allow_inconsistent = "allow inconsistent"

# Remove DATAPUMP Clause from rman restore
tablespace_dump_clause = ""

# 11g -> for transport not supported, add section size clause
# 12c/19c :
# if src_platform = 13 : no need of for transport, add section size clause
Expand Down Expand Up @@ -2110,7 +2135,7 @@ def main(args):
exit(1)
log_end_time(start_time)

_env.platform_id = int(_env.DB_PROPS_ARRAY[4])
_env.platform_id = int(_env.DB_PROPS_ARRAY[3])
_env.version_full = _env.DB_PROPS_ARRAY[9]
_env.bigfile_tablespaces = _env.DB_PROPS_ARRAY[15].replace(';', ',')
_env.smallfile_tablespaces = _env.DB_PROPS_ARRAY[16].replace(';', ',')
Expand Down
12 changes: 12 additions & 0 deletions migration-tools/tts-backup-python/ttsTemplate.txt
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,18 @@ get_local_schemas:
owners_in_tablespaces:
select distinct owner from dba_tables where tablespace_name in (${ts_list});

owners_and_grantee_in_tablespaces:
select distinct username from (
select owner as username from dba_tables where tablespace_name in (${ts_list})
union
select grantee as username from dba_tab_privs
where owner in (
select owner from dba_tables where tablespace_name in (${ts_list})
) and grantee in (
select username from dba_users where ${l_user_list_clause}
)
);

object_validation:
-- SEGMENTS : Physical Segments (tables, indexes, lobs, partitions etc.)
SELECT 'SEGMENT,' || owner || '.' || segment_name
Expand Down
8 changes: 7 additions & 1 deletion migration-tools/tts-backup-python/version.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
26.2.1.2 - 05 February 2005
26.2.3.2 - 20 February 2026
+ Escape '$' in table names (EXCLUDE_TABLES) e.g. TABLE$1 --> TABLE\$1
+ Add users to schema list those have obj grants on tbs list if schema list not provided
- remove tde keys file check to avoid platform dependency issues
+ Improve error messages incase of invalid user input for DATABASE_NAME

26.2.1.2 - 05 February 2026
+ Added support to query the TTS Backup Utility version
+ Updated RMAN and Data Pump job names to include the project name
+ Added validation to ensure the tablespace list remains unaltered across backups
Expand Down