~jfb-tempo-consulting/unifield-wm/sync-env-py3

« back to all changes in this revision

Viewing changes to export.sh

  • Committer: Cecile Tonglet
  • Date: 2013-10-17 14:40:19 UTC
  • Revision ID: cto@openerp.com-20131017144019-grjgxx09qz1q311p
[FIX] Version problem with openerplib

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
today=`date +'%Y-%m-%d'`
37
37
fdoy="`date +'%Y'`-01-01" # first day of year
38
38
 
39
 
# Args
40
 
ARCHIVE=1
41
 
 
42
39
#####
43
40
## FUNCTIONS
44
41
###
45
42
 
46
 
usage() {
47
 
  cat << EOF
48
 
usage: $PROGRAM [command]
49
 
 
50
 
This script helps to create synchronization environments.
51
 
See exportrc file to see which params can be changed.
52
 
 
53
 
COMMANDS:
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
57
 
EOF
58
 
}
59
 
 
60
43
error_and_exit() {
61
44
  echo -e $1
62
45
  exit 1
96
79
## TESTS
97
80
###
98
81
 
99
 
# Check params
100
 
if [ $# -lt 1 ]; then
101
 
  echo "Need 1 parameter"
102
 
  usage
103
 
  exit 1
104
 
fi
105
 
 
106
 
command=$1
107
 
 
108
 
# Check command
109
 
case $command in 
110
 
  all)
111
 
  echo "Command: ALL"
112
 
  ;;
113
 
  noarchive)
114
 
  ARCHIVE=0
115
 
  echo "Command: NOARCHIVE"
116
 
  ;;
117
 
  help)
118
 
  echo "Command: HELP"
119
 
  usage
120
 
  exit 0
121
 
  ;;
122
 
  *)
123
 
  echo "Command $command not found!"
124
 
  usage
125
 
  exit 1
126
 
  ;;
127
 
esac
128
 
 
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
159
112
done
160
113
 
 
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"
 
118
fi
 
119
echo "openerp-client-lib 1.0.1: installed."
 
120
 
161
121
# tmp directory presence. If not create it.
162
122
if [ -a "$tmpdir" ] ; then
163
123
  if ! [ -d "$tmpdir" ] ; then
252
212
## Stop server
253
213
stop_server ${pidfile}
254
214
 
255
 
if [ "$ARCHIVE" == 1 ] ; then
256
 
  ## Save databases
257
 
  # create a list file containing all files to save
258
 
  list="${tmpdir}/${dbname}.list"
259
 
  if ! [ -a "$list" ] ; then
260
 
    touch $list
261
 
  else
262
 
    echo "" > $list
 
215
## Save databases
 
216
# create a list file containing all files to save
 
217
list="${tmpdir}/${dbname}.list"
 
218
if ! [ -a "$list" ] ; then
 
219
  touch $list
 
220
else
 
221
  echo "" > $list
 
222
fi
 
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
 
225
  pre_process_db "$db"
 
226
  # save DB
 
227
  dumpfile="${db}.dump"
 
228
  if [ -a "$dumpfile" ] ; then
 
229
    error_and_exit "$dumpfile already exists! Aborted."
263
230
  fi
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
266
 
    pre_process_db "$db"
267
 
    # save DB
268
 
    dumpfile="${db}.dump"
269
 
    if [ -a "$dumpfile" ] ; then
270
 
      error_and_exit "$dumpfile already exists! Aborted."
271
 
    fi
272
 
    echo -e -n "Saving '$db' to $dumpfile: "
273
 
    pg_dump -Fc $db > $dumpfile
274
 
    echo "$dumpfile" >> ${list}
275
 
    dropdb $db
276
 
    echo "DONE."
277
 
  done
278
 
 
279
 
  ## Add some file into list file to archive
280
 
  echo "manage_syncdb.sh" >> ${list}
281
 
  echo "manage_syncdbrc" >> ${list}
282
 
 
283
 
  ## Create archive
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."
288
 
 
289
 
  ## Delete all DB dumps
290
 
  rm -f *.dump
291
 
fi
 
231
  echo -e -n "Saving '$db' to $dumpfile: "
 
232
  pg_dump -Fc $db > $dumpfile
 
233
  echo "$dumpfile" >> ${list}
 
234
  dropdb $db
 
235
  echo "DONE."
 
236
done
 
237
 
 
238
## Add some file into list file to archive
 
239
echo "manage_syncdb.sh" >> ${list}
 
240
echo "manage_syncdbrc" >> ${list}
 
241
 
 
242
## Create archive
 
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."
 
247
 
 
248
## Delete all DB dumps
 
249
rm -f *.dump
292
250
 
293
251
########################
294
252
## WORK IN PROGRESS