X-Original-To: alpine-devel@lists.alpinelinux.org Delivered-To: alpine-devel@lists.alpinelinux.org Received: from mail.squbes.com (squbes.com [208.74.142.49]) by lists.alpinelinux.org (Postfix) with ESMTP id 5D3B61EB598 for ; Thu, 13 May 2010 06:10:43 +0000 (UTC) Received: from [10.252.6.46] (c-71-198-150-62.hsd1.ca.comcast.net [71.198.150.62]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: nangel@nothome.org) by mail.squbes.com (Postfix) with ESMTPSA id 36BEC50001CA0 for ; Thu, 13 May 2010 06:10:42 +0000 (UTC) Message-ID: <4BEB97F0.4060304@nothome.org> Date: Wed, 12 May 2010 23:10:56 -0700 From: Nathan Angelacos User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9) Gecko/20100411 Icedove/3.0.4 X-Mailinglist: alpine-devel Precedence: list List-Id: Alpine Development List-Unsubscribe: List-Post: List-Help: List-Subscribe: MIME-Version: 1.0 To: Alpine-devel Subject: [alpine-devel] Patch to postgresql init script Content-Type: multipart/mixed; boundary="------------070509060000010808030205" This is a multi-part message in MIME format. --------------070509060000010808030205 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Attached is a patch for /etc/init.d/postgresql and /etc/conf.d/postgresql A lbu commit of the /var/lib/postgresql/x.x/data directory takes a very long time if the database is running. apk-tools 2.0 includes the ability (/etc/lbu/pre-package.d) to make a pg_dumpall of the databases, and then commit the archive. This is much faster. There has not been a way to automatically restore the backup on reboot. This patch attempts to address that issue Limitations: The archive is assumed to be created with pg_dumpall -U postgres | gzip -c >/some/path/here.gz * bzip2 or plain dumps are not supported You must do a lbu_include /some/path/here.gz and also edit /etc/conf.d/postgresql to define LBU_BACKUP=/some/path/here.gz postgresql stores the pg_hba.conf (access controls) and postgresql.conf in $PGDATA; so if you have password protection on the postmaster account (a good idea); that gets lost. This script addresses that by moving the files in $PGDATA out of the way, restoring the database, and then moving them back. This way you can do a lbu include /var/lib/postgresql/8.4/data/pg_hba.conf and get the access controls on the restored databases. --------------070509060000010808030205 Content-Type: text/x-patch; name="postgresql-restore.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="postgresql-restore.patch" >From d4f7f491ff2fe5628fad55e5777129e5b5f2a636 Mon Sep 17 00:00:00 2001 From: Nathan Angelacos Date: Wed, 12 May 2010 22:36:57 -0700 Subject: [PATCH] Patches to allow postgresql to restore a pg_dump made by an lbu commit These patches cause postgresql to load a gzip archive of a pg_dump file defined in /etc/conf.d/postgresql on initial load. This allows postgresql to "restore its state" on reboot --- main/postgresql/postgresql.confd | 6 +++++ main/postgresql/postgresql.initd | 43 ++++++++++++++++++++++++++++++++++--- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/main/postgresql/postgresql.confd b/main/postgresql/postgresql.confd index 4fe28a4..5361e1f 100644 --- a/main/postgresql/postgresql.confd +++ b/main/postgresql/postgresql.confd @@ -7,6 +7,12 @@ PGUSER="postgres" # PostgreSQL Group PGGROUP="postgres" +# Alpine Linux LBU can create a database backup with /etc/lbu/pre-package.d/ +# If you create a dump with pg_dumpall -U postgres | gzip -c >/root/pgdatabases.gz +# uncommenting the next line will restore the database on reboot +# For more information see the lbu docs on www.alpinelinux.org +# LBU_BACKUP="/root/pgdatabases.gz" + # Extra options to run postmaster with, e.g.: # -N is the maximal number of client connections # -B is the number of shared buffers and has to be at least 2x the value for -N diff --git a/main/postgresql/postgresql.initd b/main/postgresql/postgresql.initd index 23b0acf..b4fa762 100644 --- a/main/postgresql/postgresql.initd +++ b/main/postgresql/postgresql.initd @@ -2,6 +2,7 @@ # Copyright 1999-2008 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Header: /var/cvsroot/gentoo-x86/dev-db/postgresql-server/files/postgresql.init-8.3,v 1.4 2008/09/28 22:53:02 caleb Exp $ +# Modifications for database Reload on Alpine Linux - 2010 opts="${opts} reload setup" @@ -11,18 +12,52 @@ depend() { } checkconfig() { - [ -d "$PGDATA" ] && return 0 - - if [ -z "$AUTO_SETUP" ] || [ "$AUTO_SETUP" = "no" ]; then + if [ ! -d "$PGDATA" ] ; then eerror "Directory not found: $PGDATA" eerror "Please make sure that PGDATA points to the right path." eerror "You can run '/etc/init.d/postgresql setup' to setup a new database cluster." return 1 fi - setup +} + +restore_lbu_dump() { + # this function calls start, which calls this function. Exit early if we called start + [ "$LBU_RESTORE_ACTIVE" ] && return + LBU_RESTORE_ACTIVE=1 + + if [ -e "$LBU_BACKUP" ] ; then + ewarn "Found an lbu backup file - restoring it." + if [ -e "$PGDATA"/base ] ; then + eerror "The database directories are already created - not restoring the backup" + return 1 + fi + + # If the pg_hba.conf and friends exist, move them + local tmpdir=$( dirname "$PGDATA" )/tmp + mkdir -p "$tmpdir" + mv "$PGDATA"/* "$tmpdir" 2>/dev/null + + rm -rf "$PGDATA" + einfo "Initializing a new database directory" + setup + start + + einfo "Extracting the lbu backup file" + # assume it is gzip + gunzip -c "$LBU_BACKUP" | psql -U postgres >/dev/null 2>/dev/null + + # move the pg_hba.conf and friends + mv $tmpdir/* "$PGDATA" 2>/dev/null + rm -rf $tmpdir 2>/dev/null + + rm -f "$LBU_BACKUP" + stop + return $? + fi } start() { + restore_lbu_dump checkconfig || return 1 ebegin "Starting PostgreSQL" -- 1.7.1 --------------070509060000010808030205-- --- Unsubscribe: alpine-devel+unsubscribe@lists.alpinelinux.org Help: alpine-devel+help@lists.alpinelinux.org ---