print 'restore db1'
run_command('pg_restore -i -h localhost -p 5432 -U postgres -d db1 -v "/var/lib/project/backup/db1.backup" -c')
print '--- wait 3 seconds'
time.sleep(3)
print 'restore db2'
run_command('pg_restore -i -h localhost -p 5432 -U postgres -d db2 -v "/var/lib/project/backup/db2.backup" -c')
print '--- wait 3 seconds'
time.sleep(3)
print 'restoring mongodb'
run_command('/var/lib/project/bbds/mongodb-linux/bin/mongorestore /var/lib/project/backup/dump --drop')
print '--- wait 3 seconds'
time.sleep(3)
我的run_command
基本上取自this .
在我的控制台上:
python ignition.py --load-fixtures
For safety, this process will run for about one minute.
setup LDAP
restore db1
['pg_restore', '-i', '-h', 'localhost', '-p', '5432', '-U', 'postgres', '-d', 'db1', '-v', '/var/lib/project/backup/db1.backup', '-c']
Password:
输入密码后就卡住了。之后什么也没有发生。我不确定资源是否繁忙。 pg_restore
仍在根据 ps au|grep pg_restore
运行,而 mongorestore
则未运行。所以一定要坚持第一次恢复。我也不认为内存已满,因为我的虚拟机只有 512mb,而且它总是满的,并且总是使用交换内存。
我们如何知道它在做什么?有时它会卡在恢复 mongo 上。所以所有这些操作都会导致问题。 我应该如何解决这个问题?
谢谢。
当我杀死进程时,我得到了这个回溯:http://pastebin.com/Cnv9P6HW 重新启动将“解决”问题。它将允许我毫无问题地运行脚本。但这并不稳定。有时我们最终会陷入困境。
最佳答案
您对 pg_restore
和 mongorestore
的使用似乎是独立的。我会尝试:
- 直接从命令行运行每个命令(即不通过 Python
do_command()
) - 将它们放入单独的脚本中,以便您可以找出哪个命令挂起
您提到的只有 512MB RAM 并且始终使用交换表明此虚拟机上没有足够的可用内存。 “卡住”到底是什么意思?如果虚拟机实际上被卡住并需要重新启动,那么它很可能已经耗尽了 RAM 和交换空间。如果您仍然可以登录,但恢复脚本的运行时间似乎比预期的时间长,我会尝试使用 performance monitoring tools 了解资源使用情况例如 iostat
和 vmstat
。
关于python - 有时我的 pg_restore 或 mongorestore 会卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11196175/