Skip to content

Commit be752bb

Browse files
committed
- added possibility to specify sharetype (smb:qnap or filesystem)
- configuration file to use can be passed as first parameter to script
1 parent 43044c7 commit be752bb

File tree

4 files changed

+42
-19
lines changed

4 files changed

+42
-19
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ EDIT 1.0 - 28.12.2017: ignore template databases while backing up
33
EDIT 1.0 - 30.12.2017: ignore databases disallowing connections and include template databases while backing up
44
EDIT 1.0 - 02.01.2018: changed the path looking for psql and pg_dump commands
55
EDIT 1.1 - 22.04.2018: added server-, port- and searchfolders-configuration in configfile, added example with default values for configfile
6+
EDIT 1.1 - 23.04.2018: added possibility to specify sharetype (smb:qnap or filesystem), configuration file to use can be passed as first parameter to script

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ Place the users password in the config file.
4040

4141
# Location of configuration file
4242
The config file is to be placed here: /etc/config/pgsqlbackup.conf
43+
Alternatively, the configuration file to be used can also be passed to the script as the first parameter.

examples/pgsqlbackup.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ week_retention=5
44
month_retention=3
55
day_rotate=0
66
share=
7+
sharetype=smb:qnap
78
user=User
89
pw=Password
910
errorlvl=0

pgsqlbackup.sh

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,6 @@
2020
# Thanks to Kenneth Fribert for mysqlbackup (https://forum.qnap.com/viewtopic.php?t=15628)
2121
#
2222

23-
# Read config file
24-
config="/etc/config/pgsqlbackup.conf"
25-
day_ret=$(/sbin/getcfg pgsqlbackup day_retention -f $config)
26-
week_ret=$(/sbin/getcfg pgsqlbackup week_retention -f $config)
27-
month_ret=$(/sbin/getcfg pgsqlbackup month_retention -f $config)
28-
weekday_rot=$(/sbin/getcfg pgsqlbackup day_rotate -f $config)
29-
share=$(/sbin/getcfg pgsqlbackup share -f $config)
30-
folder=$(/sbin/getcfg pgsqlbackup folder -f $config)
31-
user=$(/sbin/getcfg pgsqlbackup user -f $config)
32-
pw=$(/sbin/getcfg pgsqlbackup pw -f $config)
33-
level=$(/sbin/getcfg pgsqlbackup errorlvl -f $config)
34-
searchfolders=$(/sbin/getcfg pgsqlbackup searchfolders -f $config)
35-
server=$(/sbin/getcfg pgsqlbackup server -f $config)
36-
port=$(/sbin/getcfg pgsqlbackup port -f $config)
37-
3823
# Standard commands used in this script
3924
rm_c="/bin/rm"
4025
tar_c="/bin/tar"
@@ -46,6 +31,29 @@ md_c="/bin/mkdir"
4631
ls_c="/bin/ls"
4732
date_c="/bin/date"
4833

