|
a/scripts/backup_project.py |
|
b/scripts/backup_project.py |
|
... |
|
... |
62 |
cls, fqname, visited_collections[fqname])
|
62 |
cls, fqname, visited_collections[fqname])
|
63 |
continue
|
63 |
continue
|
64 |
visited_collections[fqname] = cls
|
64 |
visited_collections[fqname] = cls
|
65 |
if 'project_id' in m.property_index:
|
65 |
if 'project_id' in m.property_index:
|
66 |
# Dump the things directly related to the project
|
66 |
# Dump the things directly related to the project
|
67 |
oq = cls.query.find(dict(project_id=project._id), validate=False)
|
67 |
oq = dict(project_id=project._id)
|
68 |
elif 'app_config_id' in m.property_index:
|
68 |
elif 'app_config_id' in m.property_index:
|
69 |
# ... and the things related to its apps
|
69 |
# ... and the things related to its apps
|
70 |
oq = cls.query.find(dict(app_config_id={'$in':app_config_ids}), validate=False)
|
70 |
oq = dict(app_config_id={'$in':app_config_ids})
|
71 |
else:
|
71 |
else:
|
72 |
# Don't dump other things
|
72 |
# Don't dump other things
|
73 |
continue
|
73 |
continue
|
74 |
num_objs = oq.count()
|
74 |
num_objs = cls.query.find(oq).count()
|
75 |
if num_objs == 0: continue
|
75 |
if num_objs == 0: continue
|
76 |
if not os.path.exists(os.path.join(dirname, dbname)):
|
76 |
if not os.path.exists(os.path.join(dirname, dbname)):
|
77 |
os.mkdir(os.path.join(dirname, dbname))
|
77 |
os.mkdir(os.path.join(dirname, dbname))
|
78 |
fname = os.path.join(
|
78 |
fname = os.path.join(
|
79 |
dirname,
|
79 |
dirname,
|
80 |
dbname,
|
80 |
dbname,
|
81 |
'%s.bson' % (cls.__mongometa__.name))
|
81 |
'%s.bson' % (cls.__mongometa__.name))
|
82 |
log.info('%s: dumping %s objects to %s',
|
82 |
log.info('%s: dumping %s objects to %s',
|
83 |
cname, num_objs, fname)
|
83 |
cname, num_objs, fname)
|
84 |
with open(os.path.join(dirname, fname), 'w') as fp:
|
84 |
with open(os.path.join(dirname, fname), 'w') as fp:
|
85 |
for obj in oq.ming_cursor: _write_bson(fp, obj)
|
85 |
for obj in cls.query.find(oq, validate=False).ming_cursor: _write_bson(fp, obj)
|
86 |
|
86 |
|
87 |
if __name__ == '__main__':
|
87 |
if __name__ == '__main__':
|
88 |
sys.exit(main())
|
88 |
sys.exit(main())
|