Move Proxmox Container to Different Storage (Updated for LXC)

The 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.

-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:

1

./migrate-d-snewstorage-c101

Related posts:

3 Comments

Olsonnn

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.