Search code examples
databasepostgresqlherokubackup

How can I schedule to backup my database monthly


I want to do backup for my website database monthly without involving me everytime I put this code everytime to backup my website heroku pg:backups:capture --app appname Is there any code that i can add to backup monthly?


Solution

  • You ask about monthly backups. In case you're okay with more frequent backups, you can schedule daily backups using heroku pg:backups:schedule (' quotes converted to " for compatibility with Windows):

    Scheduled Backups

    In addition to manually triggered backups, you can schedule regular automatic backups. These run daily against the specified database.

    Set Up a Backup Schedule

    heroku pg:backups:schedule DATABASE_URL --at "02:00 America/Los_Angeles" --app example-app
    

    The --at option uses a 24-hour clock to indicate the hour of the day that you want the backup taken. It also accepts a timezone in either the full TZ format (America/Los_Angeles) or the abbreviation (PST), but we recommend using the full TZ format.

    Note that backup retention depends on the database tier, varying from 7 daily backups and 1 weekly backup all the way up to 7 daily backups, 8 weekly backups, and 12 monthly backups. If you need longer retention, you'll have to retrieve your backups from Heroku and store them elsewhere.

    If you really want monthly backups and not daily ones, you'll have to schedule backups some other way, e.g. using a cron job on another system.