我正在编写一个shell脚本(将成为一个cronjob),它将:
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
Run Code Online (Sandbox Code Playgroud)