Backup and restore full backup VPS (migrate VPS)
First step was backup your Linux VPS directly on the server and then download it into your machine. Hereโs how to create a compressed backup and download it afterward.
Creating and Downloading a Compressed Backup
- Create a Compressed Archive on the VPS:
- You can useย
tarย to create a compressed archive of the entire root filesystem while excluding directories that donโt need to be backed up (such asย/dev,ย/proc,ย/sys, etc.). - Run the following command on your VPS: sudo tar -czvf /root/vps-backup.tar.gz –exclude={“/dev/*”,”/proc/*”,”/sys/*”,”/tmp/*”,”/run/*”,”/mnt/*”,”/media/*”,”/lost+found”} /
- This command will create a file namedย
vps-backup.tar.gzย in theย/rootย directory. - Explanation:
tar -czvf:-c: Creates a new archive.-z: Compresses the archive with gzip.-v: Verbose mode to show progress.-f: Specifies the filename.
--exclude: Excludes directories that shouldnโt be part of the backup (as explained previously).
- You can useย
- Download the Backup File to Your Local Machine:
- After creating the compressed file, you can transfer it to your Windows machine using anย
scpย tool likeย WinSCPย or a terminal withย SSHย (e.g., PowerShell or a WSL terminal). - Option 1: Using WinSCP:
- Open WinSCP and connect to your VPS using SFTP.
- Navigate to theย
/rootย directory and locateยvps-backup.tar.gz. - Download the file by dragging it to your local directory on Windows.
- Option 2: Using scp in PowerShell or WSL:
- Open PowerShell or WSL on your Windows machine.
- Use the following command to copy the file: scp user@vps_ip:/root/vps-backup.tar.gz C:\path\to\local\directory
- Replaceย
userย andยvps_ipย with your VPS username and IP address, and specify the local path where you want to save the file.
- After creating the compressed file, you can transfer it to your Windows machine using anย
- Verify the Backup File on your local machine:
- After downloading, you can use tools likeย 7-Zipย orย WinRARย on Windows to inspect the contents ofย
vps-backup.tar.gzย and ensure the backup was successful.
- After downloading, you can use tools likeย 7-Zipย orย WinRARย on Windows to inspect the contents ofย
- Clean Up (Optional):
- If you need to free up space on the VPS, you can delete the backup file fromย
/rootย after confirming itโs safely downloaded:sudo rm /root/vps-backup.tar.gz
- If you need to free up space on the VPS, you can delete the backup file fromย
This method will give you a full, compressed backup of your Linux system that you can easily store or move. To restore it to another Linux server, you can transfer the archive back to the new server and extract it.
To restore the vps-backup.tar.gz file to a new VPS, you can follow these steps. This process will extract all files and configurations, effectively replicating your original system on the new VPS.
Restoring the Backup on a New VPS
- Transfer the Backup File to the New VPS:
- If the backup file is on your local machine, upload it to the new VPS usingย
scpย or a tool like WinSCP. - Example usingย
scp: scp C:\path\to\vps-backup.tar.gz user@new_vps_ip:/root - Replaceย
user@new_vps_ipย with your new VPS username and IP address, and specify the local path to the backup file.
- If the backup file is on your local machine, upload it to the new VPS usingย
- Prepare the New VPS:
- Connect to the new VPS via SSH: ssh user@new_vps_ip
- Make sure you are logged in asย
rootย or haveยsudoย privileges since restoring the backup will need access to system files and directories.
- Extract the Backup Archive:
- Go to the directory where you transferred the backup file, e.g.,ย
/root. - Run the following command to extract the backup archive:sudo tar -xzvf /root/vps-backup.tar.gz -C /
- Explanation:
-x: Extracts the archive.-z: Decompresses the file (since itโs gzip compressed).-v: Verbose mode to show progress.-f: Specifies the file.-C /: Extracts everything to the root directory.
- Go to the directory where you transferred the backup file, e.g.,ย
- Adjust System Configurations:
- After restoring, some configurations may need adjustment based on the new VPS environment. For example:
- Network Configurations: Ensure any network or IP-specific settings inย
/etc/network/interfacesย orย/etc/netplanย are correct. - Hostname: Update the hostname if needed by editingย
/etc/hostnameย andย/etc/hosts. - SSH Keys: If your SSH keys differ, update them inย
/root/.sshย orย/home/username/.ssh.
- Network Configurations: Ensure any network or IP-specific settings inย
- After restoring, some configurations may need adjustment based on the new VPS environment. For example:
- Reinstall GRUB (Optional):
- If your VPS uses a different bootloader or disk layout, you may need to reinstall GRUB or another bootloader.
- To reinstall GRUB, you can use the following command:sudo grub-install sudo update-grub
- Reboot the New VPS:
- Restart the VPS to apply changes and ensure all services are running with the restored configurations:sudo reboot
- Verify the Restoration:
- After rebooting, check that key services like Apache, Docker, and other applications are running correctly.
- Runย
systemctlย to see the status of services:sudo systemctl status apache2 sudo systemctl status docker
This process should restore all your original files, configurations, and installed applications, effectively cloning your previous setup on the new VPS.





