写了一个备份Postgresql数据文件的超简单Linux Shell


#!/bin/bash
#author:lovejuan1314
#date:2008-12-19
#This script will dump servers's views data per month
#
#

#Define a array to store all of table names which will be backuped to here
array=(`psql --quiet --tuples-only -h server_name -p 5432 -U slony db_name -c "SELECT tablename FROM pg_tables WHERE tablename like 'fb_fy_views_%';"`)
#Array 's length
len=${#array[ * ]} echo "The array has $len members. They are:"
i=0
while [ $i -lt $len ]; do
echo "$i: ${array[$i]}"
#dump table
pg_dump -t ${array[$i]} -i -O -h server_name -p 5432 -U slony -f "${array[$i]}.pgdump" -F c -Z 9 db_name
let i++
done


tar czvf .tar.gz *.pgdump

rm -rf *.pgdump


你可能感兴趣的:(写了一个备份Postgresql数据文件的超简单Linux Shell)