forked from JAC2703/proxmox-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmigrate
executable file
·84 lines (70 loc) · 1.52 KB
/
migrate
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/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