zoukankan      html  css  js  c++  java
  • postgres数据库备份脚本

    问题描述

    postgres数据库之前没有备份机制,现在加上以防万一。每周末备份1次,只保留最新的3个sql文件

    shell脚本

    #config begin
    meta_host="*.*.*.*"
    mete_user="mete_user"
    mete_databse="mete_databse"
    mete_password="mete_password"
    meta_port="meta_port"
    back_path="/home/soft/psql/backup/"
    back_count=3
    #config end
    echo $(date +%Y-%m-%d %H:%M:%S)" pg_dump begin"
    #备份数据库文件
    date=$(date +%Y-%m-%d)
    PGPASSWORD=${mete_password} /opt/PostgreSQL/9.5/bin/pg_dump -U ${mete_user} -d ${mete_databse} > ${back_path}sjck_${date}.sql
    echo $(date +%Y-%m-%d %H:%M:%S)" pg_dump end"
    #只保留最新的3个文件,删除旧的
    c=0
    for file in `ls ${back_path}`
    do
        filelist[$c]=$file
        ((c++))
    done
    size=${#filelist[*]}
    echo "文件数组长度:" ${size}
    for value in ${filelist[@]}
    do
        echo $value
    done
    if [ ${size} -gt ${back_count} ]
    then
        echo "size>" ${back_count}
        for ((i=0; i<${size}-${back_count}; i++))
        do
            echo "要删除的过期excel文件夹:" ${filelist[$i]}
            rm -rf ${back_path}${filelist[$i]}
        done
    else
        echo "size<=" ${back_count}
    fi
    echo $(date +%Y-%m-%d %H:%M:%S)" task end"
    

    运行截图

  • 相关阅读:
    第10组 Beta冲刺(2/5)
    第10组 Beta冲刺(1/5)
    第10组 Alpha事后诸葛亮
    3月7-第十次机试课记录
    3月5-第九次机试课记录
    3月2-第八次机试课记录
    3月1-第六次机试课记录
    2月28-第五次机试课记录
    STL
    2月27-第四次机试课记录
  • 原文地址:https://www.cnblogs.com/wanli002/p/11174034.html
Copyright © 2011-2022 走看看