gpt4 book ai didi

python - python中的增量postgresql数据转储

转载 作者:行者123 更新时间:2023-11-29 13:54:19 28 4
gpt4 key购买 nike

我已经返回了一个 python 脚本来获取特定表的 postgresql 数据库转储,我怎样才能有一天将特定表的转储或增量数据转储到 .sql 文件。

username = 'postgres'
port = 5432
date = time.strftime('%Y-%m-%d')

base = 'databasename'
if base == 'databasename':

filename = "%s/%s-%s.sql" % (fulldir, base, date)

os.popen("nice -n 19 pg_dump -C -t table1 -t table2 -t table3 -t table4 -F p -U%s -p%s %s > %s" % (username, port, base, filename))
print(base + "backup taken")

最佳答案

您可以将此 python 制作为可执行文件,然后打开您的 linux 终端并使用 corntab -e 命令编辑 crontab 并将命令放在那里

30 23 * * * your_executable_file_name

这将在服务器时间的每天晚上 11:30 进行备份。希望这对您有所帮助。

关于python - python中的增量postgresql数据转储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35124062/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com