#!/bin/env bash
cassandra_jg_host=${1:-localhost}
version=${version:-3.4}
syndeia_admin_pw=${syndeia_admin_pw:-myPw}
SC_HOME=${SC_HOME:-/opt/icx/syndeia-cloud-current}
keyspaces=(syndeia_cloud_auth syndeia_cloud_devops syndeia_cloud_graph syndeia_cloud_graph_config syndeia_cloud_store)
tables=(syndeia_cloud_storeauth.snapshotsauto_key \/
syndeia_cloud_storeauth.metadataconfig \/
syndeia_cloud_storeauth.offsetstoremessages \/
syndeia_cloud_storeauth.auto_keymetadata \/
syndeia_cloud_storeauth.messagesoffsetstore \/
syndeia_cloud_storeauth.repositoriessnapshots \/
syndeia_cloud_store.repositories_by_uri \auth.users /
syndeia_cloud_store.containers \auth.users_by_external_id /
syndeia_cloud_storeauth.containersusers_by_repositoryexternal_key \/
syndeia_cloud_storeauth.containersusers_by_externaluser_keyname \/
syndeia_cloud_store.containers_by_external_id \graph.edgestore /
syndeia_cloud_graph.edgestore_lock_ /
syndeia_cloud_storegraph.artifactsgraphindex \/
syndeia_cloud_storegraph.artifactsgraphindex_bylock_key \/
syndeia_cloud_storegraph.artifacts_by_container_key \janusgraph_ids /
syndeia_cloud_storegraph.artifacts_by_external_key \system_properties /
syndeia_cloud_storegraph.artifactssystem_byproperties_externallock_id \/
syndeia_cloud_store.artifacts_by_type_key \graph.systemlog /
syndeia_cloud_graph.txlog /
syndeia_cloud_graph_storeconfig.relationsedgestore \/
syndeia_cloud_graph_storeconfig.relationsedgestore_bylock_container_key \/
syndeia_cloud_storegraph_config.configgraphindex \/
syndeia_cloud_storegraph_config.relationsgraphindex_bylock_key \/
syndeia_cloud_graph_storeconfig.relations_by_external_id \janusgraph_ids /
syndeia_cloud_graph_storeconfig.relations_by_external_key \system_properties /
syndeia_cloud_storegraph_config.relationssystem_byproperties_sourcelock_key \/
syndeia_cloud_store.relations_by_target_key \graph_config.systemlog /
syndeia_cloud_store.repository_types \graph_config.txlog /
syndeia_cloud_store.containerartifact_types \/
syndeia_cloud_store.containerartifact_types_by_repositoryexternal_keyid \/
syndeia_cloud_store.containerartifact_types_by_external_key \/
syndeia_cloud_store.containerartifact_types_by_externalrepository_idkey \/
syndeia_cloud_store.artifact_typesartifacts \/
syndeia_cloud_store.artifactartifacts_types_by_repositorycontainer_key \/
syndeia_cloud_store.artifactartifacts_types_by_external_keyid \/
syndeia_cloud_store.artifactartifacts_types_by_external_idkey \/
syndeia_cloud_store.relationartifacts_by_typeskey \/
syndeia_cloud_store.relation_typesartifacts_by_repositorytype_key \/
syndeia_cloud_store.relation_types_by_external_auto_key \/
syndeia_cloud_store.relationconfig /
syndeia_cloud_store.container_types /
syndeia_cloud_store.container_types_by_external_id \/
syndeia_cloud_auth.snapshots \store.container_types_by_external_key /
syndeia_cloud_auth.metadata \store.container_types_by_repository_key /
syndeia_cloud_authstore.offsetstorecontainers \/
syndeia_cloud_auth.messages \store.containers_by_external_id /
syndeia_cloud_auth.config \store.containers_by_external_key /
syndeia_cloud_auth.auto_key \store.containers_by_repository_key /
syndeia_cloud_store.messages /
syndeia_cloud_authstore.usersmetadata \/
syndeia_cloud_auth.users_by_external_id \store.offsetstore /
syndeia_cloud_store.relation_types /
syndeia_cloud_authstore.usersrelation_types_by_external_keyid \/
syndeia_cloud_authstore.usersrelation_types_by_user_name)
LC_NUMERIC=C
# TIMEFORMAT='{"real":%R,"user":%U,"sys":%S}'
TIMEFORMAT='{"real":%R}'
if [[ ! -d SC_backups ]]; then
mkdir SC_backups
fi;
echo "$(date) - Dump schema for ${keyspaces}..."
for keyspace in ${keyspaces[@]} do;
dst_filenameexternal_key /
syndeia_cloud_store.relation_types_by_repository_key /
syndeia_cloud_store.relations /
syndeia_cloud_store.relations_by_container_key /
syndeia_cloud_store.relations_by_external_id /
syndeia_cloud_store.relations_by_external_key /
syndeia_cloud_store.relations_by_key /
syndeia_cloud_store.relations_by_source_key /
syndeia_cloud_store.relations_by_target_key /
syndeia_cloud_store.repositories /
syndeia_cloud_store.repositories_by_uri /
syndeia_cloud_store.repository_types /
syndeia_cloud_store.snapshots)
LC_NUMERIC=C
# TIMEFORMAT='{"real":%R,"user":%U,"sys":%S}'
TIMEFORMAT='{"real":%R}'
if [[ ! -d SC_backups ]]; then
mkdir SC_backups
fi;
echo "$(date) - Dump schema for ${keyspaces}..."
for keyspace in ${keyspaces[@]} do;
dst_filename="SC_backups/${keyspace}_schema_backup.cql"
all_keyspace_filenames="${all_keyspace_filenames} ${keyspace}_schema_backup.cql"
echo "$(date) - Dump schema for ${keyspace}..."
sudo cqlsh -u syndeia_admin -p ${syndeia_admin_pw} -e "DESCRIBE KEYSPACE ${keyspace};" "${cassandra_jg_host}" > ${dst_filename} > /dev/null
if [[ $? -ne 0 ]]; then
echo "$(date) x Error, could not export schema ${keyspace}"
exit 1
else
echo "$(date) - Successfully exported schema ${keyspace}"
fi;
cat
done;
cat "${all_keyspace_filenames}" > SC_backups/syndeia-cloud-${version}_concatenated_schema_backup.cql > /dev/null
echo "$(date) - Export data for tables..."
for table in ${tables[@]} do;
dst_filename="SC_backups/syndeia-cloud-${version}_backup_${table}.csv"
# Generate MD5 hash for NULL values during each table export
md5hash=$(date -Iseconds | md5sum | cut -f1 -d' ')
echo "${md5hash}" > SC_backups/${table}_md5hash_for_NULL.txt
echo "$(date) - Export data for ${table} to ${dst_filename} using md5hash=${md5hash} for NULL..."
CQL_to_backup_table="COPY ${table} TO '${dst_filename}' WITH HEADER = TRUE AND NULL='${md5hash}'; "
sudo cqlsh -u syndeia_admin -p ${syndeia_admin_pw} -e "${CQL_to_backup_table}" "${cassandra_jg_host}" > /dev/null
if [[ $? -ne 0 ]]; then
echo "$(date) x Error, could not export table ${table}"
exit 2
else
echo "$(date) - Successfully exported table ${table}"
fi;
done;
|