/[scripts]/trunk/pgsql-backup-cron.sh
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /trunk/pgsql-backup-cron.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 17 - (hide annotations)
Wed Jan 25 22:12:28 2006 UTC (17 years ago) by dpavlin
File MIME type: application/x-sh
File size: 1073 byte(s)
backup all PostgreSQL databases in separate directories, making dumps named
like dates (thus keeping last 30-or-so versions).

1 dpavlin 17 #!/bin/sh
2    
3     dir=/data/sql-backup
4    
5     function do_dump () {
6     echo -n `date +"%Y-%m-%d %H:%M:%S"` $db_name
7     psql -q -c "vacuum full analyze" $1
8     test ! -d "$dir/$1" && mkdir "$dir/$1"
9     file=$dir/$1/`date +%d`.sql.gz
10     /usr/bin/pg_dump -i $1 | gzip > $file
11     gzip -l $file | tail -1 | sed 's/ */ /g' | cut -d" " -f-4
12     }
13    
14     psql -c "select datname from pg_database where not datistemplate and datname not in ('phpOpenTracker','') order by datname" -A -t template1 | while read db_name
15     do
16     #echo $db_name
17     do_dump $db_name
18     done
19    
20     ## sync databases (poor man's replication)
21     #
22     #(
23     # echo "BEGIN;"
24     #
25     # echo "delete from open_positions;"
26     # pg_dump --data-only --no-reconnect -t open_positions -U dpavlin --no-owner --inserts corp
27     #
28     # echo "delete from open_position_locations;"
29     # pg_dump --data-only --no-reconnect -t open_position_locations -U dpavlin --no-owner --inserts corp
30     #
31     # echo "delete from open_positions_company;"
32     # pg_dump --data-only --no-reconnect -t open_positions_company -U dpavlin --no-owner --inserts corp
33     #
34     # echo "COMMIT;"
35     #) | psql -q -h erec.pliva.hr -U dpavlin erec
36    

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26