0

I have the code that you can see below. I'm trying to go first to the directory and then,with the pipe "|" make a backup of the MongoDB´s database.The problem is that when I launch the script the console returns me

mongodump is not an internal or external command.

On the other hand,if I launch the same line

cd C:\\...\\MongoDB\\Server\\3.6\\bin | mongodump -h ip -d database name -o C:\\Users\\...\\Desktop\\BackUpMongo

in my system cmd it works without problems. Any idea?

import sys
import os

if __name__ == '__main__':

try:

    os.system('cd C:\\...\\MongoDB\\Server\\3.6\\bin | mongodump -h ip -d database name -o C:\\Users\\...\\Desktop\\BackUpMongo')


    print("Copia de seguridad finalizada")

except:
    print("Error during data base backup")


sys.exit(0)
teeyo
  • 3,665
  • 3
  • 22
  • 37
Jonan87
  • 31
  • 2
  • 6
  • Have you tried using `&` or `&&` instead of `|`? See https://stackoverflow.com/questions/8055371/how-do-i-run-two-commands-in-one-line-in-windows-cmd – Matthias Fripp Feb 21 '18 at 16:42

1 Answers1

0

Use os.chdir() instead of os.system('cd ...').

import os

os.chdir('C:\\...\\MongoDB\\Server\\3.6\\bin')
os.system('mongodump -h ip -d database name -o C:\\Users\\...\\Desktop\\BackUpMongo')

print("Copia de seguridad finalizada")
AboodXD
  • 148
  • 9