Migrating a Linux VPS to a new server may seem complicated, but with the right approach, you can transfer your entire server—including websites, databases, emails, configurations, and user data—with minimal downtime.
In this guide, you'll learn how to create a complete Linux VPS backup and restore it on a new VPS safely.
Why Migrate a Linux VPS?
There are several reasons why you may need to migrate your VPS:
- Upgrading to a faster server
- Moving to a different data center
- Better hardware and performance
- Lower hosting costs
- Improved security
- Changing hosting providers
Before You Start
Before taking a backup, make sure:
- You have root SSH access.
- Both old and new VPS are running Linux.
- The new VPS has enough storage.
- Important services are stopped during backup (optional but recommended).
Step 1: Check Disk Usage
First, check how much data needs to be backed up.
df -h
du -sh /*
This helps ensure your new VPS has sufficient storage.
Step 2: Create a Full VPS Backup
A full server backup can be created using the tar command.
Run:
cd /
tar --exclude=/proc \
--exclude=/sys \
--exclude=/dev \
--exclude=/run \
--exclude=/mnt \
--exclude=/media \
--exclude=/tmp \
--exclude=/lost+found \
-czpf /root/vps-backup.tar.gz .
This backup includes:
- Website files
- Home directories
- Databases
- Apache/Nginx configuration
- User accounts
- Cron jobs
- SSL certificates
- System configuration
Step 3: Backup Databases
For MySQL or MariaDB, create a database dump.
mysqldump --all-databases --single-transaction --quick --lock-tables=false > /root/all-database.sql
If you're using PostgreSQL:
pg_dumpall > /root/postgres-backup.sql
Step 4: Backup Email (Optional)
If your VPS hosts email services such as Postfix or Dovecot, also back up:
/etc/postfix
/etc/dovecot
/var/vmail
Step 5: Transfer Backup to the New VPS
Use scp:
scp /root/vps-backup.tar.gz root@NEW_SERVER_IP:/root/
scp /root/all-database.sql root@NEW_SERVER_IP:/root/
Or use rsync for faster and resumable transfers:
rsync -avzP /root/vps-backup.tar.gz root@NEW_SERVER_IP:/root/
Step 6: Restore Backup on the New VPS
Extract the backup:
cd /
tar -xzpf /root/vps-backup.tar.gz
Step 7: Restore Databases
MySQL:
mysql < /root/all-database.sql
PostgreSQL:
psql -f /root/postgres-backup.sql postgres
Step 8: Install Missing Packages
If the new VPS is freshly installed, install the required software.
Example:
dnf install httpd mariadb-server php
or
apt install apache2 mariadb-server php
depending on your Linux distribution.
Step 9: Restart Services
Restart all major services.
systemctl restart httpd
systemctl restart nginx
systemctl restart mariadb
systemctl restart mysql
systemctl restart php-fpm
systemctl restart dovecot
systemctl restart postfix
Only restart the services that are installed on your server.
Step 10: Verify Everything
Before changing DNS:
- Check websites.
- Test database connections.
- Verify email functionality.
- Test SSL certificates.
- Check cron jobs.
- Confirm user permissions.
- Review server logs.
Useful commands:
systemctl status apache2
systemctl status httpd
systemctl status nginx
journalctl -xe
Step 11: Update DNS
Once everything works correctly:
- Update the A record to the new VPS IP.
- Lower TTL before migration for faster propagation.
- Wait for DNS propagation.
Alternative Method: Use rsync for Live Migration
If you want minimal downtime, use:
rsync -aAXHv --delete / root@NEW_SERVER_IP:/
Exclude virtual directories:
--exclude=/proc
--exclude=/sys
--exclude=/dev
--exclude=/run
--exclude=/tmp
Run rsync twice—the second run after stopping services—to synchronize only the changed files.
VPS Migration Checklist
- ✅ Full file backup created
- ✅ Database backup completed
- ✅ Email data backed up
- ✅ SSL certificates copied
- ✅ User accounts migrated
- ✅ Cron jobs verified
- ✅ Applications tested
- ✅ DNS updated
Common Migration Mistakes
- Forgetting to back up databases
- Restoring on a different Linux version without testing
- Not copying SSL certificates
- Ignoring file permissions
- Changing DNS before testing the new server
- Not verifying firewall rules
Best Practices
- Always keep at least two backup copies.
- Test the backup before deleting the old VPS.
- Use rsync for large servers.
- Keep software versions compatible between the old and new VPS.
- Monitor logs after migration to catch any issues early.
Conclusion
Migrating a Linux VPS is straightforward when you follow a structured process. By creating a complete server backup, transferring it securely, restoring the data, and thoroughly testing the new environment, you can move your applications with minimal downtime and without data loss.
Whether you're upgrading hardware, switching hosting providers, or moving to a new location, following these steps ensures a smooth and reliable VPS migration.