Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Creating PG Backup On Heroku

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 410
    Comment on it

    As we all know that creating a backup of your project is very crucial for any application , not just to recover your application in case of any unseen conditions but also for testing , creating a new server , migration etc.

    Until recently heroku does provide us with a free addon know as "PGBackups" but its has been depreciated. Thus in order user wants to take backup of his PG database being presently hosted on heroku he needs to follow the following steps.

    $ heroku pg:backups capture --app test_staging

    By default, pg:backups operates against your primary database that is identified by the DATABASE_URL mentioned in config var.

    If you have multiple database then you can choose it by mentioning the specified database as given below.

    $  heroku pg:backups capture HEROKU_POSTGRESQL_CHARCOAL

    Where HEROKU_POSTGRESQL_CHARCOAL is the name of database for which you want to take backup. You can use command --verbose in order to see logs as the backup proceed , similarly if you ever need to stop backup any time after running it can be done as

    $ heroku pg:backups cancel

    Heroku has a limit for the number of backup that you can maintain on the server depending on your plan , will delete oldest backup if the limit exceeds.

    If you want to schedule the backup so that it happens automatically it can be done as :

    $ heroku pg:backups schedule DATABASE_URL --app test_staging

    Backup time can also be scheduled any specific time with respect to a particular timezone like :

    $ heroku pg:backups schedule --at '02:00 America/Los_Angeles' DATABASE_URL --app test_staging

    For more information regarding timezone please refer the following link :

    http://en.wikipedia.org/wiki/List_of_tz_database_time_zones

    To unshedule a particular sheduled backup use the following command :

    $ heroku pg:backups unscheduled DATABASE_URL --app test_staging

    To view all the schedule for a particular app use the following command :

    $ heroku pg:backups schedules --app test_staging

    To download your backup you can create a public url which is accessible directly from a browser but it has a time limit after which it expires :

    $ heroku pg:backups public-url b001 --app test_staging

    To check the logs of backup with the list use the following command :

    $ heroku pg:backups --app test_staging

    To delete a particular backup use the following command :

    $ heroku pg:backups delete b101 --app test_staging

    If you ever want to restore the database it can be done on the following way :

    $ heroku pg:backups restore b101 DATABASE_URL --app test_staging

    where b101 is the database backup id which you checked with (heroku pg:backups --app test_staging)

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: