Move Proxmox Container to Different Storage (Updated for LXC)

Move Proxmox Container to Different Storage (Updated for LXC)

Get Social!

2015-03-05 00_18_04-Proxmox Virtual Environment storageThe Proxmox Web GUI does not give us the ability to migrate a container from one storage device to another directly. To move a container onto different storage we have to take a backup of the container and restore it to the same ID with a different storage device specified. This can be time laborious when working with several containers.

This is an update to the OpenVZ script found here.

The below script allows you to move an LXC container from one storage device to another. The process requires that the container be stopped, which the script will handle.

Save the below script into a file called migrate.

Set execution permissions on the script:

The script has several parameters which are detailed below:

  • -d is specified if you would like the script to delete the temporary backup after the process has completed. Leave this out if you would like the backup tar file to be kept, just in case anything goes wrong.
  • -s is required to specify the name of the target storage. You can find this from the Proxmox Web GUI.
  • -c is required for the container ID to migrate.

In addition, the script contains the variable TMP. This will be the location of the backup tar created as part of the migration process and must contain enough space to store the content of the container being migrated. You can change this to suit your environment.

Example command:

 


Related posts:


3 Comments

Olsonnn

21-Mar-2018 at 11:22 pm

Great script! thanks for sharing!

Björn Fries

29-Mar-2018 at 9:10 am

Hallo, there are two errors in your script:
line 58: if pct list| fgrep -w -q “$CT” | grep “running”
should be more like:
if pct list| fgrep -w “$CT” | grep “running”
the -q hides the output from fgrep, so the last grep was always ‘false’.

line 83: $TMP is already part of $LOG and has to be deleted here

Otherwise I have to thank you for this script, comes in handy as I have to move 10 containers from NFS to ceph storage.

    Björn Fries

    29-Mar-2018 at 9:20 am

    line 65: if you user HA with proxmox, you have to wait till the container is really stopped:

    if $RUNNING
    then
    pct stop $CT
    while pct list| fgrep -w “$CT”| grep -q “running” ; do sleep 1 ; done
    fi

Leave a Reply

Visit our advertisers

Search

Quick Poll

Do you use ZFS on Linux?

Visit our advertisers