你笑了

你的笑,是星星跳跃浪花的笑

0%

pg_dump自动备份数据库

db_bak.exp 脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/expect -d
# add -d enable debug info
# 删除10天之前的备份
exec find /path/to/bak -type f -mtime +10 | xargs rm -rf
set timeout 30
set date [clock format [clock seconds] -format {%Y-%m-%d}]
set channel [open "/path/to/log/db_bak.log" w]
set devfile $date\_dev.dump
puts $channel "$date backup dev db start..."
spawn pg_dump -h [host] -U [db user] -d [db name] -p 5432 -x -Fc -f /path/to/bak/$devfile
# 这里根据系统语言调整
expect "*口令:"
send "[db pwd]\r"
expect eof
set date2 [clock format [clock seconds] -format {%Y-%m-%d %H:%M:%S}]
puts $channel "$date2 backup dev db end!"