• postgresql 备份脚本


    1. 脚本

    # vim /root/pgback.sh
    !#/bin/bash
    cd /
    back=/home/backup
    
    send=`date '+%Y-%m-%d'`
    
    pg_dump --dbname="postgresql://127.0.0.1:5432/tenant_1008412?user=postgres&password=csb123456" -F c -b -v -f "$back/tenant_1008412-"$send".backup"
    pg_dump --dbname="postgresql://127.0.0.1:5432/xw_metadata?user=postgres&password=csb123456" -F c -b -v -f "$back/xw_metadata_1008412-"$send".backup"
    pg_dump --dbname="postgresql://127.0.0.1:5432/xw_platform?user=postgres&password=csb123456" -F c -b -v -f "$back/xw_platform_1008412-"$send".backup"
    pg_dump --dbname="postgresql://127.0.0.1:5432/xw_quartz?user=postgres&password=csb123456" -F c -b -v -f "$back/xw_xw_quartz_1008412-"$send".backup"

    2. 修改脚本中的 pg 连接,租户库名称,用户密码

    chmod +x /root/pg_back之后添加 crontab 作业

    3. 定时任务

    # crontab -e
    1 1 * * * /root/pgback.sh

    4. 恢复数据库

    #平台库
    create database xw_platform with encoding='utf8';
    ./pg_restore -U postgres -d xw_platform -v  "/usr/local/pgsql/database_backup/xw_platform.20190428.backup"
    #元数据
    create database xw_metadata with encoding='utf8';
    ./pg_restore -U postgres -d xw_metadata -v  "/usr/local/pgsql/database_backup/xw_metadata.2019042801.backup"
    #调度库
    create database xw_quartz with encoding='utf8';
    ./pg_restore -U postgres -d xw_quartz -v  "/usr/local/pgsql/database_backup/xw_quartz.20190428.backup"
    #租户库
    create database tenant_1008428 with encoding='utf8';
    ./pg_restore -U postgres -d tenant_1008428 -v  "/usr/local/pgsql/database_backup/tenant_1008428.20190428.backup"

     [root@master ~]# /opt/pg10/bin/pg_restore    -h 127.0.0.1  -U postgres -d  runoobdb    -p31800   -v  "/root/runoobdb-2021-03-10.backup"



     

     

    用一个例子来演示会更加清晰
  • 相关阅读:
    RedHat的定制安装
    Linux系统概述
    嵌入式学习方法
    mysql联合查询
    mysql之count
    memcached安装
    css书写规则
    nginx的fastcgi_param参数详解
    array_2.array_rand
    array_1.array_map
  • 原文地址:https://www.cnblogs.com/hixiaowei/p/14511862.html
Copyright © 2020-2023  润新知