Skip to content

Instantly share code, notes, and snippets.

@spikegrobstein
Forked from robertsosinski/daily.sh
Created April 30, 2012 02:35

Revisions

  1. spike grobstein revised this gist Apr 30, 2012. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion postgres_backup.sh
    Original file line number Diff line number Diff line change
    @@ -4,8 +4,13 @@
    ## postgres_backup
    ## back up postgres on a regular basis
    ## USAGE:
    ## ./postgres_backup [ <prefix> ]
    ## ./postgres_backup [ <prefix> ] [ <number_to_keep> ]
    ## prefix will default to 'pg'
    ## number_to_keep defaults to 2
    ##
    ## Creates a backup in the form of <prefix>_<number>
    ## Number to keep is the number of backups to keep (still not implemented.)
    ##
    ## convention says you should use 'd' for daily backups and 'h' for hourly backups.
    ## example (for hourly):
    ## ./postgres_backup h
  2. spike grobstein renamed this gist Apr 30, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. spike grobstein revised this gist Apr 30, 2012. 1 changed file with 33 additions and 1 deletion.
    34 changes: 33 additions & 1 deletion hourly.sh
    Original file line number Diff line number Diff line change
    @@ -1 +1,33 @@
    #!/bin/bash
    #! /bin/bash -

    ####
    ## postgres_backup
    ## back up postgres on a regular basis
    ## USAGE:
    ## ./postgres_backup [ <prefix> ]
    ## prefix will default to 'pg'
    ## convention says you should use 'd' for daily backups and 'h' for hourly backups.
    ## example (for hourly):
    ## ./postgres_backup h
    ## example (for daily):
    ## ./postgres_backup d
    ####


    # initialize some variables

    BACKUP_DIR="/var/postgres/backup/"
    DATABASE="exchange_prod"
    ENCODING="SQL_ASCII"
    PG_DUMP="/usr/bin/pg_dump"
    PREFIX="${1:-pg}" # default to 'pg' for prefix

    cd "$BACKUP_DIR"

    # clean up
    rm -f "${PREFIX}_2" || true
    mv "${PREFIX}_1" "${PREFIX}_2"

    # do backup!
    $PG_DUMP -E${ENCODING} -Upostgres -Fc -f"${PREFIX}_1" "$DATABASE" \
    || { echo "Errors occurred when backing up. OH NO." 2>&1; exit 1; }
  4. Robert Sosinski created this gist Apr 30, 2012.
    1 change: 1 addition & 0 deletions hourly.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    #!/bin/bash