Created
July 31, 2015 13:19
-
-
Save PeloNZ/1f637fc8315cdbb4bc23 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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