Added some error handling and logs for the GCE export startup script.
This commit is contained in:
parent
d2e65e6433
commit
1b9b37bdc1
|
@ -11,6 +11,15 @@ DISKNAME=${NAME}-toexport
|
|||
PATHS=$(GetMetadata paths)
|
||||
ZONE=$(GetMetadata zone)
|
||||
|
||||
Exit () {
|
||||
for i in ${PATHS}; do
|
||||
LOGDEST="${i}.exporter.log"
|
||||
echo "Uploading exporter log to ${LOGDEST}..."
|
||||
gsutil -h "Content-Type:text/plain" cp /var/log/daemon.log ${LOGDEST}
|
||||
done
|
||||
exit $1
|
||||
}
|
||||
|
||||
echo "####### Export configuration #######"
|
||||
echo "Image name - ${IMAGENAME}"
|
||||
echo "Instance name - ${NAME}"
|
||||
|
@ -20,25 +29,48 @@ echo "Export paths - ${PATHS}"
|
|||
echo "####################################"
|
||||
|
||||
echo "Creating disk from image to be exported..."
|
||||
gcloud compute disks create ${DISKNAME} --image ${IMAGENAME} --zone ${ZONE}
|
||||
if ! gcloud compute disks create ${DISKNAME} --image ${IMAGENAME} --zone ${ZONE}; then
|
||||
echo "Failed to create disk."
|
||||
Exit 1
|
||||
fi
|
||||
|
||||
echo "Attaching disk..."
|
||||
gcloud compute instances attach-disk ${NAME} --disk ${DISKNAME} --device-name toexport --zone ${ZONE}
|
||||
if ! gcloud compute instances attach-disk ${NAME} --disk ${DISKNAME} --device-name toexport --zone ${ZONE}; then
|
||||
echo "Failed to attach disk."
|
||||
Exit 1
|
||||
fi
|
||||
|
||||
echo "Dumping disk..."
|
||||
dd if=/dev/disk/by-id/google-toexport of=disk.raw bs=4096 conv=sparse
|
||||
if ! dd if=/dev/disk/by-id/google-toexport of=disk.raw bs=4096 conv=sparse; then
|
||||
echo "Failed to dump disk to image."
|
||||
Exit 1
|
||||
fi
|
||||
|
||||
echo "Compressing and tar'ing disk image..."
|
||||
tar -czf root.tar.gz disk.raw
|
||||
if ! tar -czf root.tar.gz disk.raw; then
|
||||
echo "Failed to tar disk image."
|
||||
Exit 1
|
||||
fi
|
||||
|
||||
echo "Detaching disk..."
|
||||
gcloud compute instances detach-disk ${NAME} --disk ${DISKNAME} --zone ${ZONE}
|
||||
if ! gcloud compute instances detach-disk ${NAME} --disk ${DISKNAME} --zone ${ZONE}; then
|
||||
echo "Failed to detach disk."
|
||||
fi
|
||||
|
||||
FAIL=0
|
||||
echo "Deleting disk..."
|
||||
gcloud compute disks delete ${DISKNAME} --zone ${ZONE}
|
||||
if ! gcloud compute disks delete ${DISKNAME} --zone ${ZONE}; then
|
||||
echo "Failed to delete disk."
|
||||
FAIL=1
|
||||
fi
|
||||
|
||||
for i in ${PATHS}; do
|
||||
echo "Uploading tar'ed disk image to ${i}..."
|
||||
gsutil -o GSUtil:parallel_composite_upload_threshold=100M cp root.tar.gz ${i}
|
||||
LOGDEST="${i}.exporter.log"
|
||||
echo "Uploading exporter log to ${LOGDEST}..."
|
||||
gsutil -h "Content-Type:text/plain" cp /var/log/daemon.log ${LOGDEST}
|
||||
if ! gsutil -o GSUtil:parallel_composite_upload_threshold=100M cp root.tar.gz ${i}; then
|
||||
echo "Failed to upload image to ${i}."
|
||||
FAIL=1
|
||||
fi
|
||||
done
|
||||
|
||||
Exit ${FAIL}
|
||||
`
|
||||
|
|
Loading…
Reference in New Issue