It can be useful for some reasons (for instance when moving to an older 1.0.x version to a newer 1.1.x version) to manually migrate / copy the data from one database to the other. To do so only a few command lines are required.
Dumping the older database content
First connect to the older instance database container:
docker exec -it samdatabase_1.0.10 /bin/sh
Don’t forget to adapt the container name (samdatabase_1.0.10 here) to your actual setup.
Then dump the content of users
, SMDevices
and SMDeviceModels
tables:
mysqldump -u root -p --single-transaction sambackend users SMDevices SMDeviceModels > dump.sql
You will then be prompter to enter the root password to access the database.
This will create an SQL file called dump.sql
with the content of the tables.
If you added personal data into other tables simply add them at the end of the command, just before the '>' character.
Now to retrieve the file on you local machine, exit the container shell and use the following command:
docker cp database:dump.sql dump.sql
Change the table names
Some tables have been renamed when moving to the new version of the product. In particular SMDevices
changed into sm_devices
and SMDeviceModels
changed into sm_device_models
. The dump.sql
file need to be updated to reflect that change. This can be done either manually using a proper file editor or with some Linux-style commands such as:
sed -i 's/SMDevices/sm_devices/g' dump.sql sed -i 's/SMDeviceModels/sm_device_models/g' dump.sql
Loading the old database content into the new one
First push the file into the newer instance of the database container:
docker cp dump.sql database:dump.sql
Then load the content into the database:
mysql -u root -p sambackend < dump.sql