[英]how to periodically dump a set of database tables to a local machine from a psql database in a single bash script run on Mac OS X?
I tried this but it does not work. 我试过了,但是没有用。
#!/bin/bash
TABLENAMES="user_stats"
ssh -t railsapps@xxx.xxx.xxx.xx -p xxx bash -c "'
for TABLENAME in $TABLENAMES
do
psql -d mydb -P format=unaligned -P tuples_only -P fieldsep=\, -c "SELECT * FROM $TABLENAME" > /tmp/$TABLENAME
done
'"
You should use the Postgres COPY command, and stuff them all in to a single sql file, that you then run with psql
. 您应该使用Postgres COPY命令,并将它们全部填充到一个sql文件中,然后使用
psql
运行该文件。 Then you can take that script and either feed it to cron
on Mac OS X, or launchd
to run the script periodically. 然后,您可以获取该脚本并将其提供给Mac OS X上的
cron
,或者launchd
以定期运行该脚本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.