From 25b70fd25a29aab6fde50f00335f3580585ab781 Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Thu, 15 May 2014 14:11:58 -0700 Subject: [PATCH] add restoredb and evolvedb, rename upgradedb to repairdb, remove runserver from everything but the runserver command --- planetstack/scripts/opencloud | 36 +++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/planetstack/scripts/opencloud b/planetstack/scripts/opencloud index 88a8d88..5093c4d 100755 --- a/planetstack/scripts/opencloud +++ b/planetstack/scripts/opencloud @@ -45,6 +45,10 @@ function syncdb { echo "Syncing OpenCloud services..." python /opt/planetstack/manage.py syncdb --noinput } +function evolvedb { + echo "Syncing OpenCloud services..." + python /opt/planetstack/manage.py evolve --hint --execute --noinput +} function stopserver { echo "Stopping any running OpenCloud Service(s)" pkill -f "python.*runserver" @@ -63,6 +67,12 @@ function dumpdata { echo "FAILED to create $FN" exit fi + SIZE=$(du -k "$FN" | cut -f 1) + if [[ $SIZE -lt 9 ]]; then + echo "Dumpdata was empty. Deleting and aborting" + rm $FN + exit + fi rm -f $BACKUP_DIR/dumpdata-latest.json ln -s $FN $BACKUP_DIR/dumpdata-latest.json } @@ -74,32 +84,46 @@ if [ "$COMMAND" = "initdb" ]; then ensure_postgres_running createdb syncdb - runserver fi -if [ "$COMMAND" = "upgradedb" ]; then +if [ "$COMMAND" = "repairdb" ]; then stopserver ensure_postgres_running dumpdata - # TODO: This is where we would run migration scripts to upgrade the + # TODO: This is where we could run migration scripts to upgrade the # dumped data to the new models. mv /opt/planetstack/core/fixtures/initial_data.json /opt/planetstack/core/fixtures/initial_data.json-old cp $BACKUP_DIR/dumpdata-latest.json /opt/planetstack/core/fixtures/initial_data.json dropdb createdb syncdb - runserver +fi +if [ "$COMMAND" = "restoredb" ]; then + if [[ ! -f $BACKUP_DIR/dumpdata-latest.json ]]; then + echo There is no dumpdata to restore + exit + fi + stopserver + ensure_postgres_running + mv /opt/planetstack/core/fixtures/initial_data.json /opt/planetstack/core/fixtures/initial_data.json-old + cp $BACKUP_DIR/dumpdata-latest.json /opt/planetstack/core/fixtures/initial_data.json + dropdb + createdb + syncdb +fi +if [ "$COMMAND" = "evolvedb" ]; then + stopserver + ensure_postgres_running + evolvedb fi if [ "$COMMAND" = "resetdb" ]; then stopserver dropdb createdb syncdb - runserver fi if [ "$COMMAND" = "syncdb" ]; then stopserver syncdb - runserver fi if [ "$COMMAND" = "runserver" ]; then stopserver -- 2.43.0