Code Monkey home page Code Monkey logo

scalingo_databases_rake_tasks-gem's Introduction

Caution

Dear Users,
This repository was deprecated and archived on the 7th of March on 2024.
If you want to backup and restore your databases, please use ou CLI and the
instruction available in our documentation: https://doc.scalingo.com/

ScalingoDatabasesRakeTasks

A gem providing rake tasks such as backup and restore for database manipulations on Scalingo.

Currently supported databases:

  • MongoDB
  • MySQL
  • PostgreSQL

Available tasks for each database:

  • backup_local: make a backup of local database
  • backup_remote: make a backup of remote Scalingo database
  • restore_local: restore a local database with an archive
  • restore_remote: restore a remote Scalingo database with an archive

Usage

For remote operations you will have to set your shell's environment variable APP as your app name on Scalingo. The variable DB_ENV_NAME is optional, by default it will be the one generated when you provisionned the database addon. For example, if your database is a MongoDB then the variable will be SCALINGO_MONGO_URL.

Available Env Vars

Global:

  • APP: Scalingo app name (mandatory)
  • DB_ENV_NAME: Scalingo database connection var name, e.g. SCALINGO_MONGO_URL (optional)
  • SSH_IDENTITY: specify a SSH identity file, e.g. ~/.ssh/id_rsa (optional)

MongoDB:

  • FILE: your database config file name, e.g. database (optional)

PostgreSQL:

  • PG_DUMP_CMD: specify the path or command name of the tool to use, default: pg_dump (optional)
  • PG_RESTORE_CMD:specify the path or command name of the tool to use, default: pg_restore (optional)

Commands

To see the complete list of tasks: rake -T scalingo

Example of commands for MongoDB:

  • rake scalingo:mongodb:backup_local
  • rake scalingo:mongodb:backup_remote
  • rake scalingo:mongodb:restore_local
  • rake scalingo:mongodb:restore_remote

Backup and Restore

Backups are stored under the tmp folder of your project, the database type is part of the archive name (e.g. scalingo_mongodb_dump.tar.gz).

To restore from a specific archive, you'll have to give it the default archive name and put it inside of tmp folder before running the rake command.

SSH Identity

If you are not using a SSH agent and your default SSH identity file is not id_rsa you can specify your custom identity file path with the SSH_IDENTITY variable.

Installation

Add this line to your application's Gemfile:

gem 'scalingo_databases_rake_tasks'

And then execute:

$ bundle

Or install it yourself as:

$ gem install scalingo_databases_rake_tasks

For Rails apps nothing to do.

For other apps, add require "scalingo_databases_rake_tasks" to your Rakefile.

Development

After checking out the repo, run bin/setup to install dependencies. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/Scalingo/scalingo_databases_rake_tasks-gem.

scalingo_databases_rake_tasks-gem's People

Contributors

whollacsek avatar soulou avatar yannski avatar reaper avatar brunto avatar leo-scalingo avatar etiennem avatar

Stargazers

 avatar  avatar Jonathan Hurter avatar  avatar Clément Joubert avatar

Watchers

 avatar Thomas Wickham avatar James Cloos avatar  avatar Jonathan Hurter avatar François avatar Bragagia Mathias avatar Pierre Curzola avatar  avatar Méderic Bazart avatar

scalingo_databases_rake_tasks-gem's Issues

PostgreSQL remote_backup doesn't work when Postgis is enabled

$ IDENTITY=~/.ssh/id_rsa_scalingo APP=myapp RAILS_ENV=development rake scalingo:postgresql:backup_remote
*** Executing scalingo -a myapp db-tunnel -p 27717 SCALINGO_POSTGRESQL_URL
*** Tunnel opened
*** Executing rm -rf /tmp/scalingo_postgresql_dump 2>/dev/null && /usr/bin/env PGPASSWORD=[FILTERED] pg_dump --no-owner --no-privileges --clean -N 'information_schema' -N '^pg_*' --format=c  -U myapp__2750 -h 127.0.0.1 -p 27717 -d myapp__2750 --if-exists > /tmp/scalingo_postgresql_dump && tar cvzf /home/pierre/Projets/rails/myapp/tmp/scalingo_postgresql_dump.tar.gz -C /tmp scalingo_postgresql_dump
pg_dump: [programme d'archivage (db)] échec de la requête : ERROR:  permission denied for schema tiger
pg_dump: [programme d'archivage (db)] la requête était : COPY tiger.geocode_settings  TO stdout;
*** Tunnel closed

Getting already initialized constants

I declared a task using your gem and i get these messages while running my tests:

/home/florian/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/scalingo_databases_rake_tasks-0.2.0/lib/scalingo_databases_rake_tasks/tasks/mongodb.rake:35: warning: already initialized constant ScalingoMongoDB::DUMP_NAME
/home/florian/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/scalingo_databases_rake_tasks-0.2.0/lib/scalingo_databases_rake_tasks/tasks/mongodb.rake:35: warning: previous definition of DUMP_NAME was here
/home/florian/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/scalingo_databases_rake_tasks-0.2.0/lib/scalingo_databases_rake_tasks/tasks/mysql.rake:35: warning: already initialized constant ScalingoMySQL::DUMP_NAME
/home/florian/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/scalingo_databases_rake_tasks-0.2.0/lib/scalingo_databases_rake_tasks/tasks/mysql.rake:35: warning: previous definition of DUMP_NAME was here
/home/florian/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/scalingo_databases_rake_tasks-0.2.0/lib/scalingo_databases_rake_tasks/tasks/mysql.rake:36: warning: already initialized constant ScalingoMySQL::DUMP_PATH
/home/florian/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/scalingo_databases_rake_tasks-0.2.0/lib/scalingo_databases_rake_tasks/tasks/mysql.rake:36: warning: previous definition of DUMP_PATH was here
/home/florian/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/scalingo_databases_rake_tasks-0.2.0/lib/scalingo_databases_rake_tasks/tasks/postgresql.rake:36: warning: already initialized constant ScalingoPostgreSQL::DUMP_NAME
/home/florian/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/scalingo_databases_rake_tasks-0.2.0/lib/scalingo_databases_rake_tasks/tasks/postgresql.rake:36: warning: previous definition of DUMP_NAME was here
/home/florian/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/scalingo_databases_rake_tasks-0.2.0/lib/scalingo_databases_rake_tasks/tasks/postgresql.rake:37: warning: already initialized constant ScalingoPostgreSQL::DUMP_PATH
/home/florian/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/scalingo_databases_rake_tasks-0.2.0/lib/scalingo_databases_rake_tasks/tasks/postgresql.rake:37: warning: previous definition of DUMP_PATH was here

Here is my task:

# frozen_string_literal: true

if Rails.env.development?
  task :fetch_dev_db do
    old_app = ENV.fetch('APP')
    ENV['APP'] = 'elise-api-dev'
    puts 'Backing up remote database'
    Rake::Task["scalingo:postgresql:backup_remote"].execute
    puts 'Restoring remote database'
    ENV['APP'] = old_app
    Rake::Task["scalingo:postgresql:restore_remote"].execute
  end
end

I'm running ruby 3.3.0 and rails 7.1,
Thanks for your help !

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.