Compare commits

...

14 Commits

Author SHA1 Message Date
Alexey Skobkin c0329f8727
Updating magneticod-postgresql fork. 2019-10-20 16:17:47 +03:00
Alexey Skobkin 19f386aafc
Adding Dockerfile. 2019-10-20 02:08:38 +03:00
Alexey Skobkin 3f0c3f61c5
Crashing on chunk retrieval fail. 2019-10-19 04:17:01 +03:00
Alexey Skobkin 3e601ea2cb
Fixing stupid memory leak caused by excessive pointer dereference. 2019-10-19 04:07:24 +03:00
Alexey Skobkin 64bd20e0bf
Optimizing data processing by separating old database data by chunks. 2019-10-19 03:01:07 +03:00
Alexey Skobkin 90d8005c9a
Functions for old database are moved to the separate package 'old'. 2019-10-19 02:07:10 +03:00
Alexey Skobkin a7b2344fce
Using "Full" progress bar template. 2019-10-19 01:10:37 +03:00
Alexey Skobkin 3418b70904
Using latest commit of skobkin/magnetico with beanstalkd support. 2019-10-19 00:37:20 +03:00
Alexey Skobkin 1d54d70328
Small fix in README.md. 2019-10-19 00:15:49 +03:00
Alexey Skobkin cc9ad9a1e6
Adding "Usage" section to the README.md. 2019-10-19 00:14:56 +03:00
Alexey Skobkin dcd778f472
Using my own form version with PostgreSQL and Beanstalk support. 2019-10-18 23:41:51 +03:00
Alexey Skobkin 5206d77fe7
Fixing bug which caused processing only one file per torrent. 2019-10-12 01:25:54 +03:00
Alexey Skobkin b4ab04cf5d
Small refactoring. 2019-10-12 00:46:14 +03:00
Alexey Skobkin 3994941210
Building slim binaries. Removing arch from binary name (amd64 only). Adding automatic release draft. 2019-10-09 02:13:55 +03:00
7 changed files with 278 additions and 87 deletions

View File

@ -1,31 +1,46 @@
image: "golang:1-alpine"
stages:
- build
- publish
before_script:
# Disabling cgo to not install gcc
- export CGO_ENABLED=0
- export GOARCH=amd64
build_linux_amd64:
stage: build
script:
- export GOOS=linux
- go build -o ./magnetico-go-migrator-$GOOS-$GOARCH .
- ./magnetico-go-migrator-$GOOS-$GOARCH --help
- go build -o ./magnetico-go-migrator-$GOOS "-ldflags=-s -w" .
- ./magnetico-go-migrator-$GOOS --help
artifacts:
paths:
- magnetico-go-migrator-*-*
- magnetico-go-migrator-*
build_windows_amd64:
stage: build
script:
- export GOOS=windows
- go build -o ./magnetico-go-migrator-$GOOS-$GOARCH .
- go build -o ./magnetico-go-migrator-$GOOS.exe "-ldflags=-s -w" .
artifacts:
paths:
- magnetico-go-migrator-*-*
- magnetico-go-migrator-*.exe
build_darwin_amd64:
stage: build
script:
- export GOOS=darwin
- go build -o ./magnetico-go-migrator-$GOOS-$GOARCH .
- go build -o ./magnetico-go-migrator-$GOOS "-ldflags=-s -w" .
artifacts:
paths:
- magnetico-go-migrator-*-*
- magnetico-go-migrator-*
#publish:
# image: inetprocess/gitlab-release
# stage: publish
# only:
# - tags
# script:
# - gitlab-release --message 'New release' magnetico-go-migrator-linux-$CI_BUILD_TAG magnetico-go-migrator-windows-$CI_BUILD_TAG.exe magnetico-go-migrator-darwin-$CI_BUILD_TAG

22
Dockerfile Normal file
View File

@ -0,0 +1,22 @@
FROM golang:1.13-alpine AS build
WORKDIR /migrator
RUN apk add --no-cache build-base curl git
ADD ./old /migrator/old
ADD ./go.mod /migrator/go.mod
ADD ./magnetico-migrator.go /migrator/magnetico-migrator.go
RUN go build "-ldflags=-s -w" -o /migrator/migrator .
FROM alpine:latest
LABEL maintainer="skobkin-ru@ya.ru"
WORKDIR /
VOLUME /data
COPY --from=build /migrator/migrator /migrator
ENTRYPOINT ["/migrator"]

