How to Transfer Data Between VPS Without Downtime

🔹 Why You Might Need This

Transferring data from one VPS to another may be necessary when:

  • you’re upgrading to a new plan or changing hosting providers;
  • the old VPS runs an outdated OS or lacks resources;
  • you want to switch server locations (e.g., to another data center);
  • the infrastructure is being upgraded without interrupting services.

The goal is to migrate data while keeping your website or app fully operational.

⚙️ 1. Preparation

  1. Deploy a new VPS — ideally with the same operating system as the current one.
  2. Check access permissions:
    • SSH access to both servers;
    • root privileges;
    • port 22 open for SSH connections.
  3. Update both systems: sudo apt update && sudo apt upgrade -y
  4. Ensure there’s enough free space on the new VPS for backups and files.

📦 2. Transferring Files and Databases

🔸 Option 1: rsync (recommended)

rsync allows you to sync files between servers without stopping services:

rsync -avz -e ssh /var/www/ root@NEW_SERVER_IP:/var/www/

Key flags:
-a — archive mode (preserves permissions and ownership);
-v — verbose output;
-z — compresses data during transfer.

You can re-run the command before the DNS switch to copy only modified files.

🔸 Option 2: tar + scp (archiving)

On the old VPS:

tar czf backup.tar.gz /var/www/
scp backup.tar.gz root@NEW_SERVER_IP:/root/

On the new VPS:

tar xzf backup.tar.gz -C /

🔸 Option 3: Transferring Databases (MySQL / MariaDB)

On the old VPS:

mysqldump -u root -p database_name > backup.sql
scp backup.sql root@NEW_SERVER_IP:/root/

On the new VPS:

mysql -u root -p database_name < /root/backup.sql

🌐 3. Testing the New Server

Before updating DNS, edit your local /etc/hosts file:

NEW_SERVER_IP yourdomain.com

This lets you preview the site from the new VPS and ensure everything works correctly.

🔄 4. Switching DNS Without Downtime

  1. Lower your DNS TTL to 300 seconds (5 minutes) in advance.
  2. After confirming that the new VPS works properly, update the A record to the new IP.
  3. DNS propagation usually takes 5–30 minutes, during which users may connect to either server.

To avoid losing new data (e.g., orders, messages), run rsync again after DNS update to synchronize changes.

🧱 5. Final Steps

  • Verify that backups have been created successfully.
  • Remove temporary files (backup.tar.gz, backup.sql).
  • Renew the SSL certificate if it’s IP-bound.
  • If needed, extend the disk or configure automatic backups on the new VPS.

🧩 6. Useful Tips

  • For complex setups (WordPress, Laravel, Docker), combine rsync with mysqldump or use Docker Volume backups.
  • For long migrations, you can temporarily configure a reverse proxy on the old VPS to redirect traffic to the new IP.
  • To automate the process, use Rclone or scp with SSH keys for passwordless access.
Leave a Reply 0

Your email address will not be published. Required fields are marked *