PageRenderTime 20ms CodeModel.GetById 14ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 1ms

/src/scripts/zotonic-copysite

https://code.google.com/p/zotonic/
#! | 51 lines | 46 code | 5 blank | 0 comment | 0 complexity | df98313a9982841d821767cf34631b98 MD5 | raw file
 1#!/usr/bin/env bash
 2#
 3# Copyright 2011 Lloyd R. Prentice
 4#
 5# Licensed under the Apache License, Version 2.0 (the "License");
 6# you may not use this file except in compliance with the License.
 7# You may obtain a copy of the License at
 8# 
 9#     http://www.apache.org/licenses/LICENSE-2.0
10# 
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17#
18# usage zotonic-copysite [site_name] [source_server]
19#
20
21SITE=$1
22SERVER=$2
23
24if [ ! $SITE ]
25then
26	echo USAGE: $0 [site_name] [source_server] 1>&2
27	echo USAGE: See ZotonicCommands.txt 1>&2
28else
29	if [ ! $SERVER ]
30	then
31		echo USAGE: $0 [site_name] [source_server] 1>&2
32	else
33		ssh $SSH_OPTIONS zotonic@$SERVER "$ZOTONIC_BIN/zotonic snapshot $SITE"
34		rsync -ae "ssh $SSH_OPTIONS" zotonic@$SERVER:$SITES/$SITE/ \
35				--include=files/archive \
36				--include=files/backup \
37				--include=files/snapshot \
38				--include=files \
39				--exclude=files/* \
40				$SITES/$SITE
41
42		PANIC_FILE=`tempfile`
43		pg_dump zotonic_$SITE > $PANIC_FILE
44		echo "To restore if this goes wrong: psql zotonic_$SITE < $PANIC_FILE"
45
46		echo "\pset tuples_only on
47		SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'" \
48		  | psql zotonic_$SITE --quiet | xargs -i echo 'DROP TABLE {} CASCADE;' | psql zotonic_$SITE
49		psql zotonic_$SITE < $SITES/$SITE/files/snapshot/zotonic_$SITE.sql
50	fi
51fi