← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6975: Updated backup script

 

------------------------------------------------------------
revno: 6975
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-05-17 13:46:53 +0200
message:
  Updated backup script
modified:
  resources/backup/pg_backup.sh
  resources/backup/readme.txt


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'resources/backup/pg_backup.sh'
--- resources/backup/pg_backup.sh	2011-12-05 15:58:38 +0000
+++ resources/backup/pg_backup.sh	2012-05-17 11:46:53 +0000
@@ -1,13 +1,32 @@
-#!/bin/sh
-
-backup_dir="/var/backups/pg_backups"
-datetime=`date +%F`
-backupfile="$backup_dir/pg-backup-$datetime.gz"
-
-echo "Starting backup..."
-
-/usr/bin/pg_dump dhis2ke -U postgres -T aggregated* | gzip > $backupfile
-
-timeinfo=`date '+%T %x'`
-
-echo "Backup file $backupfile complete at $timeinfo"
+#!/bin/bash
+
+# The backupdir must be created manually (mkdir pg_backups)
+# The backupdir owner must be changed to postgres (chown postgres pg_backups)
+# Script must be made executable (chmod 755 pg_backup.sh)
+# Script must be invoked by postgres user
+# Postgres user must have a home dir (usermod -d /home/postgres postgres) and private/public key pair (ssh-keygen -t rsa)
+# Postgres user public key must be uploaded to remote server (if remote copy)
+
+DATE_TIME=`date +%F`
+BACKUP_DIR="/var/backups/pg_backups"
+DB_NAME="dhis2demo"
+BACKUP_FILE="${BACKUP_DIR}/pg-${DB_NAME}-${DATE_TIME}.gz"
+REMOTE="true"
+REMOTE_DEST="username@xxxxxxxxxx:backup_dir/"
+
+echo "Starting backup of ${DB_NAME} to ${BACKUP_FILE}..."
+
+/usr/bin/pg_dump ${DB_NAME} -U postgres -T aggregated* | gzip > ${BACKUP_FILE}
+
+TIME_INFO=`date '+%T %x'`
+
+echo "Backup file ${BACKUP_FILE} complete at ${TIME_INFO}"
+echo "Starting remote copy to ${REMOTE_DEST}..."
+
+if [[ ${REMOTE} == "true" ]]; then
+  scp ${BACKUP_FILE} ${REMOTE_DEST}
+fi
+
+TIME_INFO=`date '+%T %x'`
+
+echo "Backup file ${BACKUP_FILE} copied to ${REMOTE_DEST} at ${TIME_INFO}"

=== modified file 'resources/backup/readme.txt'
--- resources/backup/readme.txt	2012-02-26 20:37:36 +0000
+++ resources/backup/readme.txt	2012-05-17 11:46:53 +0000
@@ -7,9 +7,11 @@
 
 - The backupdir must be created manually (mkdir pg_backups)
 - The backupdir owner must be changed to postgres (chown postgres pg_backups)
+- Script must be copied to /usr/local/bin/
 - Script must be made executable (chmod 755 pg_backup.sh)
 - Script must be invoked by postgres user so load crontab as postgres
-- Script must be copied to /usr/local/bin/
+- Postgres user must have a home dir (usermod -d /home/postgres postgres) and private/public key pair (ssh-keygen -t rsa)
+- Postgres user public key must be uploaded to remote server (if remote copy)
 
 2) pg_backup.cron - crontab file invoking the script every day at 23:00