Change to user root without end the script

Hello there!
I need help:

I have this script:

#!/bin/bash

#chage to root user
sudo su

#Insert actual date
echo -n "Ingrese fecha actual: "

#Read the actual date
read fecha

#clean RAM memory
sync ;  echo 3 > /proc/sys/vm/drop_caches ; swapoff -a && swapon -a

#backup opennms files
tar cvfzP opennms_etc_$fecha.tar.gz /etc/opennms/* -R

#copy PostgreSQL Client Authentication Configuration File
cp /etc/postgresql/8.3/main/pg_hba.conf pg_hba.conf

#copy PostgreSQL configurarion file
cp /etc/postgresql/8.3/main/postgresql.conf postgresql.conf

#change to postgres user
su - postgres

#backup PostgreSQL database
pg_dumpall  > opennms_all_$fecha.sql
exit

#Move PostgreSQL database to the home directory
sudo mv opennms_all_$fecha.sql /home/bobbasystem

#Change to default user
su - bobbasystem

#copy all backuped files to main server
scp opennms_etc_$fecha.tar.gz trancos@172.17.40.232:
scp opennms_all_$fecha.sql     trancos@172.17.40.232:
scp pg_hba.conf               trancos@172.17.40.232:
scp postgresql.conf           trancos@172.17.40.232:

#end

and when I change in the first line to root user, the script terminates without executing the rest.
If I delete these instructions and run the script with sudo su,
the instructions su -postgres can be executed, but not the rest.

How do I get the script does not end in these instructions?

Sorry for my english.

Thanks!

The reason is simple: su runs a program given on the command line as the user specified, or just executes a shell if none is given. It won't change the permissions of a script it's called from (can't even, as that would have to be done by the shell itself).

If you have it, you can use sudo with the -u switch to change the user for single commands. Otherwise, you're probably better off if you put the commands into a temporary script, run that as root/postgres, and delete it afterwards.

thanks for your help pludi!