Sequel is a fantastic ORM available in Ruby.

It also comes with an IRB console so it can be run directly from the command line with various options.

For example, to console into an SQLite database testdb.sqlite in the current directory –

$> sequel sqlite://testdb.sqlite

Or for Postgres –

$> sequel postgres://dbuser:dbpassword@localhost/testdb

However, I use sequel most frequently to take quick database backups or to restore them.

Copy Postgres to SQLite

$> sequel -C postgres://localhost/testdb sqlite://testdb.sqlite

Copy SQLite to Postgres

$> sequel -C sqlite://testdb.sqlite postgres://localhost/testdb

Copy SQLite to SQLite

$> sequel -C sqlite://testdb.sqlite sqlite://testdb-copy.sqlite

Note:

  • The target database should be an empty database i.e. it should not have any tables
  • Path to SQLite should be fully qualified path / current directory
  • If Postgres requires credentials, they should be in the connection parameters –
postgres://databaseuser:databasepassword@localhost/testdb