Migrate VPS Storage on Virtualizor Panel without Data Loss: Easy Steps
This tutorial, part of our Virtualizor tutorials series, will guide you through the process of migrate VPS storage on your Virtualizor panel without any data loss.
Often, you might find yourself in a situation where you need to move a virtual server’s disk from one storage location to another within the same server. This usually happens when your server has multiple storage drives and you want to relocate a VPS’s data without going through the hassle of reinstalling the virtual server.
Note: If your goal is to move the entire virtual server between two completely separate physical servers, refer to our guide on Migrate VPS on Virtualizor between two servers. This article specifically focuses on moving storage within a single server environment.
Let’s walk through the steps of migrate VPS storage using the Virtualizor panel:
-
Log in to your Virtualizor Panel. On the left-hand menu, navigate to "Virtual Servers" and select "Migrate Disk."
-
You’ll be presented with a page similar to the image below:
-
Select the appropriate Server and VPS. Configure the options as needed, and then click the "Migrate VPS Disk" button.
Let’s delve into the details of each option available on the migrate VPS storage page within Virtualizor:
-
Select Server: Choose the server where the virtual server you want to modify is currently located.
-
Select VPS Disk: Select the specific virtual server whose disk you intend to move to a different storage location.
-
Migrate All Disk of Selected VPS: If the selected VPS has multiple disks and you want to move all of them to the new storage, check this option.
-
Select Storage: This is the crucial step where you specify the destination storage drive for the VPS disk(s).
-
Speed Limit for transferring VPS(s) data (in Mbps): If you need to control the transfer speed to avoid impacting other services on the server, enter the desired speed limit in Mbps (Megabits per second). Refer to Mbps Definition for more information on Mbps.
-
Disable Compression: By default, Virtualizor can compress the disk data before transferring it, which can save time and bandwidth. If you want to disable compression, uncheck this option. Otherwise, leave it checked to enable compression during the migration process.
Conclusion
This tutorial has shown you how to migrate VPS storage on the Virtualizor panel without data loss. Previously, this required manual data transfer using SSH commands. Now, with Virtualizor’s built-in feature, you can accomplish this task with just a few clicks.
If you have any further questions about this process, please leave a comment below.
You might also find these related Virtualizor articles helpful:
- Add Administrator ACL on Virtualizor
- Email Settings in Virtualizor step-by-step
- Add Slave Server in Virtualizor
- Two-Factor Authentication Virtualizor
Alternative Solutions for Migrating VPS Storage
While the Virtualizor panel offers a convenient method for migrating VPS storage, there are alternative approaches, especially if you prefer more control or need to work outside the panel. Let’s explore two such alternatives: using rsync
over SSH and leveraging LVM (Logical Volume Management) snapshots.
1. Using rsync
over SSH
rsync
is a powerful command-line utility for synchronizing files and directories. Combined with SSH, it provides a secure and reliable way to transfer VPS disk data. This method requires the VPS to be shut down to ensure data consistency.
Explanation:
This method involves creating an image of the disk, and then using rsync to copy that image to the new location. This has the added advantage of allowing the transfer to be restarted in case of failure.
Steps:
-
Shutdown the VPS: Ensure the VPS is completely shut down to prevent data corruption during the transfer.
-
Create a disk image: Using
qemu-img convert
, create an image of the disk to be migrated. Replace/path/to/old/disk.img
with the actual path to the VPS disk image file, and/path/to/new/disk.img
with the desired path for the new disk image on the destination storage.qemu-img convert -O raw /path/to/old/disk.img /path/to/new/disk.img
-
Use
rsync
over SSH: Usersync
to securely transfer the disk image to the new storage location. Replaceuser@host
with the appropriate SSH user and hostname or IP address. Also, ensure the destination directory exists. The-avz
flags enable archive mode (preserving permissions and timestamps), compression, and verbosity. The--progress
flag shows the transfer progress.rsync -avz --progress /path/to/new/disk.img user@host:/path/to/destination/
-
Verify the Transfer: After the transfer is complete, verify the integrity of the copied disk image. You can use checksums (e.g.,
md5sum
,sha256sum
) on both the source and destination files to ensure they match.md5sum /path/to/new/disk.img md5sum user@host:/path/to/destination/new/disk.img
Compare the outputs of both commands. If the checksums are identical, the transfer was successful.
-
Update Virtualizor: Update the Virtualizor configuration to point the VPS to the new disk image location. This step is crucial for Virtualizor to recognize and use the migrated disk. This will likely involve editing the VPS configuration file within Virtualizor.
-
Start the VPS: Start the VPS to ensure it boots correctly from the new storage location.
Code Example:
# Example assuming source disk is /vz/vps/vps101/disk.img and destination is /new_storage/vps101/disk.img
# Shutdown the VPS (using Virtualizor or command line)
# Example: virsh shutdown vps101
# Create a disk image
qemu-img convert -O raw /vz/vps/vps101/disk.img /new_storage/vps101/disk.img
# Rsync the image over SSH
rsync -avz --progress /new_storage/vps101/disk.img root@your_server_ip:/new_storage/vps101/
# Verify the transfer using checksums
md5sum /new_storage/vps101/disk.img
ssh root@your_server_ip "md5sum /new_storage/vps101/disk.img"
# Update Virtualizor configuration (This step varies depending on the Virtualizor setup)
# Example: Modify the VPS configuration file to point to /new_storage/vps101/disk.img
# Start the VPS (using Virtualizor or command line)
# Example: virsh start vps101
Advantages:
- Control: Provides granular control over the transfer process.
- Flexibility: Works independently of the Virtualizor panel, useful for troubleshooting or custom setups.
- Resilience:
rsync
can resume interrupted transfers, making it suitable for large disk images.
Disadvantages:
- Downtime: Requires VPS downtime during the transfer.
- Complexity: Requires command-line proficiency.
- Manual Configuration: Involves manual updates to the Virtualizor configuration.
2. Leveraging LVM Snapshots
If your storage is managed using LVM (Logical Volume Management), you can leverage snapshots to create a point-in-time copy of the VPS’s logical volume. This allows you to migrate the data with minimal downtime.
Explanation:
LVM snapshots create a copy-on-write image of the original logical volume. Any changes made to the original volume after the snapshot is created are stored separately, leaving the snapshot as a consistent copy of the data at the time of creation.
Steps:
-
Create an LVM Snapshot: Create an LVM snapshot of the VPS’s logical volume. You’ll need to identify the logical volume associated with the VPS. The syntax is:
lvcreate -s -n <snapshot_name> -L <snapshot_size> <original_lv>
. Replace<snapshot_name>
with a descriptive name for the snapshot (e.g.,vps101-snapshot
),<snapshot_size>
with the desired size of the snapshot (usually a percentage of the original LV size, e.g., 20%), and<original_lv>
with the path to the original logical volume (e.g.,/dev/vg0/vps101
).lvcreate -s -n vps101-snapshot -L 20G /dev/vg0/vps101
Note: The snapshot size should be large enough to accommodate the changes made to the original volume during the migration. If the snapshot fills up, it will become invalid.
-
Mount the Snapshot: Mount the snapshot to a temporary directory. This allows you to access the snapshot’s data as if it were a regular filesystem.
mount /dev/vg0/vps101-snapshot /mnt/vps-snapshot
-
Copy the Data: Use
rsync
or another data transfer tool to copy the data from the mounted snapshot to the new storage location.rsync -avz --progress /mnt/vps-snapshot/ user@host:/path/to/destination/
-
Unmount the Snapshot: After the data transfer is complete, unmount the snapshot.
umount /mnt/vps-snapshot
-
Remove the Snapshot: Remove the LVM snapshot to reclaim the storage space.
lvremove /dev/vg0/vps101-snapshot
-
Update Virtualizor: Update the Virtualizor configuration to point the VPS to the new storage location.
Code Example:
# Example assuming the VPS logical volume is /dev/vg0/vps101
# Create LVM snapshot
lvcreate -s -n vps101-snapshot -L 20G /dev/vg0/vps101
# Mount the snapshot
mkdir /mnt/vps-snapshot
mount /dev/vg0/vps101-snapshot /mnt/vps-snapshot
# Rsync the data over SSH
rsync -avz --progress /mnt/vps-snapshot/ root@your_server_ip:/new_storage/vps101/
# Unmount the snapshot
umount /mnt/vps-snapshot
rmdir /mnt/vps-snapshot
# Remove the snapshot
lvremove /dev/vg0/vps101-snapshot
# Update Virtualizor configuration (This step varies depending on the Virtualizor setup)
# Example: Modify the VPS configuration file to point to /new_storage/vps101/
# No need to restart the VPS if done correctly
Advantages:
- Minimal Downtime: Allows for near-zero downtime migration, as the VPS can continue running while the snapshot is being created and copied.
- Data Consistency: Ensures data consistency by capturing a point-in-time snapshot.
Disadvantages:
- LVM Dependency: Requires the storage to be managed using LVM.
- Snapshot Size: The snapshot size needs to be carefully chosen to avoid filling up.
- Performance Impact: Creating and maintaining snapshots can have a slight performance impact on the original volume.
- Complexity: Requires familiarity with LVM concepts and commands.
These alternative methods offer flexibility and control over the VPS storage migration process. Choose the method that best suits your needs and technical expertise. Remember to always back up your data before performing any storage migration.