This repository has been archived by the owner on Dec 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
/
rsrsyncLive.sh
executable file
·770 lines (634 loc) · 22.3 KB
/
rsrsyncLive.sh
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
#!/bin/bash
# =============================================================================
# - title : Migrating Servers Using RSYNC
# - description : This Script Will Migrate Data From one Instance to another
# - License : GPLv3
# - author : Kevin Carter
# - date : 2013-11-16
# - version : 2.0.1
# - usage : bash rsrsyncLive.sh
# - OS Supported : Ubuntu, Debian, SUSE, Gentoo, RHEL, CentOS, Scientific, Arch
# =============================================================================
# Trap Errors and or Exits
trap "CONTROL_C" SIGINT
trap "EXIT_ERROR Line Number: ${LINENO} Exit Code: $?" ERR
# Set modes
set -u
set -e
# Root user check for install
# =============================================================================
function CHECKFORROOT() {
USERCHECK=$( whoami )
if [ "$(id -u)" != "0" ]; then
echo -e "This script must be run as ROOT
You have attempted to run this as ${USERCHECK}
use sudo $0 or change to root.
"
exit 1
fi
}
# Root user check for install
# =============================================================================
function CREATE_SWAP() {
cat > /tmp/swap.sh <<EOF
#!/usr/bin/env bash
if [ ! "\$(swapon -s | grep -v Filename)" ];then
SWAPFILE="/SwapFile"
if [ -f "\${SWAPFILE}" ];then
swapoff -a
rm \${SWAPFILE}
fi
dd if=/dev/zero of=\${SWAPFILE} bs=1M count=1024
chmod 600 \${SWAPFILE}
mkswap \${SWAPFILE}
swapon \${SWAPFILE}
fi
EOF
cat > /tmp/swappiness.sh <<EOF
#!/usr/bin/env bash
SWAPPINESS=\$(sysctl -a | grep vm.swappiness | awk -F' = ' '{print \$2}')
if [ "\${SWAPPINESS}" != 60 ];then
sysctl vm.swappiness=60
fi
EOF
if [ ! "$(swapon -s | grep -v Filename)" ];then
chmod +x /tmp/swap.sh
chmod +x /tmp/swappiness.sh
/tmp/swap.sh && /tmp/swappiness.sh
fi
}
# Trap a CTRL-C Command
# =============================================================================
function CONTROL_C() {
set +e
echo -e "
\033[1;31mAAHAHAAHH! FIRE! CRASH AND BURN! \033[0m
\033[1;36mYou Pressed [ CTRL C ] \033[0m
"
QUIT
if [ "${INFLAMMATORY}" == "True" ];then
echo -e "You obviously screwed something up or you got cold feet..."
fi
echo "I quit, and deleted all of the temp files I made."
EXIT_ERROR
}
# Tear down
# =============================================================================
function QUIT() {
set +e
set -v
echo 'Removing Temp Files'
GENFILES="/tmp/intsalldeps.sh /tmp/known_hosts /tmp/postopfix.sh /tmp/swap.sh"
for temp_file in ${EXCLUDE_FILE} ${GENFILES} ${SSH_KEY_TEMP};do
[ -f ${temp_file} ] && rm ${temp_file}
done
set +v
}
function EXIT_ERROR() {
# Print Messages
echo -e "ERROR! Sorry About that...
Here is what I know: $@
"
QUIT
exit 1
}
# Say something nice and exit
# =============================================================================
function ALLDONE() {
echo "all Done."
if [ "${INFLAMMATORY}" == "True" ];then
echo -e "I hope you enjoyed all of my hard work..."
fi
GITHUBADDR="\033[1;36mhttps://github.com/cloudnull\033[0m"
WEBADDR="\033[1;36mhttp://cloudnull.io\033[0m"
echo -e "
Stop by ${GITHUBADDR} or ${WEBADDR} for other random tidbits...
"
if [ "${INFLAMMATORY}" == "True" ];then
echo -e "And if you feel so Inclined you can buy me a \033[1;33mBeer\033[0m,
I perfer cold \033[1;33mBeer\033[0m But I will normally drink anything. :)
"
fi
}
# Check to see if this is an Amazon Server Migrating to the Rackspace Cloud
# =============================================================================
function ISTHISAMAZON() {
KERNELTYPE=$(uname -r | head -n 1)
if [ "$(echo "${KERNELTYPE}" | grep -i amzn)" ];then
AK="YES"
else
AK="FALSE"
fi
# Check for known Amazon BOTO Python Modules
AB=$(echo -e "
try:
import boto.roboto.awsqueryservice
except ImportError:
print 'FAIL'
else:
print 'YES'
" | python)
# Check for known BOTO Python Modules
CB=$(echo -e "
try:
import boto
except ImportError, e:
print 'FAIL'
else:
print 'YES'
" | python)
if [ "${AK}" == "YES" ] || [ "${AB}" == "YES" ] || [ "${CB}" == "YES" ];then
echo -e "It seems you are currently on an Amazon Server using
The \033[1;33mAmazon AMI\033[0m Linux Distribution.
"
if [ "${INFLAMMATORY}" == "True" ];then
echo -e "Which must really suck..."
fi
echo -e "Is this instance coming from \033[1;33mAmazon EC2\033[0m?"
read -p "Please Answer yes or no : " MIGRATEEC2
MIGRATEEC2=${MIGRATEEC2:-"no"}
case ${MIGRATEEC2} in
yes)
echo -e "Due to \033[1;33mAmazon EC2\033[0m SSH Security already in
place. Access to your Instance POST migration will use your current Amazon
Method. Which may involve PEM files, keys or other assorted means.
"
if [ "${INFLAMMATORY}" == "True" ];then
echo -e "Bottom Line, If it worked before it should work again..."
fi
# Adding additional Excludes, for Amazon
echo -e "We are adding additional Excludes to accommodate
\033[1;33mAmazon EC2\033[0m Instances.
"
if [ "${INFLAMMATORY}" == "True" ];then
echo -e "Which by the way are junk..."
fi
AMAZONEXCLUDEVAR=$(echo ${AMAZONEXCLUDE_LIST} | sed 's/\ /\\n/g')
echo -e ${AMAZONEXCLUDEVAR} | tee -a ${EXCLUDE_FILE}
find / -name '*cloudinit*' | tee -a ${EXCLUDE_FILE}
find / -name '*cloud-init*' | tee -a ${EXCLUDE_FILE}
find / -name '*amazon*' | tee -a ${EXCLUDE_FILE}
sleep 5
if [ "${AK}" == "YES" ];then
echo -e "Based on the \033[1;33m${KERNELTYPE}\033[0m Kernel. You
seem to be using an Instance of \033[1;33mAmazon AMI Linux\033[0m. If you want
to continue you can, but there may be complications. Your best bet for
guaranteed success is to manually migrate your data.
"
if [ "${INFLAMMATORY}" == "True" ];then
echo -e "The reason for this is that you have chosen a terrible
distribution of Linux which really is nothing more than a clone of another
terrible Linux Distribution... RHEL...but rest assured I did test this action
thoroughly... even if I did hate every minute of it.
"
fi
echo -e "I have Great success in migrating \033[1;33mAmazon AMI
Linux\033[0m to \033[1;31mCentOS/RHEL\033[0m If your Target Server is a
\033[1;31mCentOS/RHEL\033[0m you should be fine. While I have had a lot of
Success moving these types of Instances around, You should also be aware that
\033[1;33mAmazon AMI Linux\033[0m is proprietary and it could have issues moving
to a more Open Source Platform.
"
read -p "Press [Enter] to Continue or [ CTRL -C ] to quit."
fi
;;
no)
echo -e "Sounds Good, I don't like \033[1;33mAmazon\033[0m anyway."
;;
*)
echo "Please Enter \"yes\" or \"no\" in lower case letters."
unset MIGRATEEC2
ISTHISAMAZON
;;
esac
fi
}
# Amazon Specific Processes
# =============================================================================
function AMAZONPROCESSES() {
if [ "${AK}" == "YES" ];then
echo -e "\033[1;36mNow performing Amazon Specific Processes\033[0m"
T_HOST=$(ssh -i ${SSH_KEY_TEMP} -o UserKnownHostsFile=/dev/null \
-o StrictHostKeyChecking=no root@${TIP} \
"echo \$( head -1 /etc/issue )")
ssh -i ${SSH_KEY_TEMP} -o UserKnownHostsFile=/dev/null \
-o StrictHostKeyChecking=no root@${TIP} \
"bash postopfix.sh";
ssh -i ${SSH_KEY_TEMP} -o UserKnownHostsFile=/dev/null \
-o StrictHostKeyChecking=no root@${TIP} \
"yum -y install initscripts"
if [ "$(echo ${T_HOST} | grep -i centos)" ];then
TARGET_OS_TYPE="centos"
ssh -i ${SSH_KEY_TEMP} -o UserKnownHostsFile=/dev/null \
-o StrictHostKeyChecking=no root@${TIP} \
"yum -y install ${TARGET_OS_TYPE}-release"
elif [ "$(echo ${T_HOST} | grep -i redhat)" ];then
TARGET_OS_TYPE="redhat"
ssh -i ${SSH_KEY_TEMP} -o UserKnownHostsFile=/dev/null \
-o StrictHostKeyChecking=no root@${TIP} \
"yum -y install ${TARGET_OS_TYPE}-release"
else
TARGET_OS_TYPE="YOUR-TARGET-DISTRO"
echo -e "The Target Distro did not match what I was looking for
You need to login to the Target Instance and run :
yum install ${TARGET_OS_TYPE}-release"
fi
fi
}
# Post Migration script for Amazon AMI Linux
# =============================================================================
function AMAZONPOSTPROCESSES() {
if [ "${AK}" == "YES" ];then
echo -e "# Post Migration Script
REL=\"/etc/yum/vars/releasever\"
VER=\"\$( cat /etc/issue | head -n 1 | awk '{print \$3}' )\"
echo \"\$( echo \${VER} | awk -F '.' '{print \$1}' )\" | tee \${REL}
PKS=\"epel-release system-release sysvinit perl-io perl-file perl-http \"
PKS+=\"perl-lwp perl-net aws perl-libwww\"
for pkg in \${PKS};do
if [ \"\$(rpm -qa | grep -iE \$pkg )\" ];then
rpm -e --nodeps \$pkg
fi
done" | tee /tmp/postopfix.sh
scp -i ${SSH_KEY_TEMP} /tmp/postopfix.sh root@${TIP}:/root/
fi
}
function AMAZONWARNING() {
if [ "${AK}" == "YES" ];then
echo -e "Being that this instance was migrating from an
\033[1;33mAmazon EC2\033[0m You should login to the Target Server and make any
configuration changes that are needed. I have tried to be thorough but some
times things happen which can cause incompatibilities.
"
if [ "${INFLAMMATORY}" == "True" ];then
echo -e "In short if its broke, don't cry...\n"
fi
fi
}
# Set the Source and Origin Drives
# =============================================================================
function GETDRIVE1() {
read -p "
Press [Enter] to Continue accepting the normal Rackspace Defaults
or you may Specify a Source Directory: " DRIVE1
DRIVE1=${DRIVE1:-"/"}
if [ ! -d "${DRIVE1}" ];then
echo "The path or Device you specified does not exist."
read -p "Specify \033[1;33mYOUR\033[0m Source Mount Point : " DRIVE1
DRIVE1=${DRIVE1:-"/"}
GETDRIVE1
fi
}
function GETDRIVE2() {
echo -e "
Here you Must Specify the \033[1;33mTarget\033[0m mount point. This is
\033[1;33mA MOUNT\033[0m Point. Under Normal Rackspace Circumstances this drive
would be \"/\" or \"/dev/xvdb1\". Remember, there is no way to check that the
directory or drive exists. This means we are relying on \033[1;33mYOU\033[0m to
type correctly.
"
read -p "Specify Destination Drive or press [Enter] for the Default : " DRIVE2
DRIVE2=${DRIVE2:-"/dev/xvdb1"}
}
# Get the Target IP
# =============================================================================
function GETTIP() {
MAX_RETRIES=${MAX_RETRIES:-5}
RETRY_COUNT=0
read -p "If you are ready to proceed enter your Target IP address : " TIP
TIP=${TIP:-""}
if [ -z "${TIP}" ];then
echo "No IP was provided, please try again"
unset TIP
RETRY_COUNT=$((${RETRY_COUNT}+1))
if [ ${RETRY_COUNT} -ge ${MAX_RETRIES} ];then
EXIT_ERROR "Hit maximum number of retries, giving up."
else
GETTIP
fi
else
unset MAX_RETRIES
fi
}
# When RHEL-ish Distros are detected
# =============================================================================
function WHENRHEL() {
echo -e "\033[1;31mRHEL Based System Detected\033[0m Installing rsync."
yum -y install rsync
cat > /tmp/intsalldeps.sh <<EOF
#!/usr/bin/env bash
# RHEL Dep Script
yum -y install rsync
EOF
if [ "${INFLAMMATORY}" == "True" ];then
echo -e "It seems that you may be victim of poor life decisions, judging by
your use of RHEL. While I hate having to do this, I am going ahead with the
sync and so don't worry I tested on RHEL even if I hated every moment of it.
"
fi
}
# When Debian based distros
# =============================================================================
function WHENDEBIAN() {
echo -e "\033[1;31mDebian Based System Detected\033[0m"
echo "Performing Package Update"
apt-get update > /dev/null 2>&1
echo "Installing rsync Package."
apt-get -y install rsync > /dev/null 2>&1
cat > /tmp/intsalldeps.sh <<EOF
#!/usr/bin/env bash
# Debian Dep Script
apt-get update > /dev/null 2>&1
apt-get -y install rsync > /dev/null 2>&1
EOF
if [ "${INFLAMMATORY}" == "True" ];then
echo -e "Great choice by choosing a Debian Based Distro.
The Debian way is by far the best way.";
sleep 1
fi
}
# When SUSE
# =============================================================================
function WHENSUSE() {
echo -e "\033[1;31mSUSE Based System Detected\033[0m"
zypper in rsync
cat > /tmp/intsalldeps.sh <<EOF
#!/usr/bin/env bash
# SUSE Dep Script
zypper -n in rsync
EOF
if [ "${INFLAMMATORY}" == "True" ];then
echo -e "I like SUSE Linux, and you should too.
Its not as good as Debian But WAY better than ANYTHING RHEL.
"
sleep 2
fi
}
# When Gentoo
# =============================================================================
function WHENGENTOO() {
echo -e "\033[1;31mGentoo Based System Detected\033[0m"
if [ "${INFLAMMATORY}" == "True" ];then
echo -e "Gentoo is nice if you are into that sort of thing. But I have to
ask, WHY THE HELL are you using this script to move a Gentoo image? As a Gentoo
User, you should have more pride and do it all by hand...
"
sleep 2
fi
}
# When Arch
# =============================================================================
function WHENARCH() {
echo -e "\033[1;31mArch Based System Detected\033[0m"
if [ "${INFLAMMATORY}" == "True" ];then
echo -e "I have never meet anyone who ram a production ready Arch Linux
Anything... And you think your different...
"
sleep 2
fi
}
# When UNKNOWN
# =============================================================================
function WHENUNKNOWN() {
echo -e "
\033[1;31mWARNING! \033[0m
I could not determine your OS Type. This Application has only been tested on :
\033[1;31mDebian\033[0m, \
\033[1;31mUbuntu\033[0m, \
\033[1;31mFedora\033[0m, \
\033[1;31mCentOS\033[0m, \
\033[1;31mRHEL\033[0m, \
\033[1;31mSUSE\033[0m, \
\033[1;31mGentoo\033[0m, \
and \033[1;31mArch\033[0m.
You may need to edit the file '\033[1;31m/etc/issue\033[0m' in an effort to
correct the OS detection issues
"
if [ "${INFLAMMATORY}" == "True" ];then
echo -e "Basically I have no IDEA what to do with you..."
sleep 2
fi
exit 1
}
# Do Distro Check
# =============================================================================
function DISTROCHECK() {
# Check the Source Distro
if [ -f /etc/issue ];then
if [ "$(grep -i '\(centos\)\|\(red\)\|\(scientific\)' /etc/redhat-release)" ]; then
WHENRHEL
elif [ "$(grep -i '\(fedora\)\|\(amazon\)' /etc/issue)" ]; then
WHENRHEL
elif [ "$(grep -i '\(debian\)\|\(ubuntu\)' /etc/issue)" ];then
WHENDEBIAN
elif [ "$(grep -i '\(suse\)' /etc/issue)" ];then
WHENSUSE
elif [ "$(grep -i '\(arch\)' /etc/issue)" ];then
WHENARCH
else
WHENUNKNOWN
fi
elif [ -f /etc/gentoo-release ];then
WHENGENTOO
else
WHENUNKNOWN
fi
}
# RSYNC Check for Version and Set Flags
# =============================================================================
function RSYNCCHECKANDSET() {
if [ ! $(which rsync) ];then
echo -e "The \033[1;36m\"rsync\"\033[0m command was not found. The automatic
Installation of rsync failed so that means you NEED to install it."
exit 1
else
RSYNC_VERSION_LINE=$(rsync --version | grep -E "version\ [0-9].[0-9].[0-9]")
RSYNC_VERSION_NUM=$(echo ${RSYNC_VERSION_LINE} | awk '{print $3}')
RSYNC_VERSION=$(echo ${RSYNC_VERSION_NUM} | awk -F'.' '{print $1}')
if [ "${RSYNC_VERSION}" -ge "3" ];then
RSYNC_VERSION_COMP="yes"
fi
fi
# Set RSYNC Flags
if [ "${RSYNC_VERSION_COMP}" == "yes" ];then
RSYNC_FLAGS='aHEAXSzx'
echo "Using RSYNC <= 3.0.0 Flags."
else
RSYNC_FLAGS='aHSzx'
echo "Using RSYNC >= 2.0.0 but < 3.0.0 Flags."
fi
}
# Dep Scripts
# =============================================================================
function KEYANDDEPSEND() {
echo -e "\033[1;36mBuilding Key Based Access for the target host\033[0m"
ssh-keygen -t rsa -f ${SSH_KEY_TEMP} -N ''
# Making backup of known_host
if [ -f "/root/.ssh/known_hosts" ];then
cp /root/.ssh/known_hosts /root/.ssh/known_hosts.${DATE}.bak
fi
echo -e "Please Enter the Password of the \033[1;33mTARGET\033[0m Server."
ssh-copy-id -i ${SSH_KEY_TEMP} root@${TIP}
if [ -f /tmp/intsalldeps.sh ];then
echo -e "Passing RSYNC Dependencies to the \033[1;33mTARGET\033[0m Server."
scp -i ${SSH_KEY_TEMP} /tmp/intsalldeps.sh root@${TIP}:/root/
fi
if [ -f /tmp/swap.sh ];then
echo -e "Passing Swap script to the \033[1;33mTARGET\033[0m Server."
scp -i ${SSH_KEY_TEMP} /tmp/swap.sh root@${TIP}:/root/
fi
if [ -f /tmp/swappiness.sh ];then
echo -e "Passing Swappiness script to the \033[1;33mTARGET\033[0m Server."
scp -i ${SSH_KEY_TEMP} /tmp/swappiness.sh root@${TIP}:/root/
fi
}
# Commands
# =============================================================================
function RUNPREPROCESS() {
echo -e "Running Dependency Scripts on the \033[1;33mTARGET\033[0m Server."
SCRIPTS='[ -f "swap.sh" ] && bash swap.sh;
[ -f "swappiness.sh" ] && bash swappiness.sh;
[ -f "intsalldeps.sh" ] && bash intsalldeps.sh'
ssh -i ${SSH_KEY_TEMP} -o UserKnownHostsFile=/dev/null \
-o StrictHostKeyChecking=no root@${TIP} \
"${SCRIPTS}" > /dev/null 2>&1
}
function RUNRSYNCCOMMAND() {
set +e
MAX_RETRIES=${MAX_RETRIES:-5}
RETRY_COUNT=0
# Set the initial return value to failure
false
while [ $? -ne 0 -a ${RETRY_COUNT} -lt ${MAX_RETRIES} ];do
RETRY_COUNT=$((${RETRY_COUNT}+1))
${RSYNC} -e "${RSSH}" -${RSYNC_FLAGS} --progress \
--exclude-from="${EXCLUDE_FILE}" \
--exclude "${SSHAUTHKEYFILE}" \
/ root@${TIP}:/
echo "Resting for 5 seconds..."
sleep 5
done
if [ ${RETRY_COUNT} -ge ${MAX_RETRIES} ];then
EXIT_ERROR "Hit maximum number of retries, giving up."
fi
unset MAX_RETRIES
set -e
}
function RUNMAINPROCESS() {
echo -e "\033[1;36mNow performing the Copy\033[0m"
RSYNC="$(which rsync)"
RSSH_OPTIONS="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
RSSH="ssh -i ${SSH_KEY_TEMP} ${RSSH_OPTIONS}"
RUNRSYNCCOMMAND
echo -e "\033[1;36mNow performing Final Sweep\033[0m"
RSYNC_FLAGS="${RSYNC_FLAGS} --checksum"
RUNRSYNCCOMMAND
}
# Run Script
# =============================================================================
INFLAMMATORY=${INFLAMMATORY:-"False"}
VERBOSE=${VERBOSE:-"False"}
DEBUG=${DEBUG:-"False"}
# The Date as generated by the Source System
DATE=$(date +%y%m%d%H)
# The Temp Working Directory
TEMPDIR='/tmp'
# Name of the Temp SSH Key we will be using.
SSH_KEY_TEMP="${TEMPDIR}/tempssh.${DATE}"
# ROOT SSH Key File
SSHAUTHKEYFILE='/root/.ssh/authorized_keys'
# General Exclude List; The exclude list is space Seperated
EXCLUDE_LIST='/boot /dev/ /etc/conf.d/net /etc/fstab /etc/hostname
/etc/HOSTNAME /etc/hosts /etc/issue /etc/init.d/nova-agent* /etc/mdadm*
/etc/mtab /etc/network* /etc/network/* /etc/networks* /etc/network.d/*
/etc/rc.conf /etc/resolv.conf /etc/selinux/config /etc/sysconfig/network*
/etc/sysconfig/network-scripts/* /etc/ssh/ssh_host_*
/etc/udev/rules.d/* /lock /net /sys /tmp
/usr/sbin/nova-agent* /usr/share/nova-agent* /var/cache/yum/* /SwapFile'
# Allow the user to add excludes to the general Exclude list
USER_EXCLUDES=${USER_EXCLUDES:-""}
# Amazon Exclude List; The exclude list is space Seperated
AMAZONEXCLUDE_LIST='/etc/sysctl.conf /etc/yum.repos.d/amzn-*'
# Extra Exclude File
EXCLUDE_FILE='/tmp/excludeme.file'
# Building Exclude File - DONT TOUCH UNLESS YOU KNOW WHAT YOU ARE DOING
# =============================================================================
if [ "${VERBOSE}" == "True" ];then
set -v
fi
if [ "${DEBUG}" == "True" ];then
set -x
fi
if [ "${USER_EXCLUDES}" ];then
EXCLUDE_LIST+=${USER_EXCLUDES}
fi
EXCLUDEVAR=$(echo ${EXCLUDE_LIST} | sed 's/\ /\\n/g')
if [ -f ${EXCLUDE_FILE} ];then
rm ${EXCLUDE_FILE}
fi
echo -e "${EXCLUDEVAR}" | tee -a ${EXCLUDE_FILE}
# Check that we are the root User
CHECKFORROOT
# Clear the screen to get ready for work
clear
if [ "${INFLAMMATORY}" == "True" ];then
echo -e "Inflammatory mode has been enabled...
The application will now be really opinionated...
\033[1;33mYOU\033[0m have been warned...
"
fi
echo -e "This Utility Moves a \033[1;36mLIVE\033[0m System to an other System.
This application will work on \033[1;36mAll\033[0m Linux systems using RSYNC.
Before performing this action you \033[1;35mSHOULD\033[0m be in a screen
session.
"
sleep 1
echo -e "This Utility does an \033[1;32mRSYNC\033[0m copy of instances over the
network. As such, I recommend that you perform this Migration Action on SNET
(Internal IP), however any Network will work.
Here is why I make this recommendation:
Service Net = \033[1;32mFREE\033[0m Bandwidth.
Public Net = \033[1;35mNOT FREE\033[0m Bandwidth
"
# Run the Amazon Check
ISTHISAMAZON
# If the Target IP is not set, ask for it
GETTIP
# Allow the user to specify the source drive
GETDRIVE1
GETDRIVE2
# check what distro we are running on
DISTROCHECK
# Make sure we can swap
CREATE_SWAP
# Check RSYNC version and set the in use flags
RSYNCCHECKANDSET
# Create a Key for target access and send over a dependency script
KEYANDDEPSEND
# If this is an amazon AMI linux Distro send over a post processing script
AMAZONPOSTPROCESSES
# Removing known_host entry made by script
if [ -f "/root/.ssh/known_hosts" ];then
cp /root/.ssh/known_hosts /tmp/known_hosts
sed '$ d' /tmp/known_hosts > /root/.ssh/known_hosts
fi
RUNPREPROCESS
RUNMAINPROCESS
AMAZONPROCESSES
echo -e "\033[1;36mThe target Instance is being rebooted\033[0m"
ssh -i ${SSH_KEY_TEMP} -o UserKnownHostsFile=/dev/null \
-o StrictHostKeyChecking=no root@${TIP} \
"shutdown -r now &"
echo -e "If you were copying something that was not a Rackspace Cloud Server,
You may need to ensure that your setting are correct, and the target is healthy
"
AMAZONWARNING
echo -e "Other wise you are good to go, and the target server should have been
rebooted. If all is well, you should now be able to enjoy your newly cloned
Virtual Instance.
"
# Say something nice
ALLDONE
# Teardown what I setup on the source node and exit
QUIT
exit 0