36
36
today=`date +'%Y-%m-%d'`
37
37
fdoy="`date +'%Y'`-01-01" # first day of year
48
usage: $PROGRAM [command]
50
This script helps to create synchronization environments.
51
See exportrc file to see which params can be changed.
54
help show this help message
55
all launch a server, the MKDB script and create an archive of the result (tar.xz extension)
56
noarchive launch a server and the MKDB script without any archive
100
if [ $# -lt 1 ]; then
101
echo "Need 1 parameter"
115
echo "Command: NOARCHIVE"
123
echo "Command $command not found!"
129
82
# Configuration file exists and is readable
130
83
if ! [ -r $configfile ] ; then
131
84
error_and_exit "${configfile}: missing"
158
111
check_cmd_presence $cmdname $pkgname
114
# openerp-client-lib 1.0.1 presence
115
openerp_clientlib=`pip search openerp-client-lib|grep INSTALLED|cut -d ':' -f 2|tr -d ' '`
116
if ! [ "${openerp_clientlib}" == "1.0.1" ] ; then
117
error_and_exit "openerp-client-lib 1.0.1 missing.\nInstall it: sudo pip install openerp-client-lib==1.0.1"
119
echo "openerp-client-lib 1.0.1: installed."
161
121
# tmp directory presence. If not create it.
162
122
if [ -a "$tmpdir" ] ; then
163
123
if ! [ -d "$tmpdir" ] ; then
253
213
stop_server ${pidfile}
255
if [ "$ARCHIVE" == 1 ] ; then
257
# create a list file containing all files to save
258
list="${tmpdir}/${dbname}.list"
259
if ! [ -a "$list" ] ; then
216
# create a list file containing all files to save
217
list="${tmpdir}/${dbname}.list"
218
if ! [ -a "$list" ] ; then
223
# update each DB, save it in a dump file, add it to a list to save and drop DB
224
for db in `psql template1 -t -c "SELECT datname from pg_database where datname ilike '${dbname}_%';"`; do
227
dumpfile="${db}.dump"
228
if [ -a "$dumpfile" ] ; then
229
error_and_exit "$dumpfile already exists! Aborted."
264
# update each DB, save it in a dump file, add it to a list to save and drop DB
265
for db in `psql template1 -t -c "SELECT datname from pg_database where datname ilike '${dbname}_%';"`; do
268
dumpfile="${db}.dump"
269
if [ -a "$dumpfile" ] ; then
270
error_and_exit "$dumpfile already exists! Aborted."
272
echo -e -n "Saving '$db' to $dumpfile: "
273
pg_dump -Fc $db > $dumpfile
274
echo "$dumpfile" >> ${list}
279
## Add some file into list file to archive
280
echo "manage_syncdb.sh" >> ${list}
281
echo "manage_syncdbrc" >> ${list}
284
echo -n "Creating archive: "
285
archive="`date +'%Y%m%d'`_${dbname}.tar.xz"
286
tar cfJ $archive `cat $list|tr -s '\n' ' '` || error_and_exit "An error occured to create archive: $archive."
287
echo "$archive DONE."
289
## Delete all DB dumps
231
echo -e -n "Saving '$db' to $dumpfile: "
232
pg_dump -Fc $db > $dumpfile
233
echo "$dumpfile" >> ${list}
238
## Add some file into list file to archive
239
echo "manage_syncdb.sh" >> ${list}
240
echo "manage_syncdbrc" >> ${list}
243
echo -n "Creating archive: "
244
archive="`date +'%Y%m%d'`_${dbname}.tar.xz"
245
tar cfJ $archive `cat $list|tr -s '\n' ' '` || error_and_exit "An error occured to create archive: $archive."
246
echo "$archive DONE."
248
## Delete all DB dumps
293
251
########################
294
252
## WORK IN PROGRESS