Code Monkey home page Code Monkey logo

copy-kvs's Introduction

copy-kvs

Perl script that can be used to copy a lot of objects (files) between MongoDB GridFS, PostgreSQL BLOBs, and Amazon S3.

Build Status

Build Status Coverage Status

Usage

  1. Copy configuration template file:

     cp sample-config/gridfs-to-s3.yml.dist gridfs-to-s3.yml
    
  2. Edit configuration file gridfs-to-s3.yml to set the MongoDB GridFS / Amazon S3 connection settings and other properties.

  3. To copy files from GridFS to S3, run:

     perl bin/copy-kvs.pl gridfs-to-s3.yml mongodb_gridfs amazon_s3
    
  4. To copy files from S3 to GridFS, run:

     perl bin/copy-kvs.pl gridfs-to-s3.yml amazon_s3 mongodb_gridfs
    

Implementation details

Code formatting

Install perltidy Git hook to automatically fix script formatting:

cpanm --installdeps .
githook-perltidy install

Sorting in GridFS

When copying from GridFS, the script will sort files roughly by insertion date. The script uses object's ObjectId for sorting. As the default ObjectId contains an insertion timestamp (rounded to seconds), the objects are sorted in 1 second precision.

For example, if your GridFS deployment contains the following files:

> db.fs.files.find( { }, { filename: 1, uploadDate: 1 } )
{ "uploadDate" : ISODate("2013-06-11T08:00:00Z"), "filename" : "1" }
{ "uploadDate" : ISODate("2013-06-11T08:00:00Z"), "filename" : "2" }
{ "uploadDate" : ISODate("2013-06-11T08:00:00Z"), "filename" : "3" }
{ "uploadDate" : ISODate("2013-06-11T08:00:00Z"), "filename" : "4" }
{ "uploadDate" : ISODate("2013-06-11T08:00:00Z"), "filename" : "5" }
{ "uploadDate" : ISODate("2013-06-11T08:00:00Z"), "filename" : "6" }
{ "uploadDate" : ISODate("2013-06-11T08:00:00Z"), "filename" : "7" }
{ "uploadDate" : ISODate("2013-06-11T08:00:00Z"), "filename" : "8" }
{ "uploadDate" : ISODate("2013-06-11T08:00:01Z"), "filename" : "9" }
{ "uploadDate" : ISODate("2013-06-11T08:00:01Z"), "filename" : "10" }
{ "uploadDate" : ISODate("2013-06-11T08:00:01Z"), "filename" : "11" }
{ "uploadDate" : ISODate("2013-06-11T08:00:01Z"), "filename" : "12" }
{ "uploadDate" : ISODate("2013-06-11T08:00:01Z"), "filename" : "13" }
{ "uploadDate" : ISODate("2013-06-11T08:00:01Z"), "filename" : "14" }
{ "uploadDate" : ISODate("2013-06-11T08:00:01Z"), "filename" : "15" }
{ "uploadDate" : ISODate("2013-06-11T08:00:01Z"), "filename" : "16" }

...the script will copy files 1-8 in any order (because they were inserted during the same second), but will upload files 1-8 before uploading files 9-16 (because the latter were inserted in the next second).

Sorting in PostgreSQL

When copying from PostgreSQL, the script will sort files by primary key.

So, unless you do something funky with your primary keys, the objects will be sorted in an insertion order.

Sorting in S3

When copying from S3, the script will sort files in lexicographical order.

For example, if your S3 bucket contains the following files:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

...these files will be copied from S3 to GridFS in the following order:

1
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9

This is because lexicographical order is the only one Amazon supports for sorting S3 contents (at the time of writing).

Unit tests

Execute:

COPY_KVS_S3_ACCESS_KEY_ID="AKIAIOSFODNN7EXAMPLE" \
COPY_KVS_S3_SECRET_ACCESS_KEY="wJalrXUtnFEMI/K7MDENG/bPxRfiCYzEXAMPLEKEY" \
COPY_KVS_S3_BUCKET_NAME="copy-kvs-unit-tests" \
\
COPY_KVS_POSTGRES_HOST="localhost" \
COPY_KVS_POSTGRES_USERNAME="copy_kvs_test" \
COPY_KVS_POSTGRES_PASSWORD="copy_kvs_test" \
COPY_KVS_POSTGRES_DATABASE="copy_kvs_test" \
\
make test

to run unit tests provided with the script.


copy-kvs's People

Contributors

pypt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.