We already have defined these in database.yml and application.yml so we want to re-use these. In :db_backup model you define things like the database name, user, password and credentials for S3. Our model is called db_backup and is automatically stored in config/models/db_backup.rb by the generator. Run the Generator to create a general configuration and a model for a backup.First you install the backup gem:gem install backup.How can we run backup outside of our application environment and still use this configuration and Rails specific values? This is how we did it. Although backup advices NOT to include the gem in Gemfile, we do want to store the configuration for the backup in the Rails application. backup gem provides an easy to use interface for handling backup. When you start a Rails console and enter _settings.aws_access_key_id you will see the key you defined in your environment file. In the end, I got this (working) permission:īackup : bucket : ' my-bucket' connection_settings : aws_access_key_id : aws_secret_access_key : region : ' eu-west-1'Īs you can see, we also defined other S3 settings, to keep them all in one place. The simplest way to define permissions is by using the Policy Generator, but it still took me a few hours to get this working, cause I misunderstood the format to use when defining a Resource (hence the /*, which grants the group for the content of the bucket).Credentials for a user are only supplied once, so make sure you store them in a safe place.Creating a user and a group is very straight forward with the IAM Management Console, but keep the following in mind: We also define a group Backup where the user belongs to and give this group access to the bucket. We create a separate user for performing the backup. Here you add a rule to have files of a specific age cleanup for you. In the Amazon S3 console, select the bucket, choose Properties and open LifeCycle. Instead of managing this programmatically, you can define a rule for your bucket which takes care of cleaning up old backups. It’s ok for backups older than 30 days to be removed (or at least: in our case). For this you just follow the AWS documentation. For this, of course, this bucket needs to be created. Our back up will be uploaded to an Amazon S3 bucket my-app.backups. Creating a location, credentials and permission on Amazon The bucket So I figured, why not sharing it with the world. Nevertheless, it took me about 1.5 day to have this sorted out and get this up and running. Well, so seems to be playing Eddie Van Halen’s Eruption. Creating a backup of a (PostgreSQL) database in your Rails application should be easy.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |