# 新しいインポートスクリプト作成中のデータベースクリーンアップ

**URL:** <https://meta.discourse.org/t/database-cleanup-while-writing-a-new-import-script/94134>\
**Category:** Development\
**Created:** [2018 年 8 月 7 日午後 4:59 UTC](https://meta.discourse.org/t/database-cleanup-while-writing-a-new-import-script/94134 "2018-08-07T16:59:17Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)\
**Post date:** [2018 年 8 月 7 日午後 7:40 UTC](https://meta.discourse.org/t/database-cleanup-while-writing-a-new-import-script/94134/5 "2018-08-07T19:40:37Z")

</div>

That’s what I usually do as well. 😉  
I have scripts for that too.

**backup**

```bash
#!/bin/bash

BACKUP_NAME=${1:-development}

mkdir -p /data/backups/discourse
pg_dump -d discourse_development -F c -b -v -f /data/backups/discourse/${BACKUP_NAME}.backup

```

**restore**

```bash
#!/bin/bash

BACKUP_NAME=${1:-development}

cd /data/backups/discourse

cd ~/Repositories/discourse
rm -R public/upload/*
rm -R public/backups/default/*
rm -R tmp/*
rm -R log/*

# close all connections because I usually forget to disconnect something...
psql -d postgres -c "SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = 'discourse_development' AND pid <> pg_backend_pid();"

redis-cli flushall

bundle install
bundle exec rake db:drop db:create

pg_restore -d discourse_development -v /data/backups/discourse/${BACKUP_NAME}.backup
bundle exec rake db:migrate

```

---

_[View the full topic](https://meta.discourse.org/t/database-cleanup-while-writing-a-new-import-script/94134)._
