我正在编写一个 shell 脚本(将成为一个骗子) ,它将:
1: 转储我的生产数据库
2: 将转储导入到我的开发数据库中
在步骤1和步骤2之间,我需要清除开发数据库(删除所有表?).如何通过 shell 脚本最好地实现这一点?到目前为止,它看起来是这样的:
#!/bin/bash
time=`date '+%Y'-'%m'-'%d'`
# 1. export(dump) the current production database
pg_dump -U production_db_name > /backup/dir/backup-${time}.sql
# missing step: drop all tables from development database so it can be re-populated
# 2. load the backup into the development database
psql -U development_db_name < backup/dir/backup-${time}.sql