mirror of
https://github.com/NovaOSS/nova-api.git
synced 2024-11-25 14:33:57 +01:00
Removed local from backups
This commit is contained in:
parent
4673b23055
commit
453c6e7430
|
@ -4,7 +4,7 @@
|
|||
# git commit -am "Auto-trigger - Production server started" && git push origin Production
|
||||
|
||||
# backup database
|
||||
/usr/local/bin/python /home/nova-api/backup_manager/main.py pre_prodpush
|
||||
/usr/local/bin/python /home/nova-api/api/backup_manager/main.py pre_prodpush
|
||||
|
||||
# Kill production server
|
||||
fuser -k 2333/tcp
|
||||
|
|
|
@ -1,21 +1,22 @@
|
|||
from dotenv import load_dotenv
|
||||
import os
|
||||
from motor.motor_asyncio import AsyncIOMotorClient
|
||||
from bson import json_util
|
||||
import json
|
||||
from sys import argv
|
||||
import asyncio
|
||||
|
||||
from sys import argv
|
||||
from bson import json_util
|
||||
from dotenv import load_dotenv
|
||||
from motor.motor_asyncio import AsyncIOMotorClient
|
||||
|
||||
load_dotenv()
|
||||
|
||||
MONGO_URI = os.getenv("MONGO_URI")
|
||||
MONGO_URI = os.environ['MONGO_URI']
|
||||
FILE_DIR = os.path.dirname(os.path.realpath(__file__))
|
||||
|
||||
async def main(output_dir):
|
||||
async def main(output_dir: str):
|
||||
await make_backup(output_dir)
|
||||
|
||||
async def make_backup(output_dir):
|
||||
output_dir = os.path.join(FILE_DIR, "..", "backups", output_dir)
|
||||
async def make_backup(output_dir: str):
|
||||
output_dir = os.path.join(FILE_DIR, '..', 'backups', output_dir)
|
||||
|
||||
if not os.path.exists(output_dir):
|
||||
os.makedirs(output_dir)
|
||||
|
@ -25,26 +26,29 @@ async def make_backup(output_dir):
|
|||
databases = {db: await client[db].list_collection_names() for db in databases}
|
||||
|
||||
for database in databases:
|
||||
if not os.path.exists(f"{output_dir}/{database}"):
|
||||
os.mkdir(f"{output_dir}/{database}")
|
||||
if database == 'local':
|
||||
continue
|
||||
|
||||
if not os.path.exists(f'{output_dir}/{database}'):
|
||||
os.mkdir(f'{output_dir}/{database}')
|
||||
|
||||
for collection in databases[database]:
|
||||
print(f"Making backup for {database}/{collection}")
|
||||
print(f'Making backup for {database}/{collection}')
|
||||
await make_backup_for_collection(database, collection, output_dir)
|
||||
|
||||
async def make_backup_for_collection(database, collection, output_dir):
|
||||
path = f"{output_dir}/{database}/{collection}.json"
|
||||
path = f'{output_dir}/{database}/{collection}.json'
|
||||
|
||||
client = AsyncIOMotorClient(MONGO_URI)
|
||||
collection = client[database][collection]
|
||||
documents = await collection.find({}).to_list(length=None)
|
||||
|
||||
with open(path, "w") as f:
|
||||
with open(path, 'w') as f:
|
||||
json.dump(documents, f, default=json_util.default)
|
||||
|
||||
if __name__ == "__main__":
|
||||
if __name__ == '__main__':
|
||||
if len(argv) < 2 or len(argv) > 2:
|
||||
print("Usage: python3 main.py <output_dir>")
|
||||
print('Usage: python3 main.py <output_dir>')
|
||||
exit(1)
|
||||
|
||||
output_dir = argv[1]
|
||||
|
|
|
@ -217,8 +217,8 @@ async def demo():
|
|||
print('Checking streamed chat completions...')
|
||||
print(await test_chat_stream_gpt3())
|
||||
|
||||
print('[lightblue]Checking if image generation works...')
|
||||
print(await test_image_generation())
|
||||
# print('[lightblue]Checking if image generation works...')
|
||||
# print(await test_image_generation())
|
||||
|
||||
print('Checking the models endpoint...')
|
||||
print(await test_models())
|
||||
|
|
Loading…
Reference in a new issue