-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackupdb
executable file
·48 lines (40 loc) · 1.19 KB
/
backupdb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env bash
# Made by Sinfallas <[email protected]>
# Licence: GPL-2
LC_ALL=C
SECONDS=0
IFS=" "
LOCKFILE="/tmp/$(basename $0)_$(whoami)"
LOCKFD="150"
nom=$(basename "$0")
fecha=$(date +%d%m%Y)
function clean_1() {
rm -f /run/$(basename $0).pid
rm -f "$LOCKFILE"
}
function lock() {
echo {LOCKFD}>$LOCKFILE
flock -n $LOCKFD
}
function exit_error() {
echo "ERROR: Ya hay una instancia en ejecución. Saliendo"
exit 1
}
echo "$BASHPID" > /run/$(basename $0).pid
trap "clean_1; exit" 0 1 2 3 15
lock || exit_error
clear
if ! [[ -f /app/lista.txt ]]; then
echo "ERROR: el archivo /app/lista.txt, favor consulte la documentacion."
exit 1
fi
mkdir -p /app/$fecha
while read -r ip puerto usuario clave db; do
echo "$ip", "$puerto", "$usuario", "$clave", "$db"
verori=$(PGPASSWORD=$clave psql -h $ip -p $puerto -U $usuario -d $db -c 'show server_version;' | grep -v '(1 row)' | grep -v 'server_version' | sed 1d | sed 2d | cut -c 1-6)
echo "version: $verori"
PGPASSWORD="$clave" pg_dump -Fc -h $ip -p $puerto -U $usuario -d $db > /app/$fecha/$db-$ip-$puerto.dump
echo "==================="
done < ./lista.txt
echo "duracion $SECONDS segundos"
echo "Finalizado."