migrate.sh
migrate.sh - Overview
This script automates the migration of data from bind mounts to Docker volumes for SigNoz components like ClickHouse, Zookeeper, SigNoz SQLite, and Alertmanager. It supports both standalone and Docker Swarm deployments. It also includes a post-migration cleanup operation.
Detailed Documentation
Global Variables
NAME
: The name of the script, "volume-migration".DOCKER_COMPOSE_DIR
: Directory containing docker compose files for standalone deployments, "deploy/docker".DOCKER_SWARM_COMPOSE_DIR
: Directory containing docker compose files for swarm deployments, "deploy/docker-swarm".STANDALONE_DATA_DIR
: Data directory for standalone deployments, "deploy/docker/clickhouse-setup/data".SWARM_DATA_DIR
: Data directory for swarm deployments, "deploy/docker-swarm/clickhouse-setup/data".SIGNOZ_NETWORK
: Docker network name, "signoz-net".SIGNOZ_NETWORK_OLD
: Old Docker network name, "clickhouse-setup_default".SCRIPT_PATH
: Full path to the script.BASE_DIR
: Directory containing the script.DOCKER_COMPOSE_CMD
: Docker compose command (determined dynamically).DEPLOYMENT_TYPE
: Deployment type (standalone or swarm).MIGRATION_COMPONENT
: Component to migrate (all, clickhouse, zookeeper, signoz, alertmanager).OPERATION
: Operation to perform (migrate or post-migrate).SIGNOZ_ROOT_DIR
: Root directory of SigNoz installation.SILENT
: Flag to enable/disable silent mode.
Function: help
- Purpose: Prints a help message describing script usage and options.
- Parameters: None
- Returns: None (prints to stdout)
Function: print
- Purpose: Prints a message to stdout, only if silent mode is disabled.
- Parameters:
Message
: The message to print.
- Returns: None (prints to stdout)
Function: err
- Purpose: Prints an error message to stderr.
- Parameters:
Error message
: The error message to print.
- Returns: None (prints to stderr)
Function: docker_check
- Purpose: Checks if Docker is installed and available.
- Parameters: None
- Returns: None (exits if Docker is not found)
Function: docker_compose_cmd
- Purpose: Determines the correct Docker Compose command to use (
docker compose
ordocker-compose
). - Parameters: None
- Returns: The Docker Compose command (string).
Function: start_services
- Purpose: Starts SigNoz services using Docker Compose, based on the deployment type.
- Parameters:
deployment_type
: The deployment type (standalone or swarm).signoz_root_dir
: The root directory of the SigNoz installation.
- Returns: None
Function: docker_network_check
- Purpose: Checks if a Docker network exists.
- Parameters:
network
: The name of the Docker network to check.
- Returns:
- 0 if network exists
- 1 if network does not exist
Function: cleanup_standalone
- Purpose: Stops and removes containers and networks associated with standalone deployment.
- Parameters:
compose_dir
: Path to the compose directory.
- Returns: None
Function: cleanup_swarm
- Purpose: Stops and removes the SigNoz stack in a Docker Swarm deployment.
- Parameters:
compose_dir
: Path to the compose directory.
- Returns: None
Function: stop_services
- Purpose: Stops SigNoz services based on the deployment type.
- Parameters:
deployment_type
: The deployment type (standalone or swarm).signoz_root_dir
: The root directory of the SigNoz installation.
- Returns: None
Function: get_compose_dir
- Purpose: Determines the Docker Compose directory based on the deployment type.
- Parameters:
deployment_type
: The deployment type (standalone or swarm).signoz_root_dir
: The root directory of the SigNoz installation.
- Returns: The path to the Docker Compose directory (string).
Function: get_data_dir
- Purpose: Determines the data directory based on the deployment type.
- Parameters:
deployment_type
: The deployment type (standalone or swarm).signoz_root_dir
: The root directory of the SigNoz installation.
- Returns: The path to the data directory (string).
Function: migrate_clickhouse
- Purpose: Migrates ClickHouse data from bind mounts to Docker volumes.
- Parameters:
data_dir
: The data directory.
- Returns: None
Function: migrate_zookeeper
- Purpose: Migrates Zookeeper data from bind mounts to Docker volumes.
- Parameters:
data_dir
: The data directory.
- Returns: None
Function: migrate_signoz
- Purpose: Migrates SigNoz SQLite data from bind mounts to Docker volumes.
- Parameters:
data_dir
: The data directory.
- Returns: None
Function: migrate_alertmanager
- Purpose: Migrates Alertmanager data from bind mounts to Docker volumes.
- Parameters:
data_dir
: The data directory.
- Returns: None
Function: post_migrate_clickhouse
- Purpose: Performs post-migration cleanup for ClickHouse data.
- Parameters:
data_dir
: The data directory.
- Returns: None
Function: post_migrate_zookeeper
- Purpose: Performs post-migration cleanup for Zookeeper data.
- Parameters:
data_dir
: The data directory.
- Returns: None
Function: post_migrate_signoz
- Purpose: Performs post-migration cleanup for SigNoz data.
- Parameters:
data_dir
: The data directory.
- Returns: None
Function: post_migrate_alertmanager
- Purpose: Performs post-migration cleanup for Alertmanager data.
- Parameters:
data_dir
: The data directory.
- Returns: None
Function: migrate
- Purpose: Migrates data from a bind mount to a Docker volume.
- Parameters:
migration_component
: The name of the component being migrated.bind_mounts
: The path to the bind mount directory.new_volume
: The name of the Docker volume to create and migrate data to.owner_uidgid
: The owner user and group id for the volume (e.g., "101:101").
- Returns: None
Function: post_migrate
- Purpose: Performs post-migration cleanup by removing data from the original bind mount.
- Parameters:
migration_component
: The name of the component being migrated.data_dir
: The path to the data directory (original bind mount).
- Returns: None
Function: run_migration
- Purpose: Executes the data migration process for the specified component.
- Parameters:
deployment_type
: The deployment type (standalone or swarm).migration_component
: The component to migrate (all, clickhouse, zookeeper, signoz, alertmanager).signoz_root_dir
: The root directory of the SigNoz installation.
- Returns: None
Function: run_post_migration
- Purpose: Executes the post-migration cleanup for the specified component.
- Parameters:
deployment_type
: The deployment type (standalone or swarm).migration_component
: The component to cleanup (all, clickhouse, zookeeper, signoz, alertmanager).signoz_root_dir
: The root directory of the SigNoz installation.
- Returns: None
Function: parse_args
- Purpose: Parses command line arguments.
- Parameters: None
- Returns:
- 0 on success
- Non-zero on failure
Function: main
- Purpose: Main function to execute the migration script.
- Parameters: None (uses command-line arguments)
- Returns: None
Code Examples
None needed.
Include in Getting Started: NO