neomigrate 2.29 KB
Newer Older
1
#! /usr/bin/env python2.4
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#
# neomaster - run a master node of NEO
#
# Copyright (C) 2006  Nexedi SA
# 
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

from optparse import OptionParser
import logging
import time
import os

26
from neo import setupLog
27 28 29 30 31 32 33

# register options
parser = OptionParser()
parser.add_option('-v', '--verbose', action = 'store_true', 
                  help = 'print verbose messages')
parser.add_option('-s', '--source', help = 'the source database')
parser.add_option('-d', '--destination', help = 'the destination database')
34
parser.add_option('-c', '--cluster', help = 'the NEO cluster name')
35 36 37 38 39

# parse options
(options, args) = parser.parse_args()
source = options.source or None
destination = options.destination or None
40
cluster = options.cluster or None
41 42 43 44

# check options
if source is None or destination is None:
    raise RuntimeError('Source and destination databases must be supplied')
Grégory Wisniewski's avatar
Grégory Wisniewski committed
45
if cluster is None:
46 47 48
    raise RuntimeError('The NEO cluster name must be supplied')

# set up logging
49
setupLog('neomigrate', None, options.verbose or False)
50 51

# open storages
52 53 54
from ZODB.FileStorage import FileStorage
#from ZEO.ClientStorage import ClientStorage as ZEOStorage
from neo.client.Storage import Storage as NEOStorage
55 56
if os.path.exists(source):
    src = FileStorage(file_name=source)
57
    dst = NEOStorage(master_nodes=destination, name=cluster)
58
else:
59
    src = NEOStorage(master_nodes=source, name=cluster)
60 61 62 63 64 65 66 67 68
    dst = FileStorage(file_name=destination)

# do the job
print "Migrating from %s to %s" % (source, destination)
start = time.time()
dst.copyTransactionsFrom(src, verbose=0)
elapsed = time.time() - start
print "Migration done in %3.5f" % (elapsed, )