Skip to content

Instantly share code, notes, and snippets.

@PeloNZ
Created July 31, 2015 13:19
Show Gist options
  • Save PeloNZ/1f637fc8315cdbb4bc23 to your computer and use it in GitHub Desktop.
Save PeloNZ/1f637fc8315cdbb4bc23 to your computer and use it in GitHub Desktop.
#!/bin/bash
# copy moodle database
set -x
set -e
if [ $1 ] ; then
DBFROM=$1
fi
if [ $2 ]; then
DBTO=$2
fi
# shrink tables
psql -ec "TRUNCATE mdl_log, mdl_backup_logs, mdl_tool_sync_preprocess_report, mdl_totara_sync_log;" $DBFROM
# drop connections
psql -ec "SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname IN ('$DBFROM', '$DBTO') AND pid <> pg_backend_pid();" postgres
dropdb $DBTO
createdb -T $DBFROM -O $DTO $DBTO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment