@@ -8,6 +8,19 @@ IFS=$'\n\t'
8
8
9
9
progname=" $0 "
10
10
11
+ case " $( uname) " in
12
+ Linux)
13
+ # Linux tools have long names for these options.
14
+ recursive=" --recursive"
15
+ directory=" --directory"
16
+ force=" --force"
17
+ ;;
18
+ * )
19
+ # These shoud work on any POSIX system
20
+ recursive=" -r"
21
+ directory=" -d"
22
+ force=" -f"
23
+ esac
11
24
12
25
function die {
13
26
echo " $1 "
@@ -134,14 +147,14 @@ function create_snapshot {
134
147
tgz_file=$1 .tgz
135
148
dbfile=$1 .sql
136
149
ledger_file=$2
137
- tmp_dir=$( mktemp -- directory -t db-sync-snapshot-XXXXXXXXXX)
150
+ tmp_dir=$( mktemp " ${ directory} " -t db-sync-snapshot-XXXXXXXXXX)
138
151
echo $" Working directory: ${tmp_dir} "
139
152
pg_dump --no-owner --schema=public " ${PGDATABASE} " > " ${tmp_dir} /$1 .sql"
140
153
cp " $ledger_file " " $tmp_dir /$( basename " ${ledger_file} " ) "
141
- tar zcvf - --directory " ${tmp_dir} " " ${dbfile} " " $( basename " ${ledger_file} " ) " \
142
- | tee " ${tgz_file} .tmp " | sha256sum | sed -e " s/-/ ${tgz_file} /" > " ${tgz_file} .sha256sum"
154
+ tar zcvf - --directory " ${tmp_dir} " " ${dbfile} " " $( basename " ${ledger_file} " ) " | tee " ${tgz_file} .tmp " \
155
+ | sha256sum | head -c 64 | sed -e " s/$/ ${tgz_file} \n /" > " ${tgz_file} .sha256sum"
143
156
mv " ${tgz_file} .tmp" " ${tgz_file} "
144
- rm -rf " ${tmp_dir} "
157
+ rm " ${recursive} " " ${force} " " ${tmp_dir} "
145
158
if test " $( gzip --test " ${tgz_file} " ) " ; then
146
159
echo " Gzip reports the snapshot file as being corrupt."
147
160
echo " It is not safe to drop the database and restore using this file."
@@ -156,13 +169,13 @@ function restore_snapshot {
156
169
echo " Ledger state directory ($2 ) is not empty. Please empty it and then retry."
157
170
exit 1
158
171
fi
159
- tmp_dir=$( mktemp -- directory -t db-sync-snapshot-XXXXXXXXXX)
172
+ tmp_dir=$( mktemp " ${ directory} " -t db-sync-snapshot-XXXXXXXXXX)
160
173
tar -zxvf " $1 " --directory " $tmp_dir "
161
174
db_file=$( find " $tmp_dir /" -iname " *.sql" )
162
175
lstate_file=$( find " ${tmp_dir} /" -iname " *.lstate" )
163
176
mv " ${lstate_file} " " $2 "
164
177
psql --dbname=" ${PGDATABASE} " -f " ${db_file} "
165
- rm -- recursive " ${tmp_dir} "
178
+ rm " ${ recursive} " " ${tmp_dir} "
166
179
}
167
180
168
181
function usage_exit {
@@ -252,15 +265,19 @@ case "${1:-""}" in
252
265
check_pgpass_file
253
266
check_db_exists
254
267
if test $# -ne 3 ; then
255
- echo " Expecting exactly 2 more arguments, the snapshot file name template and the ledger state directory ."
268
+ echo " Expecting exactly 2 more arguments, the snapshot file name template and the ledger state file ."
256
269
exit 1
257
270
fi
258
271
if test -z " $2 " ; then
259
272
echo " Second argument should be the snapshot file name template."
260
273
exit 1
261
274
fi
262
275
if test -z " $3 " ; then
263
- echo " Third argument should be the ledger state directory."
276
+ echo " Third argument should be the ledger state file."
277
+ exit 1
278
+ fi
279
+ if test -d " $3 " ; then
280
+ echo " Third argument is a directory and expecting a file."
264
281
exit 1
265
282
fi
266
283
create_snapshot " $2 " " $3 "
0 commit comments