因为我的greenplum很多数据表都是从其他库同步过来,不需要进行全库备份,所以就使用定时更新需要备份的文件,然后使用gpbackup进行备份
获取需要备份的数据表名称
/home/gpadmin/backup_lxcs_data.py
import pandas as pd
import sys
from sqlalchemy import create_engine
def main():
postgresql_config = {
'host': '192.168.200.201',
'port': 5432,
'database': 'lxcs_data',
'username': 'gpadmin',
'password': 'qaz123...'
}
db = create_engine(
'postgresql+psycopg2://{username}:{password}@{host}:{port}/{database}'.format(**postgresql_config))
sql="""select concat('public.',tablename) as tablename from pg_tables where schemaname = 'public' and (tablename ~'^(gp_)' or tablename ~'^(import_)' or tablename ~'^(tmp_)') """
data = pd.read_sql_query(sql, db)
fileObject = open('/home/gpadmin/include_file.txt', 'w')
for t in data.tablename.unique():
fileObject.write(t)
fileObject.write('\n')
print('finish')
if __name__ == '__main__':
try

最低0.47元/天 解锁文章
1573

被折叠的 条评论
为什么被折叠?



