前提是已经熟悉PostGreSQL的命令
1:bkpg.sh的内容:
#!/bin/bash
/usr/local/pgsql/bin/pg_dump -hlocalhost -p5431 -Ugroupware hitware>/data/back/hitware/`date +%Y-%m-%d-%T`.sql
/usr/local/pgsql/bin/pg_dump -hlocalhost -p5431 -Ugroupware stemsoft>/data/back/stemsoft/`date +%Y-%m-%d-%T`.sql
2:backpg.sh的内容:
#!/usr/bin/expect
#Description:The Scrpit is auto backup the postgresql database at 8:00 PM # every day
#Author:wang.changchun@stemsoft
#Date:2008-12-10
set passwd "12345678"
spawn ~/bin/bkpg.sh;
expect "*Password:";
sleep 0.1;
send "$passwd\r";
expect "*Password:";
sleep 0.1;
send "$passwd\r";
#等待60秒(1分钟);如果不等待,只生成文件,而导出动作没有时间执行。
sleep 60;
#back hitware
#spawn "/usr/local/pgsql/bin/pg_dump -h localhost -p 5431 -U groupware hitware > /data/back/`date +%Y-%m-%d-%T`.sql [lindex $argv 0]";
#expect "*Password:";
#sleep 1;
#send "$passwd\r";
把上面的两个文件存到PostGreSQL用户的bin目录下,赋予执行权限。
然后用crontab -e添加到用户的定时任务就可以了。
阅读(5929) | 评论(0) | 转发(0) |