File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -631,7 +631,9 @@ migrate_db_using_dump_file() {
631631 safe_mv " $PREFIX /share" postgresql " $PREFIX /share.new"
632632 # restore old backup
633633 safe_cp " $BACKUP_DIR " data " $PREFIX /state/pg"
634- safe_cp " $BACKUP_DIR " bin " $PREFIX "
634+ safe_cp_nolink " $BACKUP_DIR " bin " $PREFIX "
635+ # Ensure restored old binaries are executable by cfpostgres.
636+ chmod 755 " $PREFIX /bin" /* 2> /dev/null || true
635637 on_files cp " $BACKUP_DIR /lib" " $PREFIX /lib"
636638 safe_cp " $BACKUP_DIR /lib" postgresql " $PREFIX /lib"
637639 safe_cp " $BACKUP_DIR /share" postgresql " $PREFIX /share"
@@ -745,6 +747,14 @@ do_migration() {
745747 else
746748 DEBUG=0
747749 fi
750+
751+ # cfpostgres runs the old binaries during the migration (ENT-14899)
752+ if ! su cfpostgres -c " test -x $BACKUP_DIR /bin/pg_ctl" ; then
753+ cf_console echo " Warning: cfpostgres can't execute the old PostgreSQL binaries, setting them to 755:"
754+ cf_console ls -l " $BACKUP_DIR /bin"
755+ chmod 755 " $BACKUP_DIR /bin" /*
756+ fi
757+
748758 cd /tmp
749759 cf_console echo " Migrating database using pg_upgrade utility..."
750760 cf_console echo
Original file line number Diff line number Diff line change @@ -252,7 +252,13 @@ if migrating_postgres; then
252252 # the postgresql.conf file was modified, we should try to use it after migration
253253 cp -a " $BACKUP_DIR /data/postgresql.conf" " $BACKUP_DIR /data/postgresql.conf.modified"
254254 fi
255- safe_cp " $PREFIX " bin " $BACKUP_DIR "
255+ # Copy, don't hardlink: policy managing perms under $PREFIX/state/pg (e.g.
256+ # CFE-951 in masterfiles) would otherwise change the live binaries too.
257+ safe_cp_nolink " $PREFIX " bin " $BACKUP_DIR "
258+ # Normalize executable permissions so cfpostgres can run old PG binaries
259+ # during migration, whatever mode damage the source already had.
260+ chmod 755 " $BACKUP_DIR /bin" /* 2> /dev/null || true
261+ chmod 711 " $BACKUP_DIR /bin" 2> /dev/null || true
256262 on_files cp " $PREFIX /lib" " $BACKUP_DIR /lib"
257263 safe_cp " $PREFIX /lib" postgresql " $BACKUP_DIR /lib"
258264 safe_cp " $PREFIX /share" postgresql " $BACKUP_DIR /share"
Original file line number Diff line number Diff line change @@ -136,6 +136,21 @@ safe_cp() {
136136 return 1
137137}
138138
139+ safe_cp_nolink () {
140+ # Like `safe_cp`, but never creates hardlinks, so the copy does not share
141+ # mode and owner with the source. Args are same as in safe_cp.
142+ test " $# " -eq 3 || return 2
143+ from=" $1 "
144+ name=" $2 "
145+ to=" $3 "
146+ if cp -a " $from /$name " " $to " ; then
147+ return 0
148+ fi
149+ echo " Copy failed, so removing partially-copied data and aborting"
150+ rm -rf " $to /$name "
151+ return 1
152+ }
153+
139154safe_mv () {
140155 # "safe" alternative to `mv`. Executes `safe_cp` and deletes source dir if
141156 # that succeeds.
You can’t perform that action at this time.
0 commit comments