gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 09:23:23 27 4
gpt4 key购买 nike

我在 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com