原 在Linux系统中定时pg_dump逻辑导出备份PG或GreenPlum数据库(异机备份、动态生成导出命令)
Tags: 原创GreenPlumPostgreSQL备份恢复定时任务逻辑导出导入异地备份pg_dump异机备份
脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | cat > /home/gpadmin/ct_pg_dump.sql <<"EOF" \copy ( SELECT '/usr/local/greenplum-db/bin/pg_dump -U gpadmin -h 100.11.11.75 --dbname=LHRDB --format=custom --file=/bk/LHRDB_'||tablename||'_'||TO_CHAR(NOW(), 'YYYYMMDDHH24MISS') ||'.bk --table='||d.schemaname||'.'||tablename bk1 from pg_tables d where d.schemaname in ('public') and tablename not like 'staging_gpload_reusable_%' and tablename not like 'ext_gpload_%') to '/bk/bk_tb.sh'; EOF cat >> /home/gpadmin/bk_gp.sh <<"EOF" #!/bin/bash find /bk/ -type f -mtime +3 -exec rm -f {} \; LOGFILE="/bk/bk_gp.log" echo "Starting script at: $(date '+%Y-%m-%d %H:%M:%S')" >> $LOGFILE echo "Running ct_pg_dump.sql at: $(date '+%Y-%m-%d %H:%M:%S')" >> $LOGFILE /usr/local/greenplum-db/bin/psql -U gpadmin -h 100.11.11.75 --dbname=LHRDB -f /home/gpadmin/ct_pg_dump.sql echo "Running bk_tb.sh at: $(date '+%Y-%m-%d %H:%M:%S')" >> $LOGFILE sh /bk/bk_tb.sh >> $LOGFILE 2>&1 echo "Script finished at: $(date '+%Y-%m-%d %H:%M:%S')" >> $LOGFILE EOF sh /home/gpadmin/bk_gp.sh -- 每周五晚上20点 [gpadmin@gp-master ~]$ crontab -l 0 20 * * 5 sh /home/gpadmin/bk_gp.sh |