Simply backup PostgreSQL/MySQL database and logs to S3.
This gem needs the following softwares.
Add this line to your application's Gemfile:
gem 'sg_tiny_backup', github: 'SonicGarden/sg_tiny_backup'You should modify it according to the comments in it.
bundle exec rake sg_tiny_backup:generate
# backup database
bundle exec rake sg_tiny_backup:backup
# backup logs
bundle exec rake sg_tiny_backup:backup BACKUP_TARGET=log
# backup database
bundle exec rake sg_tiny_backup:backup_local
# backup logs
bundle exec rake sg_tiny_backup:backup_local BACKUP_TARGET=log
# show database backup command
bundle exec rake sg_tiny_backup:command
# show log backup command
bundle exec rake sg_tiny_backup:command BACKUP_TARGET=log
bundle exec rake sg_tiny_backup:decryption_command
Logs are outputted to standard output by default.
You can change the logger if you want.
SgTinyBackup.logger = Rails.loggerIf SgTinyBackup.raise_on_error is true, the backup task raises an error when the backup command fails.
So your bug tracking service (like Bugsnag, Sentry, ...) can catch the error.
SgTinyBackup.raise_on_error = true # true by defaultThis gem simply generates a command line string like the following and runs it. The credentials are passed to each command by environment variables.
pg_dump --username={USER} --host={HOST} --port={PORT} {DATABASENAME} | \
gzip | \
openssl enc -aes-256-cbc -pbkdf2 -iter 10000 -pass env:SG_TINY_BACKUP_ENCRYPTION_KEY | \
aws s3 cp - s3://{BUCKET}/{PREFIX}{TIMESTAMP}.sql.gz.enc
After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. 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 the created tag, and push the .gem file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/SonicGarden/sg_tiny_backup.
The gem is available as open source under the terms of the MIT License.