View File

@ -6,10 +6,26 @@ This simple utility will help you to migrate your data from legacy
Python version of `magneticod` to the new Go version which uses new
persistence layer.
## Install
## Installation
TBW
## Run
## Usage
TBW
### Important notes:
- `--py-database` syntax is similar but not the same. But if you'll use just
`sqlite3://` schema and path to the database you'll be ok.
- `--go-database` you can use the same syntax as used in `magneticod` CLI interface.
### Merging with magneticod-go's PostgreSQL
```shell
./magnetico-go-migrator --py-database=sqlite3:///path/to/old/database.sqlite3 --go-database=postgres://username:password@hostname/db_name?port=5432&sslmode=disable
```
### Merging into magneticod-go's Beanstalk
```shell
./magnetico-go-migrator --py-database=sqlite3:///path/to/old/database.sqlite3 --go-database=beanstalk://127.0.0.1:11300/magneticod_tube
```

3
go.mod
View File

@ -5,9 +5,10 @@ go 1.12
require (
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
github.com/boramalper/magnetico v0.9.0
github.com/anacrolix/torrent v1.1.4
github.com/cheggaaa/pb/v3 v3.0.1
github.com/mattn/go-sqlite3 v1.10.0
github.com/skobkin/magnetico v0.7.3-0.20191020131325-8ae709a3b222
go.uber.org/zap v1.10.0
gopkg.in/alecthomas/kingpin.v2 v2.2.6
)

37
go.sum
View File

