如何检查Postgres备份是否成功(无需手动操作?)>

问题描述 投票:1回答:1

我们有100多个数据库,其中包含每日备份

如何在PostgreSQL备份计划中检查故障备份

pg_dump -h localhost -p 5432  -U postgres -d db1  -v -f "path/file.backup"
pg_dump -h localhost -p 5432  -U postgres -d db2  -v -f "path/file.backup"
pg_dump -h localhost -p 5432  -U postgres -d db3  -v -f "path/file.backup"
pg_dump -h localhost -p 5432  -U postgres -d db4  -v -f "path/file.backup"
pg_dump -h localhost -p 5432  -U postgres -d db5  -v -f "path/file.backup"
...

像这样,我有100个备份时间表

[我们有100多个数据库,其中包含每日备份,如何在PostgreSQL备份计划中检查故障备份pg_dump -h localhost -p 5432 -U postgres -d db1 -v -f“ path / file.backup” pg_dump -h ...] >

postgresql postgresql-9.5
1个回答
0
投票

例如尝试在for loop中执行此操作?

#!/bin/bash

# create an indexed array with all your databases listed
database_names=( "1" "2" "3" )

# Declare an assotiative array to store dbname and dump status codes
declare -A all_dbdump_states

for db in "${database_names[@]}"; do
   echo "Executing $db dump.."
   pg_dump -h localhost -p 5432 -U postgres -d $db -v -f "path/file.backup"
   dump_rc=$? # Save exit code of pg_dump process into variable

   # After each for loop iteration, append data into array
   all_dbdump_states[$db]+=$dump_rc
done

echo -e "\nListing status codes of all dumps:"
for db in "${!all_dbdump_states[@]}"; do
   echo "Database [$db] status: ${all_dbdump_states[$db]}"
   sleep 1
done           
© www.soinside.com 2019 - 2024. All rights reserved.