Updated: 30 November 2026 · Applies to: Magento Open Source and Adobe Commerce 2.4; database steps tested with MySQL 8.4.11, file steps with rsync 3.2.7 on Ubuntu 24.04
To move a Magento 2 store without losing orders, do it in two rounds. First copy the files and a test copy of the database to the new server and check the store there through your hosts file while the old store keeps selling. Then, in a short maintenance window, put the old store into maintenance mode, take a final database export, import it on the new server, check that the latest order and stock levels match, and only then switch DNS. A single export at the start is not enough: every order placed after that export exists only on the old server and is lost when you switch.
Before you start
- SSH access to both servers, and the same Magento version, PHP version and extensions on the new server (check them against Adobe's system requirements for your Magento release).
- A database and database user on the new server.
- Lower the TTL of your domain's DNS records (for example to 300 seconds) at least a day before the switch, so the change spreads quickly.
- A full backup of the old store's files and database that you keep untouched.
- Run every
bin/magentocommand as the user that owns the Magento files. According to Adobe, all Magento CLI commands must be run by the file system owner. In the examples below that user isdeployand Magento lives in/var/www/magento; change both to match your servers.
Round 1: copy the store and test it
- Copy the files. From the new server, pull the Magento folder from the old one with rsync. Caches, sessions and generated code are rebuilt on the new server, so leave them out:
rsync -a --exclude='var/cache/' --exclude='var/page_cache/' --exclude='var/session/' --exclude='generated/code/' deploy@old.example.com:/var/www/magento/ /var/www/magento/
If SSH on the old server uses another port, see how to connect to SSH on a different port. - Take a first database copy on the old server.
--single-transactiongives a consistent copy of InnoDB tables without locking the live store, and--triggerskeeps the database triggers, which Adobe says a Commerce database dump should include:mysqldump -u magento_user -p --single-transaction --quick --routines --triggers --no-tablespaces magento_db | gzip > magento-first.sql.gz
We add--no-tablespacesbecause on MySQL 8.4 an ordinary database user without the PROCESS privilege otherwise stops with "Access denied; you need (at least one of) the PROCESS privilege(s)". - Import it on the new server. The
sedpart removes theDEFINERlines that name the old server's database user, the same approach Adobe uses in its own migration guide:zcat magento-first.sql.gz | sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/' | sudo mysql magento_db
In our test, importing the triggers as the ordinary database user failed with "ERROR 1419 (HY000): You do not have the SUPER privilege and binary logging is enabled", so import as the MySQL administrator (root) on a VPS or dedicated server. On shared hosting, ask the host to run the import or to allow trigger creation. - Point Magento at the new database. Open
app/etc/env.phpon the new server and change only thehost,dbname,usernameandpasswordvalues under'db'. Keep the'crypt'key exactly as it is: according to Adobe, it is the encryption key Magento uses to protect passwords and other sensitive data, so a new key makes saved payment and integration settings unreadable. If the old server used Redis or another cache or session store, update those sections too. - Rebuild the new copy:
sudo -u deploy bin/magento setup:upgrade --keep-generated
Only needed if the Magento version or modules differ from the old server; skip it when both are identical. Then:sudo -u deploy bin/magento indexer:reindex
sudo -u deploy bin/magento cache:flush
In production mode, also runbin/magento setup:di:compileandbin/magento setup:static-content:deploy -fifgeneratedorpub/staticwere not copied or are out of date. - Test before DNS changes. Add the new server's IP address for your domain to your computer's hosts file (see test a website before changing DNS), then browse the catalogue, log in to the admin panel, and place a test order with a test payment method. The final import in round 2 replaces the database, so this test order disappears.
Round 2: the final synchronisation (short maintenance window)
Pick a quiet hour. With a prepared new server, this round usually takes only as long as one database export and import.
- Stop new orders on the old store. On the old server, exempt your own IP and enable maintenance mode:
sudo -u deploy bin/magento maintenance:enable --ip=203.0.113.10
Visitors now get a 503 maintenance page and cannot place orders. Adobe recommends stopping message queue consumers while maintenance mode is on (find them withps -ef | grep queue:consumers:start). Also remove the old server's Magento cron jobs so they stop sending emails and running imports:sudo -u deploy bin/magento cron:remove
- Copy any files added since round 1 (new product images, invoices, exports). Run the same rsync command again; it copies only what changed. Add
--dry-run --itemize-changesfirst if you want to see the list. - Take the final database export on the old server, with the same command as before:
mysqldump -u magento_user -p --single-transaction --quick --routines --triggers --no-tablespaces magento_db | gzip > magento-final.sql.gz
- Replace the test database on the new server. Drop and re-create the database so nothing from round 1 is left, then import:
sudo mysql -e "DROP DATABASE magento_db; CREATE DATABASE magento_db;"
zcat magento-final.sql.gz | sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/' | sudo mysql magento_db
If you re-create the database, grant your Magento database user its privileges on it again if your setup removed them. - Check that nothing is missing. Run the same queries on the old and the new database and compare the results. The latest order:
SELECT MAX(entity_id), MAX(increment_id) FROM sales_order;
Total stock:SELECT SUM(qty) FROM cataloginventory_stock_item;
Both numbers must be identical on both servers. If your tables use a prefix, add it to the table names. - Finish the new server:
sudo -u deploy bin/magento indexer:reindex
sudo -u deploy bin/magento cache:flush
sudo -u deploy bin/magento cron:install
Make surevar/.maintenance.flagdid not come across in the file copy; if it did, runbin/magento maintenance:disableon the new server. - Switch DNS to the new server's IP address and install or renew the SSL certificate there if needed. Remove the hosts file entry from your computer.
- Keep the old store in maintenance mode for a few days. Visitors whose DNS still points to the old server see the maintenance page instead of placing an order that would be lost. Leave the old server running as a rollback point until you are sure everything works, then cancel it.
Lab example: we tested the database steps in a MySQL 8.4 container with a cut-down copy of the sales_order and cataloginventory_stock_item tables and a trigger. After the first copy we placed an order on the "old" database. Before the final sync the two databases differed:
db id inc old 3 000000103 new 2 000000102
After the final export and import they matched:
db id inc old 3 000000103 new 3 000000103 db qty old 14.0000 new 14.0000
That missing order 000000103 is exactly what a one-export migration loses.
If something goes wrong
- The new store shows errors after the switch: point DNS back to the old server and run
bin/magento maintenance:disablethere. Because the old store was frozen during the final sync, no orders are lost. - "ERROR 1419" during import: the importing user cannot create triggers; import as the MySQL administrator.
- Admin login or payment settings stop working: the
'crypt'key inapp/etc/env.phpdiffers from the old server. Copy the old key back and flush the cache. - The store looks unstyled: static files are missing; run
bin/magento setup:static-content:deploy -fas the file owner.
Related articles
- How to enable or disable maintenance mode in Magento
- How to use rsync to copy and sync files and directories in Linux
- How to upgrade Magento v2
A Magento store needs its own resources, so a KVM VPS or a managed dedicated server suits it better than shared hosting. If you want an engineer to plan or run the move, our Hire an Expert team can help by the hour.
Official documentation: Adobe Commerce: Enable or disable maintenance mode, Adobe Commerce: Migrate and deploy, Adobe Commerce: env.php reference