@ -1,5 +1,6 @@
bazil.org/fuse v0.0.0-20180421153158-65cc252bf669/go.mod h1:Xbm+BRKSBEpa4q4hTSxohYNQpsxXPbPry4JJWOB3LB8=
github.com/RoaringBitmap/roaring v0.4.7/go.mod h1:8khRDP4HmeXns4xIj9oGrKSz7XTQiJx2zgh7AcNke4w=
github.com/RoaringBitmap/roaring v0.4.17 h1:oCYFIFEMSQZrLHpywH7919esI1VSrQZ0pJXkZPGIJ78=
github.com/RoaringBitmap/roaring v0.4.17/go.mod h1:D3qVegWTmfCaX4Bl5CrBE9hfrSrrXIr8KVNvRsDi1NI=
github.com/VividCortex/ewma v1.1.1 h1:MnEK4VOv6n0RSY4vtRe3h11qjxL3+t0B8yOL8iMXdcM=
github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=
@ -10,35 +11,43 @@ github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2c
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
github.com/anacrolix/dht v0.0.0-20180412060941-24cbf25b72a4/go.mod h1:hQfX2BrtuQsLQMYQwsypFAab/GvHg8qxwVi4OJdR1WI=
github.com/anacrolix/dht v0.0.0-20181129074040-b09db78595aa/go.mod h1:Ayu4t+5TsHQ07/P8XzRJqVofv7lU4R1ZTT7KW5+SPFA=
github.com/anacrolix/dht v1.0.1 h1:a7zVMiZWfPiToAUbjMZYeI3UvmsDP3j8vH5EDIAjM9c=
github.com/anacrolix/dht v1.0.1/go.mod h1:dtcIktBFD8YD/7ZcE5nQuuGGfLxcwa8+18mHl+GU+KA=
github.com/anacrolix/dht/v2 v2.0.1/go.mod h1:GbTT8BaEtfqab/LPd5tY41f3GvYeii3mmDUK300Ycyo=
github.com/anacrolix/envpprof v0.0.0-20180404065416-323002cec2fa/go.mod h1:KgHhUaQMc8cC0+cEflSgCFNFbKwi5h54gqtVn8yhP7c=
github.com/anacrolix/go-libutp v0.0.0-20180522111405-6baeb806518d/go.mod h1:beQSaSxwH2d9Eeu5ijrEnHei5Qhk+J6cDm1QkWFru4E=
github.com/anacrolix/go-libutp v0.0.0-20180808010927-aebbeb60ea05 h1:Zoniih3jyqtr3I0xFoMvw1USWpg+CbI/zOrcLudr0lc=
github.com/anacrolix/go-libutp v0.0.0-20180808010927-aebbeb60ea05/go.mod h1:POY/GPlrFKRxnOKH1sGAB+NBWMoP+sI+hHJxgcgWbWw=
github.com/anacrolix/log v0.0.0-20180412014343-2323884b361d/go.mod h1:sf/7c2aTldL6sRQj/4UKyjgVZBu2+M2z9wf7MmwPiew=
github.com/anacrolix/log v0.1.0/go.mod h1:sf/7c2aTldL6sRQj/4UKyjgVZBu2+M2z9wf7MmwPiew=
github.com/anacrolix/log v0.2.0 h1:LzaW6XTEk2zcmLZkcZPkJ2mDdnZkOdOTeBH7Kt81ouU=
github.com/anacrolix/log v0.2.0/go.mod h1:sf/7c2aTldL6sRQj/4UKyjgVZBu2+M2z9wf7MmwPiew=
github.com/anacrolix/missinggo v0.0.0-20180522035225-b4a5853e62ff/go.mod h1:b0p+7cn+rWMIphK1gDH2hrDuwGOcbB6V4VXeSsEfHVk=
github.com/anacrolix/missinggo v0.0.0-20180725070939-60ef2fbf63df/go.mod h1:kwGiTUTZ0+p4vAz3VbAI5a30t2YbvemcmspjKwrAz5s=
github.com/anacrolix/missinggo v0.0.0-20181129073415-3237bf955fed/go.mod h1:IN+9GUe7OxKMIs/XeXEbT/rMUolmJzmlZiXHS7FwD/Y=
github.com/anacrolix/missinggo v0.2.1-0.20190310234110-9fbdc9f242a8/go.mod h1:MBJu3Sk/k3ZfGYcS7z18gwfu72Ey/xopPFJJbTi5yIo=
github.com/anacrolix/missinggo v1.1.0 h1:0lZbaNa6zTR1bELAIzCNmRGAtkHuLDPJqTiTtXoAIx8=
github.com/anacrolix/missinggo v1.1.0/go.mod h1:MBJu3Sk/k3ZfGYcS7z18gwfu72Ey/xopPFJJbTi5yIo=
github.com/anacrolix/mmsg v0.0.0-20180515031531-a4a3ba1fc8bb/go.mod h1:x2/ErsYUmT77kezS63+wzZp8E3byYB0gzirM/WMBLfw=
github.com/anacrolix/mmsg v0.0.0-20180808012353-5adb2c1127c0 h1:Fa1XqqLW62lQzEDlNA+QcdJbkfJcxQN0YC8983kj5tU=
github.com/anacrolix/mmsg v0.0.0-20180808012353-5adb2c1127c0/go.mod h1:x8kRaJY/dCrY9Al0PEcj1mb/uFHwP6GCJ9fLl4thEPc=
github.com/anacrolix/sync v0.0.0-20171108081538-eee974e4f8c1/go.mod h1:+u91KiUuf0lyILI6x3n/XrW7iFROCZCG+TjgK8nW52w=
github.com/anacrolix/sync v0.0.0-20180611022320-3c4cb11f5a01/go.mod h1:+u91KiUuf0lyILI6x3n/XrW7iFROCZCG+TjgK8nW52w=
github.com/anacrolix/sync v0.0.0-20180808010631-44578de4e778 h1:XpCDEixzXOB8yaTW/4YBzKrJdMcFI0DzpPTYNv75wzk=
github.com/anacrolix/sync v0.0.0-20180808010631-44578de4e778/go.mod h1:s735Etp3joe/voe2sdaXLcqDdJSay1O0OPnM0ystjqk=
github.com/anacrolix/tagflag v0.0.0-20180109131632-2146c8d41bf0/go.mod h1:1m2U/K6ZT+JZG0+bdMK6qauP49QT4wE5pmhJXOKKCHw=
github.com/anacrolix/tagflag v0.0.0-20180605133421-f477c8c2f14c/go.mod h1:1m2U/K6ZT+JZG0+bdMK6qauP49QT4wE5pmhJXOKKCHw=
github.com/anacrolix/tagflag v0.0.0-20180803105420-3a8ff5428f76/go.mod h1:1m2U/K6ZT+JZG0+bdMK6qauP49QT4wE5pmhJXOKKCHw=
github.com/anacrolix/torrent v0.0.0-20180622074351-fefeef4ee9eb/go.mod h1:3vcFVxgOASslNXHdivT8spyMRBanMCenHRpe0u5vpBs=
github.com/anacrolix/torrent v1.0.1/go.mod h1:ZYV1Z2Wx3jXYSh26mDvneAbk8XIUxfvoVil2GW962zY=
github.com/anacrolix/torrent v1.1.4 h1:AD0mO9UNUUP5rZoGv8ZbQQY903Yb4Aq2Eg3i7+GxwM4=
github.com/anacrolix/torrent v1.1.4/go.mod h1:XdYEuC3KuxFQZrQ6iUBXnwKr3IyxeyUlVH6RT8FhyaU=
github.com/anacrolix/utp v0.0.0-20180219060659-9e0e1d1d0572/go.mod h1:MDwc+vsGEq7RMw6lr2GKOEqjWny5hO5OZXRVNaBJ2Dk=
github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4=
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
github.com/boramalper/magnetico v0.9.0 h1:QaztD0b2mT+T/l0pXUBL5Smkj7LQLzyaW/UfTzi3Jxo=
github.com/boramalper/magnetico v0.9.0/go.mod h1:w/1aRTMrCIeb5RSebdXck4p+rcI35SlKvbgOtgEVi2w=
github.com/bradfitz/iter v0.0.0-20140124041915-454541ec3da2/go.mod h1:PyRFw1Lt2wKX4ZVSQ2mk+PeDa1rxyObEDlApuIsUKuo=
github.com/bradfitz/iter v0.0.0-20190303215204-33e6a9893b0c h1:FUUopH4brHNO2kJoNN3pV+OBEYmgraLT/KHZrMM69r0=
github.com/bradfitz/iter v0.0.0-20190303215204-33e6a9893b0c/go.mod h1:PyRFw1Lt2wKX4ZVSQ2mk+PeDa1rxyObEDlApuIsUKuo=
github.com/cheggaaa/pb/v3 v3.0.1 h1:m0BngUk2LuSRYdx4fujDKNRXNDpbNCfptPfVT2m6OJY=
github.com/cheggaaa/pb/v3 v3.0.1/go.mod h1:SqqeMF/pMOIu3xgGoxtPYhMNQP258xE4x/XRTYua+KU=
@ -48,20 +57,26 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
github.com/dustin/go-humanize v0.0.0-20180421182945-02af3965c54e/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
github.com/edsrzf/mmap-go v1.0.0 h1:CEBF7HpRnUCSJgGUb5h1Gm7e3VkmVDrR8lvWVLtrOFw=
github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
github.com/elgatito/upnp v0.0.0-20180711183757-2f244d205f9a h1:2Zw3pxDRTs4nX1WCLAEm27UN0hvjZSge7EaUUQexRZw=
github.com/elgatito/upnp v0.0.0-20180711183757-2f244d205f9a/go.mod h1:afkYpY8JAIL4341N7Zj9xJ5yTovsg6BkWfBFlCzIoF4=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/glycerine/go-unsnap-stream v0.0.0-20180323001048-9f0cb55181dd/go.mod h1:/20jfyN9Y5QPEAprSgKAUr+glWDY39ZiUEAYOEv5dsE=
github.com/glycerine/go-unsnap-stream v0.0.0-20181221182339-f9677308dec2 h1:Ujru1hufTHVb++eG6OuNDKMxZnGIvF6o/u8q/8h2+I4=
github.com/glycerine/go-unsnap-stream v0.0.0-20181221182339-f9677308dec2/go.mod h1:/20jfyN9Y5QPEAprSgKAUr+glWDY39ZiUEAYOEv5dsE=
github.com/glycerine/goconvey v0.0.0-20180728074245-46e3a41ad493/go.mod h1:Ogl1Tioa0aV7gstGFO7KhffUsb9M4ydbEbbxpcEDc24=
github.com/glycerine/goconvey v0.0.0-20190315024820-982ee783a72e/go.mod h1:Ogl1Tioa0aV7gstGFO7KhffUsb9M4ydbEbbxpcEDc24=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/btree v0.0.0-20180124185431-e89373fe6b4a/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c h1:964Od4U6p2jUkFxvCydnIczKteheJEzHRToSGK3Bnlw=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
@ -72,13 +87,18 @@ github.com/gorilla/schema v1.1.0/go.mod h1:kgLaKoK1FELgZqMAVxx/5cbj0kT+57qxUrAlI
github.com/gosuri/uilive v0.0.0-20170323041506-ac356e6e42cd/go.mod h1:qkLSc0A5EXSP6B04TrN4oQoxqFI7A8XvoXSlJi8cwk8=
github.com/gosuri/uiprogress v0.0.0-20170224063937-d0567a9d84a1/go.mod h1:C1RTYn4Sc7iEyf6j8ft5dyoZ4212h8G1ol9QQluh5+0=
github.com/huandu/xstrings v1.0.0/go.mod h1:4qWG/gcEcfX4z/mBDHJ++3ReCw9ibxbsNJbcucJdbSo=
github.com/huandu/xstrings v1.2.0 h1:yPeWdRnmynF7p+lLYz0H2tthW9lqhMJrQV/U7yy4wX0=
github.com/huandu/xstrings v1.2.0/go.mod h1:DvyZB1rfVYsBIigL8HwpZgxHwXozlTgGqn63UyNX5k4=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ipfs/go-ipfs v0.4.18/go.mod h1:iXzbK+Wa6eePj3jQg/uY6Uoq5iOwY+GToD/bgaRadto=
github.com/iwanbk/gobeanstalk v0.0.0-20160903043409-dbbb23937c31 h1:pYeOIZnfAA9kUZFYC6BF8iElFnmOJlfpQLTTw4ENPLM=
github.com/iwanbk/gobeanstalk v0.0.0-20160903043409-dbbb23937c31/go.mod h1:9ERvzhQ09s9SfQ7LjjF6FwUDnfkdZJUCN3vOUE+NtP8=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/kevinburke/go-bindata v3.13.0+incompatible/go.mod h1:/pEEZ72flUW2p0yi30bslSp9YqD9pysLxunQDdb2CPM=
github.com/lib/pq v1.2.0 h1:LXpIM/LZ5xGFhOpXAQUIMM1HdyqzVYM13zNdjCEEcA0=
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/libp2p/go-sockaddr v0.0.1/go.mod h1:EBeYKMYs5LFgoaBSN2nA2jPQVmnA4gv7WkY64CBqYqQ=
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
@ -91,7 +111,9 @@ github.com/mattn/go-sqlite3 v1.7.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOq
github.com/mattn/go-sqlite3 v1.10.0 h1:jbhqpg7tQe4SupckyijYiy0mJJ/pRyHvXf7JdWK860o=
github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
github.com/mschoch/smat v0.0.0-20160514031455-90eadee771ae/go.mod h1:qAyveg+e4CE+eKJXWVjKXM4ck2QobLqTDytGJbLLhJg=
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7 h1:lDH9UUVJtmYCjyT0CI4q8xvlXPxeZ0gYCVvWbmPlp88=
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk=
github.com/philhofer/fwd v1.0.0 h1:UbZqGr5Y38ApvM/V/jEljVxwocdweyH+vmYvRPBnbqQ=
github.com/philhofer/fwd v1.0.0/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
@ -99,12 +121,20 @@ github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pkg/profile v1.3.0/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/ryszard/goskiplist v0.0.0-20150312221310-2dfbae5fcf46 h1:GHRpF1pTW19a8tTFrMLUcfWwyC0pnifVo2ClaLq+hP8=
github.com/ryszard/goskiplist v0.0.0-20150312221310-2dfbae5fcf46/go.mod h1:uAQ5PCi+MFsC7HjREoAz1BU+Mq60+05gifQSsHSDG/8=
github.com/skobkin/magnetico v0.7.3-0.20191018201532-1f855ed72132 h1:tCAWIJQSSbwLGGvReUpfEdeiUk990BHrkHLSq7khSiQ=
github.com/skobkin/magnetico v0.7.3-0.20191018201532-1f855ed72132/go.mod h1:WAYXKsHqBAvuM3HpuaiVT5kj1x9BZ0DsfWafoVRN1MM=
github.com/skobkin/magnetico v0.7.3-0.20191018211700-34f92cd6c13b h1:76wfhwuusOuEMY0s7ZyeF7+L8egcRke4k4MUcoLi49w=
github.com/skobkin/magnetico v0.7.3-0.20191018211700-34f92cd6c13b/go.mod h1:3mr9Uf+LHHvg4lX8Am9PDGR2j7t6Nk/L6OnXprPvgA0=
github.com/skobkin/magnetico v0.7.3-0.20191020131325-8ae709a3b222 h1:CMVTOdIGWcJk9dwaze+dCsIluXH/05/HEcN5nDBfBDs=
github.com/skobkin/magnetico v0.7.3-0.20191020131325-8ae709a3b222/go.mod h1:xO6PmIHcomlxD1v3B/o+nNbJ3jBCXzNNOLkRLeHycE4=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/assertions v0.0.0-20190215210624-980c5ac6f3ac/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c/go.mod h1:XDJAKZRPZ1CvBcN2aX5YOUTYGHki24fSF0Iv48Ibg0s=
github.com/smartystreets/goconvey v0.0.0-20190306220146-200a235640ff/go.mod h1:KSQcGKpxUMHk3nbYzs/tIBAM2iDooCn0BmttHOJEbLs=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
@ -115,11 +145,14 @@ github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJy
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/syncthing/syncthing v0.14.48-rc.4/go.mod h1:nw3siZwHPA6M8iSfjDCWQ402eqvEIasMQOE8nFOxy7M=
github.com/tinylib/msgp v1.0.2/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE=
github.com/tinylib/msgp v1.1.0 h1:9fQd+ICuRIu/ue4vxJZu6/LzxN0HwMds2nq/0cFvxHU=
github.com/tinylib/msgp v1.1.0/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE=
github.com/willf/bitset v1.1.3/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4=
github.com/willf/bitset v1.1.9/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4=
github.com/willf/bitset v1.1.10 h1:NotGKqX0KwQ72NUzqrjZq5ipPNDQex9lo3WpaS8L2sc=
github.com/willf/bitset v1.1.10/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4=
github.com/willf/bloom v0.0.0-20170505221640-54e3b963ee16/go.mod h1:MmAltL9pDMNTrvUkxdg0k0q5I0suxmuwp3KbyrZLOZ8=
github.com/willf/bloom v2.0.3+incompatible h1:QDacWdqcAUI1MPOwIQZRy9kOR7yxfyEmxX8Wdm2/JPA=
github.com/willf/bloom v2.0.3+incompatible/go.mod h1:MmAltL9pDMNTrvUkxdg0k0q5I0suxmuwp3KbyrZLOZ8=
go.uber.org/atomic v1.4.0 h1:cxzIVoETapQEqDhQu3QfnvXAV4AlzcvUCxkVUFw3+EU=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
@ -132,6 +165,7 @@ golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/net v0.0.0-20180524181706-dfa909b99c79/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190318221613-d196dffd7c2b/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190102155601-82a175fd1598/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@ -144,6 +178,7 @@ golang.org/x/sys v0.0.0-20190516110030-61b9204099cb/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 h1:SvFZT6jyqRaOeXpc5h/JSfZenJ2O330aBsf7JfSUXmQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=

