Project

mypg

0.0
No commit activity in last 3 years
No release in over 3 years
Dump and restore PostgreSQL's structure and data.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 1.2
 Project Readme

Mypg

Easy backup for Rails applications with PostgreSQL database.

Installation

Add this line into your application's Gemfile:

gem 'mypg'

Install the gem with Bundler:

$ bundle

Configuration

And then add some settings:

$ rails g mypg:install

This will create a configuration file in config/mypg.yml who looks like this:

# target_directory: '/path/to/backup'
# files_to_keep:    7

Just enter a valid directory to save your backup files.

Note: If not specified, the amount of files that will be saved is 7.

How To

Backup

Go to your Rails root directory and run this:

$ rake db:backup RAILS_ENV=production

This command will create a .pgsql file in the directory with your database's structure and data. Moreover, will delete the older files wich exceed the amount to be saved.

Pro Tip

You can create automatic daily backups just setting up a task on Cron:

$ crontab -e

Insert this and save:

# m h  dom mon dow   command
0 0 * * * cd ~/my/rails/root && rake db:backup RAILS_ENV=production

With that, every day in the midnight (server's time) Cron will perform your backup task automatically.

Restore

If you wish to restore some saved backup, go to your Rails root directory and run this:

$ rake db:restore 'relative/target/directory/to/backup/database_x.pgsql' RAILS_ENV=production

This command will restructure the production database and restore all the data from backup file.

Note: The path for the backup file must be relative to the current directory in the console.

Thanks

Leonardo Ávila for contributing in the README translation and revision.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request