/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. # usage zotonic-copysite [site_name] [source_server]
  18. #
  19. SITE=$1
  20. SERVER=$2
  21. if [ ! $SITE ]
  22. then
  23. echo USAGE: $0 [site_name] [source_server] 1>&2
  24. echo USAGE: See ZotonicCommands.txt 1>&2
  25. else
  26. if [ ! $SERVER ]
  27. then
  28. echo USAGE: $0 [site_name] [source_server] 1>&2
  29. else
  30. ssh $SSH_OPTIONS zotonic@$SERVER "$ZOTONIC_BIN/zotonic snapshot $SITE"
  31. rsync -ae "ssh $SSH_OPTIONS" zotonic@$SERVER:$SITES/$SITE/ \
  32. --include=files/archive \
  33. --include=files/backup \
  34. --include=files/snapshot \
  35. --include=files \
  36. --exclude=files/* \
  37. $SITES/$SITE
  38. PANIC_FILE=`tempfile`
  39. pg_dump zotonic_$SITE > $PANIC_FILE
  40. echo "To restore if this goes wrong: psql zotonic_$SITE < $PANIC_FILE"
  41. echo "\pset tuples_only on
  42. SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'" \
  43. | psql zotonic_$SITE --quiet | xargs -i echo 'DROP TABLE {} CASCADE;' | psql zotonic_$SITE
  44. psql zotonic_$SITE < $SITES/$SITE/files/snapshot/zotonic_$SITE.sql
  45. fi
  46. fi