Migrasi Container Proxmox Ke Storage Lain
Ketika menggunakan Proxmox, ada kalanya kita ingin memindah sebuah Container ke Storage lain, bisa karena storage existing penuh, atau Storage existing performanya kurang baik, dll sehingga perlu ditata ulang dan perlu memindah satu atau beberapa Container ke Storage lain. Cara termudah adalah dengan mem-Backup Container tersebut kemudian me-Restore kembali di Storage tujuan, namun tentunya ribet. Nah berikut ini adalah script yang dibuat oleh James Coyle disini, yang akan menyederhanakan proses Backup Restore tersebut hanya dengan perintah yang simple dari terminal.
#!/bin/bash # # Filename : migrate # Description : Migrate Proxmox OpenVZ container from one storage to another # Author : James Coyle # # Version: # -Date -Author -Description # 20-11-2013 James Coyle Initial # # # Variables TMP=/tmp #Location to use to create the backup for transferring to new storage. This needs to be big enough to store the backup archive for the container. # Do not edit usage() { echo "Usage: $0" echo " [-c Required: Container ID to migrate <int>] " echo " [-s Required: Target storage ID <string>]" echo " [-d Optional: Delete the backup file after CT restoration <boolean>]" echo "" echo "Example: $0 -c 100 -s nasarray" echo "" exit 1; } while getopts "c:s:d" o; do case "${o}" in c) CT=${OPTARG} ;; s) TARGET_STORAGE=${OPTARG} ;; d) DELETE=true ;; *) usage ;; esac done shift $((OPTIND-1)) # Check mandatory fields if [ -z "${CT}" ] || [ -z "${TARGET_STORAGE}" ]; then usage fi RUNNING=false set -e set -o pipefail echo "Moving $CT to $TARGET_STORAGE..." if vzlist | fgrep -w -q " $CT " then RUNNING=true fi if $RUNNING then vzctl stop $CT fi vzdump --dumpdir $TMP $CT ARCHIVE=$(ls -t $TMP/vzdump-openvz-$CT-*.tar | head -n 1) vzrestore $ARCHIVE $CT -force -storage $TARGET_STORAGE if $RUNNING then vzctl start $CT fi if $DELETE then LOG=$(ls -t $TMP/vzdump-openvz-$CT-*.log | head -n 1) echo "Deleting $LOG and $ARCHIVE" rm -rf $ARCHIVE $TMP/$LOG fi
Silahkan salin script tersebut di atas dengan editor favorit Anda. Jangan lupa untuk mengatur permissionnya sbb:
chmod +x migrate
Beberapa parameter yang bisa dipakai: -d : untuk menghapus file backup/dump temporary setelah proses restore selesai dilakukan -s : storage tujuan -c : container ID Contoh perintah:
./migrate -d -s new_storage -c 101
Perintah di atas akan memindahkan Container dengan ID 101 ke Storage new_storage. Jika Container tersebut sedang running, maka akan si Stop terlebih dahulu, dan setelah proses pemindahan berhasil akan di Start kembali. Sebelum melakukan proses migrasi, pastikan Anda membackup terlebih dahulu agar apabilan proses migrasi gagal dan atau menyebaban kerusakan pada Container, Anda dapat mengembalikannya seperti semula. Selamat belajar !
Leave a Reply
Want to join the discussion?Feel free to contribute!