mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-08 02:10:24 +00:00
Add data migration script from sqlite to mysql
This commit is contained in:
31
batch-delete.py
Normal file
31
batch-delete.py
Normal file
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
import settings
|
||||
|
||||
try:
|
||||
dbname = os.environ['DBNAME']
|
||||
dbuser = os.environ['DBUSER']
|
||||
dbpasswd = os.environ['DBPASSWD']
|
||||
except:
|
||||
print 'Environment not set! Exit'
|
||||
sys.exit(1)
|
||||
|
||||
def do_delete(prefix):
|
||||
cmd = ('echo "select concat(\'drop table \', table_name ,\';\') from TABLES where TABLE_SCHEMA =\'%s\' and table_name like \'%s_%%\' ;" | mysql -u %s -p%s information_schema | sed -n \'2,$p\' | mysql -u %s -p%s %s') % (dbname, prefix, dbuser, dbpasswd, dbuser, dbpasswd, dbname)
|
||||
try:
|
||||
output = os.popen(cmd).read()
|
||||
except:
|
||||
pass
|
||||
|
||||
if __name__=="__main__":
|
||||
for app in settings.INSTALLED_APPS:
|
||||
app_name = app.split('.')[-1]
|
||||
do_delete(app_name)
|
||||
|
||||
do_delete('django')
|
||||
|
||||
print '[Delete seahub tables...Done]'
|
||||
|
36
sqlite-to-mysql.sh
Executable file
36
sqlite-to-mysql.sh
Executable file
@@ -0,0 +1,36 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Before run the script, you should have created seafile-meta
|
||||
# database.
|
||||
# Choose NO when promote to create superuser.
|
||||
|
||||
# The python path. Change to your path
|
||||
export PYTHONPATH=/usr/lib/python2.6/site-packages:thirdpart
|
||||
|
||||
# The database configuration. Change to your config
|
||||
export DBNAME='seafile-meta'
|
||||
export DBUSER='seafile-user'
|
||||
export DBPASSWD='seafile'
|
||||
|
||||
# Delete the exist seahub tables in database
|
||||
python batch-delete.py
|
||||
if [ $? -eq 1 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
DUMP_FILE='dump_seahub.json'
|
||||
SETTINGS_COPY='mysqlsettings.py'
|
||||
SETTINGS_MODULE='mysqlsettings'
|
||||
|
||||
|
||||
cp settings.py $SETTINGS_COPY
|
||||
sed -i "/DATABASE_ENGINE/c\DATABASE_ENGINE = 'mysql'" $SETTINGS_COPY
|
||||
sed -i "/DATABASE_NAME/c\DATABASE_NAME = '$DBNAME'" $SETTINGS_COPY
|
||||
sed -i "/DATABASE_USER/c\DATABASE_USER = '$DBUSER'" $SETTINGS_COPY
|
||||
sed -i "/DATABASE_PASSWORD/c\DATABASE_PASSWORD = '$DBPASSWD'" $SETTINGS_COPY
|
||||
|
||||
./manage.py syncdb --settings=$SETTINGS_MODULE
|
||||
|
||||
./manage.py dumpdata > $DUMP_FILE --settings=settings && ./manage.py loaddata $DUMP_FILE --settings=$SETTINGS_MODULE && echo '[DONE]' || echo '[FAILED]'
|
||||
|
||||
rm $DUMP_FILE $SETTINGS_COPY 2> /dev/null
|
Reference in New Issue
Block a user