diff --git a/backup-docker-to-local.py b/backup-docker-to-local.py index 5ba55e1..fa051f8 100644 --- a/backup-docker-to-local.py +++ b/backup-docker-to-local.py @@ -66,7 +66,22 @@ BACKUP_TIME = datetime.now().strftime("%Y%m%d%H%M%S") VERSION_DIR = create_version_directory() def get_instance(container): + # The function is defined to take one parameter, 'container', + # which is expected to be a string. + + # This line uses regular expressions to split the 'container' string. + # 're.split' is a method that divides a string into a list, based on the occurrences of a pattern. instance_name = re.split("(_|-)(database|db|postgres)", container)[0] + # The pattern "(_|-)(database|db|postgres)" is explained as follows: + # - "(_|-)": Matches an underscore '_' or a hyphen '-'. + # - "(database|db|postgres)": Matches one of the strings "database", "db", or "postgres". + # So, this pattern will match segments like "_database", "-db", "_postgres", etc. + # For example, in "central-db", it matches "-db". + + # After splitting, [0] is used to select the first element of the list resulting from the split. + # This element is the string portion before the matched pattern. + # For "central-db", the split results in ["central", "db"], and [0] selects "central". + print(f"Extracted instance name: {instance_name}") return instance_name