linux - PostgreSQL : Backup script creating only once backup instead of hourly

标签 linux database postgresql cron database-backups

我在 Debian 系统上工作,其中运行着 PostgreSQL 服务器。我修改了一个备份脚本并安装了一个 cron 作业来对我们的数据库进行每小时备份,并将其存储在一个文件夹中。与此同时,还会执行一个脚本,删除超过 3 天的备份。我在 3 台服务器上安装了相同的脚本,但我看到只有一台备份存在。而不是 15,因为 15 小时过去了。我做错了什么,还是删除脚本错误?

post_back.sh :

#! /bin/bash
DUMPALL='/usr/bin/pg_dumpall'
PGDUMP='/usr/bin/pg_dump'
PSQL='/usr/bin/psql'

# directory to save backups in, must be rwx by postgres user
BASE_DIR='/media/attachment/backups/postgres'
YMD=$(date "+%Y-%m-%d-%T")
DIR="$BASE_DIR/$YMD"
mkdir -p "$DIR"
cd "$DIR"

# get list of databases in system , exclude the tempate dbs
DBS=($($PSQL --list --tuples-only |
          awk '!/template[01]/ && $1 != "|" {print $1}'))

# first dump entire postgres database, including pg_shadow etc.
$DUMPALL --column-inserts | gzip -9 > "$DIR/db.out.gz"

# next dump globals (roles and tablespaces) only
$DUMPALL --globals-only | gzip -9 > "$DIR/globals.gz"

# now loop through each individual database and backup the
# schema and data separately
for database in "${DBS[@]}" ; do
    ALL="$DIR/$database.all.backup" 
 #dump all
    $PGDUMP -Fc "$database" > "$ALL"
done

# delete backup files older than 3 days
echo deleting old backup files:
find "$BASE_DIR/" -mindepth 1 -type d -mtime +3 -print0 |
    xargs -0r rm -rfv

定时任务:

0 * * * * ./home/postgres/post_back.sh

备份目录的ls命令:

/media/attachment/backups/postgres # ls
2016-09-13-14:00:01

谢谢。

最佳答案

问题出在 crontab 条目路径中的前导 .

建议您在crontab中使用绝对路径。

关于linux - PostgreSQL : Backup script creating only once backup instead of hourly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39484614/

相关文章:

sql - 如何将来自不同列的多个列组合到一个表或 View 中?

postgresql - Go语言,Postgres : cannot get oid after Scan

PHP readdir( ) 返回 ". "和 ".. "条目

c - 如何在 C 中定义 arduino 字节数组

json - 如何在Django中将搜索查询结果转换为Json可序列化对象

sql - Oracle 数据致密化填补空白

linux - 网络上所有机器的主机名发现

linux - 让 Linux 串行控制台在 imx31 上工作

SQL 连接两个表中任一表中的空值

arrays - PostgreSQL:更新 JSONB 结构内嵌套数组中元素的属性