PostgreSQL:备份脚本只创建一次备份而不是每小时
PostgreSQL : Backup script creating only once backup instead of hourly
我在 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]/ && != "|" {print }'))
# 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
中使用绝对路径。
我在 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]/ && != "|" {print }'))
# 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
中使用绝对路径。