prefix=@prefix@
# Include utilities. Use installed version if available and
# use build version if it isn't.
-if [ -e @datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh ]; then
+if [ -e "@datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh" ]; then
. @datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh
else
. @abs_top_builddir@/src/bin/admin/admin-utils.sh
# Need a path for temporary files created during upgrade data migration
# Use the state directory in the install path directory if it exists, otherwise
# use the build tree
-if [ -e @localstatedir@/@PACKAGE_NAME@ ]; then
+if [ -e "@localstatedir@/@PACKAGE_NAME@" ]; then
temp_file_dir="@localstatedir@/@PACKAGE_NAME@"
else
temp_file_dir="@abs_top_builddir@/src/share/database/scripts/cql"
-- This line concludes database upgrade to version 3.0
EOF
- if [ $? -ne 0 ]
+ if [ "$?" -ne 0 ]
then
echo Schema udpate FAILED!
- exit -1
+ exit 1
fi
}
# Function to delete temporary migration files
clean_up() {
# clean up the files
- if [ -e $export_file ]
+ if [ -e "$export_file" ]
then
rm $export_file
fi
- if [ -e $update_file ]
+ if [ -e "$update_file" ]
then
rm $update_file
fi
explanation=$1
clean_up
- if [ $status -eq 0 ]
+ if [ "$status" -eq 0 ]
then
echo "Data Migration SUCCESS! $explanation"
else
TO '$export_file'"
cqlsh $cqlargs -e "$query"
- if [ $? -ne 0 ]
+ if [ "$?" -ne 0 ]
then
- exit_now -1 "Cassandra export failed! Could not migrate data!"
+ exit_now 1 "Cassandra export failed! Could not migrate data!"
+ fi
+
+ # Strip the carriage returns that CQL insists on adding.
+ if [ -e "$export_file" ]
+ then
+ cat $export_file | tr -d '\015' > $export_file.2
+ mv $export_file.2 $export_file
+ else
+ # Shouldn't happen but then again we're talking about CQL here
+ exit_now 1 "Cassandra export file $export_file is missing?"
fi
# Iterate through the exported data, accumulating update statements,
while read line
do
- let line_cnt++;
+ line_cnt=$((line_cnt + 1));
update_cols=""
xIFS="$IFS"
- IFS=$'\r,'
+ IFS=$','
+
i=1
# Parse the column values
for val in $line
;;
*)
# We're going to assume that since any error is fatal
- exit_now -1 "Line# $line_cnt, too many values, wrong or corrupt file"
+ exit_now 1 "Line# $line_cnt, too many values, wrong or corrupt file"
;;
esac
- let i++
+ i=$((i + 1))
done
- if [ $i -ne 5 ]
+ if [ "$i" -ne 5 ]
then
# We're going to assume that since any error is fatal
- exit_now -1 "Line# $line_cnt, too few values, wrong or corrupt file"
+ exit_now 1 "Line# $line_cnt, too few values, wrong or corrupt file"
fi
# If any of the current host's columns need to be replace, append an update for it
if [ ! -z "$update_cols" ]
then
echo "update host_reservations set $update_cols where id = $host_id;" >> $update_file
- let update_cnt++
+ update_cnt=$((update_cnt + 1))
fi
IFS="$xIFS"
done < $export_file
# If we didn't record any updates, then hey, we're good to go!
- if [ $update_cnt == 0 ]
+ if [ "$update_cnt" -eq 0 ]
then
exit_now 0 "Completed successfully: No updates were needed"
fi
echo "$update_cnt update statements written to $update_file"
echo "Running the updates..."
cqlsh $cqlargs -f "$update_file"
- if [ $? -ne 0 ]
+ if [ "$?" -ne 0 ]
then
- exit_now -1 "Cassandra updates failed"
- exit -1
+ exit_now 1 "Cassandra updates failed"
fi
exit_now 0 "Updated $update_cnt of $line_cnt records"