How can I automatically restore my Heroku Postgres staging database from a daily backup? - automation

I have my Heroku production database scheduled to make daily backups, and I want to restore the backups onto my staging database daily as well. This way I can keep the staging box in sync with production for testing/debugging purposes and have a daily test of the restoration process run automatically.
I've tried to schedule a bash script to run on the staging box to perform the restore. The script I have uses the Heroku CLI to pull the url of the latest backup and perform the restoration. The problem I have is with authenticating the Heroku CLI. Since I can't open a browser on the dyno, I need to find a safe way to authenticate.
Should I pull a .netrc file from somewhere? Is it even a good idea to give a dyno the CLI? Is there a better way to go about this without standing up another server to run the restorations?

You can put an authorization token in the HEROKU_API_KEY env variable on your staging environment. Generate the token with heroku auth:token.
Then set the token on staging with heroku config:set HEROKU_API_KEY=token -a staging
From a security standpoint, this means your staging environment pretty much has full access to your production environment.
A more secure way is to have a scheduled task run on the production app or a new app just for this purpose that copies the db backup to an S3 bucket the staging app has access to. The staging app the restores from the backup in the s3 bucket. Staging needs no access to production.
This is a good idea anyway - if you lose access to Heroku you'll still have access to your backups.
There's a buildpack for this - https://github.com/kbaum/heroku-database-backups. I encourage you to read the code in the build pack - it is a pretty simple processes. I would also either fork the buildpack, or just write your own code because it will have full access to your production environment. I woud never trust a third party buildpack with that.
Bonus points if your job scrubs sensitive information from your production database for staging. It could do this by:
Restoring the production backup to second database
Scrub sensitive information from the second database
Backup the second database
Push the second database backup to the S3 bucket.

Related

Perform a full environment automatic backup

does anybody know a way to perform a periodic remote backup of the full environment (so comprehensive of the application servers and SQL databases) in Jelastic?
I wanted to use Google Drive to store the backups as I was already using it with Plesk.
Thanks.

Dev Environment creation from Prod for Azure SQL

I have a production server in Azure SQL. I have created a another empty server(dev) for development purpose. I need a copy of the tables, views, stored procedure in the dev server as well. Please suggest some way to transfer the data to dev server database
#John11 : You can take a backup of your Production Database and then simply restore on your Dev server
Ideally Production data restore to Dev is not advisable if it is a highly confidential data
If you just need to move the schema without data then you can use DevOps / CI-CD to deploy the artifacts to Dev

How to create production database in hanami?

Hanami has some commands to create a database.
But both db create and db prepare are not available in production environment.
http://hanamirb.org/guides/command-line/database/
How can I create a database in production?
It depends.
We deliberately disabled these commands in production, because they can be potentially destructive and we can't guess where you're gonna deploy your project.
Is that Heroku? Well, add it via their CLI. Do you use a VPS? Is the database on the same node? Does the Unix user who runs the Ruby process have the permissions to create the database? We can't guess.
It depends where you're gonna deploy.

I want to make staging database the same as production on Azure

My production and staging databases are on Azure and I want to make staging the same as production. I have no idea what to do, I have never worked with databases. I use SQL Server 2014.
There are a few ways to do this, but the quickest way would probably be to replace your staging database when you want the updated data by Creating a new database as a copy. Now, this would wipe out any changes to your staging database, but would be the fastest way.
More complicated, but probably a bit more about what you're actually thinking of, would be setting up azure data sync from Prod -> Staging.
Staging Azure web app has different configuration with production Azure web app. We can configure the same connection string at Azure portal to achieve this requirement. Refer to this article for more information about how to configure connection string in Azure portal. At runtime, Azure Web App will automatically retrieves values in Azure portal and makes them available to code running in your website. If the same connection string configured in Azure portal, the staging and production will use the same database.

How do backups work in DirectAdmin?

I'm sure there's a good amount of developers here that use DirectAdmin and I had a quick question.
I've always used cPanel and I'm not on a server that is using DirectAdmin instead. Where in DirectAdmin can you generate a full backup of the account at the user level?
Also, do DirectAdmin backups include everything related to the account like cPanel backups do? For example, not only the files and databases but also the cron jobs, DNS zones, email accounts, etc.?
And where are the backups stored by default? Is there an option to send the backups to a remote server via FTP like you can with cPanel?
There are two different backup systems built into DA:
Admin Tools | System Backup. This tool lets you backup configuration data and arbitrary directories, locally or using FTP or SCP.
Admin Tools | Admin Backup/Transfer. This tool is oriented toward backing up data account by account, in one archive per account, in a format that you can use to restore from (in the same tool) on the original or another DA server (i.e. if you want to transfer to a new server). You can back up locally and/or via FTP.
Both options can also be scheduled via cron.
Depending on your level of access, only one of these might be available to you. This page has further info for non-administrators: http://www.site-helper.com/backup.html.
You can improve your DirectAdmin backup with an incremental backup plugin that includes local and remote backup location, please check the setup guide here