How to migrate LabCollector to new Linux Server? - LabCollector

Search Knowledge Base by Keyword

How to migrate LabCollector to new Linux Server?

You are here:
← All Topics
SUMMARY:
You can now easily migrate the LabCollector data from old Linux server to new Linux server. 

In order to migrate the database, there could be 4 scenario where you need to backup and migrate data to the new server:

Scenario 1: Backup of all data from LabCollector

Scenario 2: If you want to dump a single table from a database

Scenario 3: If you want to dump a large database

Scenario 4: If you have a remote new LINUX server

You will have to follow the below steps for the migration of LabCollector database to new server.

Step A: MySQL Dump
Step B: Transfer MySQL Databases Dump File to New Server
Step C: Import/ Restore the Database

Note
  • Make sure to have the same version of MySQL installed on both servers
  • Make sure to have enough free space on both servers to hold the database dump file and the imported

Step A: MySQL Dump

Scenario 1: Backup of all data from LabCollector

  • You first need to create a backup of your old server before to transfer it to the new server.
  • Start by login into your old server
  • Dump your MySQL databases to a single file using the mysqldump command
# mysqldump -u username -p password database_name  > [dump_file.sql]
  • The parameters of the above command are explained below:
  1. [username] : A valid MySQL login username
  2. [password] : A valid MySQL password for the user.
  3. [database_name] : A valid Database name you want to take
  4. [dump_file.sql] : The name of the backup dump file you want to

Scenario 2: Dump a single table from database 

  • You can use the below command:
# mysqldump -u username -p password database_name table_name > [single_table_dump.sql]

Scenario 3: Dump a large database

  • When the mySQL server gets a packet that is larger than the max_allowed_packet bytes, it issues a “Packet too large” error and closes the connection.
  • You must increase this value for large messages, for this add option to the dump command : Note: Notice that the size defined here is only an example
# mysqldump -u username -p password database_name --max_allowed_packet=1024M > [dump_file.sql]

Scenario 4: If you have a remote new LINUX server

  •  If you have Remote MySQL Database, you can use:
# mysqldump --host hostaddress -u username -p password database_name > [dump_file.sql]

Step B: Transfer MySQL Databases Dump File to New Server

(For Scenario 1 & 3)

  • Once the dump is completed, you are ready to transfer the databases.
  • Now use scp command to transfer your database dump file to the new server. If you used the previous command (Scenario 1), you exported your database to your home folder.
# scp [database_name].sql [username]@[servername]:path/to/database/
  • You can also use equivalent queries to scp wit rsync
    Note: that user can use any other method he prefer (or find adapted) to upload its file to the new server.
#rsync -P --rsh=ssh path/to/dump_file.sql username@servername:path/to/database/

(For Scenario 2)

  • For copying only the table to new server, just replace the database name with table name:
# scp [table_name].sql [username]@[servername]:path/to/database/
  • You can also use equivalent queries to scp wit rsync.
    Note: that user can use any other method he prefer (or find adapted) to upload its file to the new server.
#rsync -P --rsh=ssh path/to/single_table_dump.sql username@servername:path/to/database/

Step C: Import/ Restore the Database

 (For Scenario 1 & 3)

  • Once the data has been transferred to the new server, you can import the database into MySQL
# mysql -u [user] -p [newdatabase] < [/path/to/newdatabase.sql]

(For Scenario 2)

  • For restoring only the table to new server, just replace the database name with table name
  # mysql -u [user] -p [newtable < /path/to/newdatabase.sql]

(For Scenario 4)

  • Restore DB on remote Server
mysql -h [hostname] -u [user] -p [databasename] < [dump_file.sql]
Note:
Once the import is completed, you can verify the databases on both servers using the following command on the mysql shell.
# mysql -u [user] -p # show databases;

Related topics: