Tag Archives: dump

Postgresql: export/import users with privileges

It's easy to transfer users from one instance to anothe:
#dump users and permissions
sudo -u postgres pg_dumpall -g > globals_only.dump
#restore them
cat globals_only.dump | sudo -u postgres psql
# or if you would like to choose specific user
grep USERNAME globals_only.dump

1
2
3
CREATE ROLE "USERNAME";
ALTER ROLE "USERNAME" WITH NOSUPERUSER INHERIT NOCREATEROLE NOCREATEDB LOGIN NOREPLICATION PASSWORD 'md56933b22c7ea06924799dbac5d7ed8072';
GRANT ro TO "USERNAME" GRANTED BY postgres;

These commands you could input directly to postgres command-line.

Rails: dump db schema from mysql

gem install mysql2

edit config/database.yml

development:
    adapter: mysql2
    encoding: utf8
    database: db_name
    username: user_name
    password: password_of_user
    host: host_ip
    timeout: 5000

edit Gemfile

gem 'mysql2'

bundle install

rake db:schema:dump

db/schema.rb has been created