34+
# Check config file to use
35+
if [[ -z "$1" ]] ; then config="/etc/config/pgsqlbackup.conf" ; else config=$1 ; fi
36+
if [ ! -e "$config" ] ; then
37+
$ec_c -e "PostgreSQL Backup: ERROR: configuration file not found"
38+
$log_c "PostgreSQL Backup: ERROR configuration file not found" 1
39+
exit 1
40+
fi
41+
42+
# Read config file
43+
day_ret=$(/sbin/getcfg pgsqlbackup day_retention -f "$config")
44+
week_ret=$(/sbin/getcfg pgsqlbackup week_retention -f "$config")
45+
month_ret=$(/sbin/getcfg pgsqlbackup month_retention -f "$config")
46+
weekday_rot=$(/sbin/getcfg pgsqlbackup day_rotate -f "$config")
47+
share=$(/sbin/getcfg pgsqlbackup share -f "$config")
48+
sharetype=$(/sbin/getcfg pgsqlbackup sharetype -f "$config")
49+
folder=$(/sbin/getcfg pgsqlbackup folder -f "$config")
50+
user=$(/sbin/getcfg pgsqlbackup user -f "$config")
51+
pw=$(/sbin/getcfg pgsqlbackup pw -f "$config")
52+
level=$(/sbin/getcfg pgsqlbackup errorlvl -f "$config")
53+
searchfolders=$(/sbin/getcfg pgsqlbackup searchfolders -f "$config")
54+
server=$(/sbin/getcfg pgsqlbackup server -f "$config")
55+
port=$(/sbin/getcfg pgsqlbackup port -f "$config")
56+
4957
# Internal variable setup
5058
arc=$($date_c +%y%m%d).tar.gz
5159
dest=
@@ -129,17 +137,29 @@ if [[ -z "$day_ret" ]] ; then day_ret="6" ; warn "days to keep backup not set in
129137
if [[ -z "$week_ret" ]] ; then week_ret="5" ; warn "weeks to keep backup not set in config, setting to 5" ; fi
130138
if [[ -z "$month_ret" ]] ; then month_ret="3" ; warn "months to keep backup not set in config, setting to 3" ; fi
131139
if [[ -z "$weekday_rot" ]] ; then weekday_rot="0" ; warn "weekly rotate day not set in config, setting to sunday" ; fi
132-
if [[ -z "$share" ]] ; then share="Backup" ; warn "share for storing Backup not set in config, setting to Backup" ; fi
140+
if [[ -z "$share" ]] ; then share="Backup" ; warn "share for storing backup not set in config, setting to Backup" ; fi
141+
if [[ -z "$sharetype" ]] ; then sharetype="smb:qnap" ; info "sharetype for storing backup not set in config, setting to smb:qnap" ; fi
133142
if [[ -z "$user" ]] ; then user="User" ; warn "PostgreSQL user for backup not set in config, setting to User" ; fi
134143
if [[ -z "$pw" ]] ; then pw="Password" ; warn "PostgreSQL password for backup not set in config, setting to Password" ; fi
135144
if [[ -z "$searchfolders" ]] ; then searchfolders="/share/CACHEDEV1_DATA/.qpkg/PostgreSQL /share/CACHEDEV1_DATA/.qpkg/Optware" ; info "PostgreSQL searchfolders for backup not set in config, setting
136145
to default for Qnap" ; fi
137146
if [[ -z "$server" ]] ; then server="127.0.0.1" ; info "PostgreSQL server for backup not set in config, setting to 127.0.0.1" ; fi
138147
if [[ -z "$port" ]] ; then port="5432" ; info "PostgreSQL server port for backup not set in config, setting to 5432" ; fi
139148

140-
# Check for backup share
141-
bkup_p=$($get_c "$share" path -f /etc/config/smb.conf)
142-
if [ $? != 0 ] ; then error "the share $share is not found, remember that the destination has to be a share" ; else info "Backup share found" ; fi
149+
# Check for backup share using sharetype
150+
case $(tr '[:upper:]' '[:lower:]' <<<"$sharetype") in
151+
"smb:qnap")
152+
bkup_p=$($get_c "$share" path -f /etc/config/smb.conf)
153+
if [ $? != 0 ] ; then error "the share $share is not found, remember that the destination has to be a share" ; else info "Backup smb share found" ; fi
154+
;;
155+
"filesystem")
156+
bkup_p=$share
157+
if [ ! -d "$bkup_p" ] ; then error "the share $share is not found in filesystem" ; else info "Backup filesystem share found" ; fi
158+
;;
159+
*)
160+
error "the sharetype $sharetype is unknown, supported types are smb:qnap or filesystem"
161+
;;
162+
esac
143163

144164
# Add subfolder to backup share
145165
if [[ -z "$folder" ]] ; then

0 commit comments

Comments
 (0)