View File

@ -3,10 +3,11 @@ package main
import (
"database/sql"
"encoding/hex"
"fmt"
"github.com/boramalper/magnetico/pkg/persistence"
"gitlab.com/skobkin/magnetico-go-migrator/old"
"github.com/cheggaaa/pb/v3"
_ "github.com/mattn/go-sqlite3"
"github.com/skobkin/magnetico/pkg/persistence"
"go.uber.org/zap"
"gopkg.in/alecthomas/kingpin.v2"
"net/url"
@ -15,6 +16,9 @@ import (
var (
goDatabaseUrl = kingpin.Flag("go-database", "magneticod Go version database URL.").Short('g').String()
pyDatabaseUrl = kingpin.Flag("py-database", "Python version database URL.").Short('p').Required().String()
chunkSize = kingpin.Flag("chunk-size", "How many torrents to retrieve from old DB at once").Short('c').Default("200").Uint64()
progress pb.ProgressBar
)
func main() {
@ -35,113 +39,80 @@ func main() {
logger.Panic("Can't parse Python database URL.", zap.String("url", *pyDatabaseUrl), zap.Error(err))
}
pyDatabase, err := openSqliteDb(*oldSqliteUrl)
pyDatabase, err := old.OpenSqliteDb(*oldSqliteUrl)
if err != nil {
logger.Panic("Couldn't open Python database.", zap.String("url", *pyDatabaseUrl), zap.Error(err))
}
defer pyDatabase.Close()
err = process(*pyDatabase, goDatabase)
if err != nil {
logger.Error("Error while processing data", zap.Error(err))
}
}
func process(pyDb sql.DB, goDb persistence.Database) error {
torrentsTotal, err := getNumberOfTorrents(pyDb)
torrentsTotal, err := old.GetNumberOfTorrents(pyDatabase)
if err != nil {
zap.L().Panic("Couldn't count torrents", zap.Error(err))
}
bar := pb.New(int(torrentsTotal))
//bar.SetRefreshRate(time.Second)
bar.Start()
progress = *pb.Full.New(int(torrentsTotal))
progress.Start()
// Selecting torrents
tRows, err := pyDb.Query("SELECT id, info_hash, name, total_size, discovered_on FROM torrents ORDER BY id ASC;")
err = mergeDatabases(pyDatabase, goDatabase)
if err != nil {
zap.L().Fatal("Error when querying torrents from old database.")
logger.Error("Error while processing data", zap.Error(err))
}
defer tRows.Close()
torrentLoop:
for tRows.Next() {
var torrent persistence.TorrentMetadata
progress.Finish()
}
bar.Increment()
func mergeDatabases(pyDb *sql.DB, goDb persistence.Database) error {
maxId, err := old.GetLastTorrentId(pyDb)
if err != nil {
zap.L().Fatal("Error while getting last torrent ID from old database")
}
err := tRows.Scan(&torrent.ID, &torrent.InfoHash, &torrent.Name, &torrent.Size, &torrent.DiscoveredOn)
var lastId uint64 = 0
for lastId < maxId {
chunk, err := old.GetTorrentsChunk(pyDb, lastId, *chunkSize)
if err != nil {
zap.L().Error("Error scanning torrent row.", zap.Error(err))
continue
zap.L().Error("Error while getting torrents chunk", zap.Uint64("last-id", lastId))
return err
}
// Selecting files for torrent
fRows, err := pyDb.Query("SELECT f.path, f.size FROM files AS f WHERE f.torrent_id = ? ORDER BY f.id ASC;", torrent.ID)
if err != nil {
zap.L().Fatal("Error when querying files for torrent.", zap.Uint64("torrent_id", torrent.ID))
}
defer fRows.Close()
if len(chunk) == 0 {
if (maxId - lastId) <= *chunkSize {
zap.L().Warn("Probably finished processing all data (earlier). Finishing.", zap.Uint64("last", lastId), zap.Uint64("max", maxId))
files := make([]persistence.File, 0)
for fRows.Next() {
var file persistence.File
err := fRows.Scan(&file.Path, &file.Size)
fRows.Close()
if err != nil {
zap.L().Error("Error scanning file row", zap.Uint64("torrent_id", torrent.ID), zap.Error(err))
continue torrentLoop
return nil
} else {
zap.L().Error("Prematurely received empty chunk, aborting", zap.Uint64("last", lastId), zap.Uint64("max", maxId))
}
files = append(files, file)
}
exists, err := goDb.DoesTorrentExist(torrent.InfoHash)
if err != nil {
zap.L().Error("Error checking torrent existence.", zap.String("hash", hex.EncodeToString(torrent.InfoHash)), zap.Error(err))
for _, piece := range chunk {
lastId = piece.Torrent.ID
progress.Increment()
continue
}
if !exists {
err = goDb.AddNewTorrent(torrent.InfoHash, torrent.Name, files)
err = importTorrent(goDb, piece.Torrent, piece.Files)
if err != nil {
zap.L().Error("Error adding torrent to Go database.", zap.String("hash", hex.EncodeToString(torrent.InfoHash)), zap.Error(err))
zap.L().Error("Error when importing torrent to Go database.", zap.String("hash", hex.EncodeToString(piece.Torrent.InfoHash)), zap.Error(err))
}
}
}
bar.Finish()
return nil
}
func getNumberOfTorrents(db sql.DB) (uint, error) {
rows, err := db.Query("SELECT COUNT(id) FROM torrents;")
func importTorrent(goDb persistence.Database, torrent persistence.TorrentMetadata, files []persistence.File) error {
exists, err := goDb.DoesTorrentExist(torrent.InfoHash)
if err != nil {
return 0, err
}
defer rows.Close()
if rows.Next() != true {
return 0, fmt.Errorf("No rows returned from `SELECT COUNT(id)`")
return err
}
var n *uint
if err = rows.Scan(&n); err != nil {
return 0, err
if !exists {
err = goDb.AddNewTorrent(torrent.InfoHash, torrent.Name, files)
if err != nil {
return err
}
}
// If the database is empty (i.e. 0 entries in 'torrents') then the query will return nil.
if n == nil {
return 0, nil
} else {
return *n, nil
}
}
func openSqliteDb(url_ url.URL) (*sql.DB, error) {
url_.Scheme = ""
return sql.Open("sqlite3", url_.String())
return nil
}

131
old/sqlite.go Normal file
View File

@ -0,0 +1,131 @@
package old
import (
"database/sql"
"encoding/hex"
"fmt"
"github.com/skobkin/magnetico/pkg/persistence"
"go.uber.org/zap"
"net/url"
)
type TorrentData struct {
Torrent persistence.TorrentMetadata
Files []persistence.File
}
func OpenSqliteDb(url_ url.URL) (*sql.DB, error) {
url_.Scheme = ""
return sql.Open("sqlite3", url_.String())
}
func GetNumberOfTorrents(db *sql.DB) (uint, error) {
rows, err := db.Query("SELECT COUNT(id) FROM torrents;")
if err != nil {
return 0, err
}
defer rows.Close()
if rows.Next() != true {
return 0, fmt.Errorf("No rows returned from `SELECT COUNT(id)`")
}
var n *uint
if err = rows.Scan(&n); err != nil {
return 0, err
}
// If the database is empty (i.e. 0 entries in 'torrents') then the query will return nil.
if n == nil {
return 0, nil
} else {
return *n, nil
}
}
func GetLastTorrentId(db *sql.DB) (uint64, error) {
rows, err := db.Query("SELECT MAX(id) FROM torrents;")
if err != nil {
return 0, err
}
defer rows.Close()
if rows.Next() != true {
return 0, fmt.Errorf("No rows returned from `SELECT MAX(id)`")
}
var n *uint64
if err = rows.Scan(&n); err != nil {
return 0, err
}
// If the database is empty (i.e. 0 entries in 'torrents') then the query will return nil.
if n == nil {
return 0, nil
} else {
return *n, nil
}
}
func GetTorrentsChunk(db *sql.DB, fromId uint64, size uint64) ([]TorrentData, error) {
chunk := make([]TorrentData, 0, size)
// Selecting torrents
tRows, err := db.Query(`
SELECT id, info_hash, name, total_size, discovered_on
FROM torrents
WHERE id > ?
ORDER BY id ASC
LIMIT ?;
`, fromId, size)
if err != nil {
zap.L().Fatal("Error when querying torrents from old database.")
}
defer tRows.Close()
for tRows.Next() {
var torrent persistence.TorrentMetadata
err := tRows.Scan(&torrent.ID, &torrent.InfoHash, &torrent.Name, &torrent.Size, &torrent.DiscoveredOn)
if err != nil {
zap.L().Error("Error scanning torrent row.", zap.Error(err))
return chunk, err
}
files, err := GetFilesForTorrent(db, torrent)
if err != nil {
zap.L().Error("Error getting files for torrent.", zap.String("hash", hex.EncodeToString(torrent.InfoHash)), zap.Error(err))
return chunk, err
}
chunk = append(chunk, TorrentData{Torrent: torrent, Files: files})
}
return chunk, nil
}
func GetFilesForTorrent(pyDb *sql.DB, torrent persistence.TorrentMetadata) ([]persistence.File, error) {
files := make([]persistence.File, 0)
// Selecting files for torrent
fRows, err := pyDb.Query("SELECT f.path, f.size FROM files AS f WHERE f.torrent_id = ? ORDER BY f.id ASC;", torrent.ID)
if err != nil {
return files, nil
}
defer fRows.Close()
for fRows.Next() {
var file persistence.File
err := fRows.Scan(&file.Path, &file.Size)
if err != nil {
return files, err
}
files = append(files, file)
}
return files, nil
}