How to Transfer Your Full Stack Website with Database

How to Transfer Your Full Stack Website with Database

How to Transfer Your Full Stack Website with Database

Seamless VPS Migration without Data Loss

Step 1: Back Up MongoDB on Old VPS

Log in to your old VPS and back up your MongoDB database using mongodump.

Step 2: Archive Files

Compress your database backup and website files into a tar.gz archive.

Step 3: Download Archive to Local Machine

Use SCP to transfer the archive to your local system.

Where to run: This command must be run on your local machine (e.g., in the Windows Command Prompt, PowerShell, or a terminal like Git Bash if you're using Windows). It initiates a secure copy from the old VPS to your local system. Ensure you have SSH access configured on your local machine (e.g., using an SSH client like OpenSSH or PuTTY on Windows).

Step 4: Upload Archive to New VPS

Transfer the archive to the new VPS using SCP.

Step 5: Extract Archive on New VPS

Log in to the new VPS and extract the archive.

Step 6: Restore MongoDB Database

Install MongoDB and restore the database using mongorestore.

Step 7: Update DNS Records

Update your domain’s A record to point to the new VPS IP address.

Example: Set A record to new-vps-ip with low TTL (e.g., 300).

Step 8: Set Up the MERN Stack

Install Node.js, dependencies, and build the React frontend.

Step 9: Install PM2 for Background Execution

Run your app 24/7 with PM2.

Step 10: Install and Configure Caddy

Set up Caddy as a reverse proxy with automatic HTTPS.

Conclusion

By following these steps, you can migrate your full stack website and MongoDB database without data loss. Test your site, monitor logs, and clean up temporary files.

Subscribe - Thapa Technical