Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
241782 views
1
#################################################################################
2
#
3
# (c) Copyright 2010 William Stein
4
#
5
# This file is part of PSAGE
6
#
7
# PSAGE is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation, either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# PSAGE is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
#
20
#################################################################################
21
22
23
"""
24
This module defines a light wrapper around a MongoDB collection in the
25
MFDB database.
26
"""
27
28
class Collection:
29
def __init__(self, collection, db):
30
self.collection = collection
31
self.db = db
32
33
def backup(self, outdir=None):
34
"""Dump this collection to outdir. If outdir is None,
35
dumps to backup/year-month-day-hour-minute."""
36
import os
37
if outdir is None:
38
import time
39
outdir = os.path.join('backup',time.strftime('%Y%m%d-%H%M'))
40
cmd = 'time mongodump -c "%s" -h %s:%s -d mfdb -o "%s"'%(
41
self.collection.name, self.db.host, self.db.port, outdir)
42
print cmd
43
os.system(cmd)
44
45
def find(self, *args, **kwds):
46
"""Perform a query on the collection. See the help for self.collection.find."""
47
return self.collection.find(*args, **kwds)
48
49
50