Skip to content

How to backup Mysql via SSH tunnel

Setting up an SSH Tunnel

To begin, we need to create an SSH tunnel between the two networks. This can be done using the following command:

ssh -L 3306:10.10.100.22:3306 -p 22 [email protected] -i id_rsa

This command maps the local port 3306 to the database server’s IP address (10.10.100.22) and port 3306 in the target network.

Data Synchronization

Next, we can start the data synchronization process using the following command:

mysqldump -u root -h 10.10.1.22 --port 3306 \
    --databases db1 db2 \
    --compress \
    --single-transaction \
    --order-by-primary  \
    -ppassword | mysql -u root \
        --port=3306 \
        --host=127.0.0.1 \
        -ppassword

Reference

  • https://www.bboy.app/2023/12/25/introduce-an-operation-for-backing-up-a-database/
Feedback