github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/tests/tiup/upgrade-from-v1.sh (about)

     1  #!/bin/bash
     2  
     3  set -eu
     4  
     5  CLUSTER_NAME="dm-v1"
     6  DM_V2_VER="nightly"
     7  
     8  CUR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
     9  PATH=$CUR/../_utils:$PATH # for sync_diff_inspector
    10  
    11  source $CUR/lib.sh
    12  
    13  # ref https://docs.pingcap.com/zh/tidb-data-migration/stable/deploy-a-dm-cluster-using-ansible
    14  # script following the docs to deploy dm 1.0.7 using ./ansible_data/inventory.ini
    15  function deploy_v1_by_ansible() {
    16  	# step 1
    17  	apt-get update --allow-releaseinfo-change
    18  	apt-get -y install git curl sshpass python-pip sudo
    19  
    20  	# step 2
    21  	useradd -m -d /home/tidb tidb
    22  	echo "tidb:tidb" | chpasswd
    23  	echo "tidb ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers
    24  
    25  	# use the same key from root instead of create one.
    26  	mkdir -p /home/tidb/.ssh
    27  	cp ~/.ssh/* /home/tidb/.ssh/
    28  	chown -R tidb:tidb /home/tidb/.ssh/
    29  
    30  	# step 3
    31  	su tidb <<EOF
    32      cd /home/tidb
    33      wget https://download.pingcap.org/dm-ansible-v1.0.7.tar.gz
    34  EOF
    35  
    36  	# step 4
    37  	su tidb <<EOF
    38      cd /home/tidb
    39      tar -xzvf dm-ansible-v1.0.7.tar.gz &&
    40          mv dm-ansible-v1.0.7 dm-ansible &&
    41          cd /home/tidb/dm-ansible &&
    42          sudo pip install -r ./requirements.txt
    43      ansible --version
    44  EOF
    45  
    46  	# step 5
    47  	cp $CUR/ansible_data/hosts.ini /home/tidb/dm-ansible/
    48  	cp $CUR/ansible_data/inventory.ini /home/tidb/dm-ansible/
    49  
    50  	# not following the docs, use root and without password to run it
    51  	cd /home/tidb/dm-ansible
    52  	sudo ansible-playbook -i hosts.ini create_users.yml -u root
    53  	cd $CUR/../..
    54  
    55  	#step 6
    56  	su tidb <<EOF
    57      cd /home/tidb/dm-ansible
    58      ansible-playbook local_prepare.yml
    59  EOF
    60  
    61  	# skip 7,8
    62  
    63  	# step 9
    64  	su tidb <<EOF
    65      cd /home/tidb/dm-ansible
    66      ansible -i inventory.ini all -m shell -a 'whoami'
    67      ansible -i inventory.ini all -m shell -a 'whoami' -b
    68      ansible-playbook deploy.yml
    69      ansible-playbook start.yml
    70  EOF
    71  
    72  }
    73  
    74  function stop_v1_by_ansible() {
    75  	su tidb <<EOF
    76      cd /home/tidb/dm-ansible
    77      ansible-playbook stop.yml
    78  EOF
    79  }
    80  
    81  function migrate_in_v1 {
    82  	exec_full_stage
    83  
    84  	# start v1 task
    85  	/home/tidb/dm-ansible/dmctl/dmctl --master-addr=master1:8261 start-task $CUR/conf/task.yaml
    86  
    87  	exec_incremental_stage1
    88  
    89  	check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml
    90  }
    91  
    92  # ref https://docs.pingcap.com/zh/tidb-data-migration/v2.0/deploy-a-dm-cluster-using-tiup
    93  function import_to_v2_by_tiup() {
    94  	# install TiUP-DM
    95  	curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
    96  	source /root/.profile
    97  	tiup install dm
    98  
    99  	# import from v1
   100  	# TODO: update `--cluster-version` to the target version later.
   101  	tiup install dmctl:$DM_V2_VER
   102  	tiup dm import --yes --dir=/home/tidb/dm-ansible --cluster-version $DM_V2_VER
   103  	tiup dm start --yes $CLUSTER_NAME
   104  }
   105  
   106  function migrate_in_v2 {
   107  	exec_incremental_stage2
   108  
   109  	echo "check sources"
   110  	run_dmctl_with_retry $DM_V2_VER "operate-source show" "mysql-replica-01" 1 "mariadb-replica-02" 1
   111  	echo "check workers"
   112  	run_dmctl_with_retry $DM_V2_VER "list-member --worker" "\"stage\": \"bound\"" 2
   113  
   114  	check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml
   115  
   116  	# stop v2 task
   117  	tiup dmctl:$DM_V2_VER --master-addr=master1:8261 stop-task $TASK_NAME
   118  }
   119  
   120  function destroy_v2_by_tiup() {
   121  	tiup dm destroy --yes $CLUSTER_NAME
   122  }
   123  
   124  function test() {
   125  	install_sync_diff
   126  
   127  	deploy_v1_by_ansible
   128  
   129  	migrate_in_v1
   130  
   131  	stop_v1_by_ansible
   132  
   133  	import_to_v2_by_tiup
   134  
   135  	migrate_in_v2
   136  
   137  	destroy_v2_by_tiup
   138  }
   139  
   140  test