X-Original-To: pgsql-admin@postgresql.org Received: from THOR.goeci.com (thor.goeci.com [66.28.220.99]) by postgresql.org (Postfix) with ESMTP id 5379C474E44 for ; Fri, 14 Mar 2003 13:58:31 -0500 (EST) Received: by THOR.goeci.com with Internet Mail Service (5.5.2653.19) id ; Fri, 14 Mar 2003 13:58:31 -0500 Message-ID: <2D92FEBFD3BE1346A6C397223A8DD3FC09218F@THOR.goeci.com> From: Murthy Kambhampaty To: 'Matt Clark' , pgsql-admin@postgresql.org Subject: Re: LVM snapshots Date: Fri, 14 Mar 2003 13:58:30 -0500 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: multipart/mixed; boundary="----_=_NextPart_000_01C2EA5B.B4057DDC" X-Archive-Number: 200303/235 X-Sequence-Number: 7875 This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_000_01C2EA5B.B4057DDC Content-Type: text/plain; charset="iso-8859-1" Here's the script I use to mount a snapshot and rsync to a remote server; postgresql is started and stopped on the remote server as part of the backup procedure to make sure that the backup log contains any errors that might show up. The restore strategy is to start the postmaster on the remote server and dump restore like so: pgdump -Fc -h -U -d -t | pgrestore -h -U -d -t
[-c] Note that this is not particularly safe with 7.3, since pgrestore will try to restore every table in the database with the given name. If you use the schema feature that allows indentically named tables in different schema, you're in for trouble when you recover it. Backup restore has been tested so far by restoring a table and comparing the contents; they were identical. Thanks to rsync performance is fantastic compared to pgdump to a file (my past e-mail to the list will give some idea of the problems we've had with that). I'd be interested in comments on the strategy and the script itself. Cheers, Murthy -----Original Message----- From: Matt Clark [mailto:matt@ymogen.net] Sent: Friday, March 14, 2003 13:22 To: pgsql-admin@postgresql.org Subject: Re: [ADMIN] LVM snapshots Thanks all. The conclusion there seemed to be that it ought to work just fine, but should be tested. Well, I'll test it and see if anything interesting comes up. If anything LVM snapshots will be less tricky than NetApp snapshots as LVM has access to the OS's local cache buffers, whereas the NetApp doesn't (though presumably the OS shouldn't/doesn't do any write caching when writing to a network FS). -----Original Message----- From: pgsql-admin-owner@postgresql.org [mailto:pgsql-admin-owner@postgresql.org]On Behalf Of Trewern, Ben Sent: 14 March 2003 17:55 To: 'Matt Clark' Cc: pgsql-admin@postgresql.org Subject: Re: [ADMIN] LVM snapshots Try - [GENERAL] A few questions to real pgsql gurus Ben ------_=_NextPart_000_01C2EA5B.B4057DDC Content-Type: application/octet-stream; name="pgSnapBack.sh" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="pgSnapBack.sh" #!/bin/bash # FN: pgsnapshot. # AB: creates and mounts snapshot of $PGDATA; rsyncs from compa5; # reinitializes database on backup server; unmounts and removes snapshot # DT: 2003-03-05 # AU: S. Murthy Kambhampaty # An e-mail address for the monitor: pgMonitor=3D"" # "log" instances of this script as follows: # (this form is good for unattended scripts; for manually run scripts # you might want to save and restore stdin and stdout; see # http://www.tldp.org/LDP/abs/html/x11830.html#REDIR, example 16-3) LogFile=3D"/var/log/`basename $0 .sh`-`date +%Y%m%d-%H%M`" exec > "$LogFile" exec 2> "$LogFile.err" echo "$(date +%c): Backup initiated" pgSRV=3D"$(echo -e `hostname` | awk 'BEGIN{FS=3D"."}{print $1}')" BackupSRV=3D"host2" DataFS=3D"/home/db" DataLV=3D"/dev/VG00/LVdb" SnapNM=3D"pgsnapshot" SnapLV=3D"/dev/VG00/$SnapNM" SnapDir=3D"/mnt/$SnapNM" RshCMD=3D"ssh -i /home/postgres/.ssh/id_rsa postgres@$BackupSRV" RsyncSRC=3D"$pgSRV::pgsnapshot/pgsql/" RsyncDST=3D"/home/db/mirrors/$pgSRV" RsyncOpts=3D"-avW --stats --exclude=3D'postmaster.pid' --delete" # First vacuum all databases echo $'\n\n' "$(date +%c): Vacuuming databases on `hostname`" # Mark vacuum start and end in the log to ease log navigation /usr/local/pgsql/bin/psql -U pguser -d template1 -c \ "select '+++++ Nightly Vacuum About To Commence +++++'" >/dev/null /usr/local/pgsql/bin/vacuumdb -U postgres -q -a && \ /usr/local/pgsql/bin/psql -U pguser -d template1 -c \ "select '+++++ Nightly Vacuum Completed +++++'" >/dev/null && \ echo $'\n\t' "$(date +%c): Successfully vacuumed databases on `hostname`" # Now create and mount the snapshot volume echo $'\n\n' "$(date +%c): Snapshot creation and mounting" /usr/sbin/xfs_freeze -f "$DataFS" /sbin/lvcreate -s -l 1536 -n "$SnapNM" "$DataLV"; SnapTest=3D$? # Record ex= it status of lvcreate /usr/sbin/xfs_freeze -u "$DataFS" # If snapshot creation succeeded, mount the snapshot volume; else bail if [[ $SnapTest -eq 0 ]]; then echo $'\n\t' "$(date +%c): Successfully created snapshot" mount "$SnapLV" "$SnapDir" -o nouuid,norecovery,ro else echo $'\n\t' "$(date +%c): Snapshot failed." \ $'\n\t' "(Is it already mounted?)" \ $'\n\t' "!!! Terminating backup ..." >&2 exit fi # Do the backup # The backup is controlled from a remote shell on the backup server # to keep CPU utilization on the database server low echo $'\n\n' "$(date +%c): Rsync from snapshot to mirror on $BackupSRV" $RshCMD rsync "$RsyncOpts" "$RsyncSRC" "$RsyncDST" 2>&1 && \ echo "$(date +%c): Rsync complete"; echo $'\n\n' # Remove the snapshot on rsync completion umount "$SnapLV" /sbin/lvremove -f "$SnapLV" # "Reinitialize" the snapshot of the database on the backup server echo $'\n\n' "$(date +%c): Start postmaster on $BackupSRV, capture output, = and shutdown" $RshCMD /usr/local/pgsql-7.3/bin/postmaster -D "$RsyncDST/data" 2>&1 & sleep 60 # give the postmaster time for recovery $RshCMD /usr/local/pgsql-7.3/bin/pg_ctl stop -D "$RsyncDST/data" echo $'\n\n' "$(date +%c): Attempted to reinitialize backup; check for erro= rs above" if [ ! -s "$LogFile.err" ]; then rm -f "$LogFile.err" echo $'\n\n' "$(date +%c): Backup completed (without errors)-ish" # Why do= es postmaster log to sterr, rather than stdout? :-( else cat "$LogFile.err" | /usr/sbin/postfix.sendmail $pgMonitor echo $'\n\n' "$(date +%c): Backup encountered errors" \ $'\t' "Notified $pgMonitor" fi ------_=_NextPart_000_01C2EA5B.B4057DDC--