0

I'm lookign for a way to create backups from several databases and send result files to server in Debian Linux 6 (Sqeeze) from crontab job There are databases named database1 .. database4 Backup from every db shoudl created and sent using ftp

I tried script below, but send.sh script does not finis automatically: it must terminated by keyboard. How to fix ? How to make script shorter?

Crontab script:

#!/bin/sh
PGUSER=postgres
PGPASSWORD=mymass
export PGUSER PGPASSWORD
backupdir=/root/mybackups
backupdate=$(date +%u)

baas=database1
export baas backupdate
fail=${backupdir}/${baas}${backupdate}.backup
pg_dump -U postgres ${baas} -f ${fail}
./saada.sh

baas=database2
export baas backupdate
fail=${backupdir}/${baas}${backupdate}.backup
pg_dump -U postgres ${baas} -f ${fail}
./saada.sh

baas=database3
export baas backupdate
fail=${backupdir}/${baas}${backupdate}.backup
pg_dump -U postgres ${baas} -f ${fail}
./saada.sh

baas=database4
export baas backupdate
fail=${backupdir}/${baas}${backupdate}.backup
pg_dump -U postgres ${baas} -f ${fail}
./saada.sh

sending which does not exit saada.sh is

#!/bin/sh
/usr/bin/ftp -inp <<EOF
open mybackupsite.com
user backupuser  pass
bin
lcd /root/eeva-backups
delete "${baas}*.backup"
put "${baas}${backupdate}.backup"
bye

#reset PGUSER and PGPASSWORD
#PGUSER=""
#PGPASSWORD=""
#export PGUSER PGPASSWORD
#End

#exit 0
EOF
Andrus
  • 169
  • 4
  • 12

1 Answers1

0

Andrew's comment is probably on the spot however, I discourage anyone from using FTP as transfer method because it sends user/pass without being encrypted first

Is there any compelling reason for not using ssh + rsync? You would achieve the same result with password-less authentication which is easily achievable

Your script would be safer and shorter too

rsync --delete -av ${baas}${backupdate}.backup user@server.domain.com:/root/eeva-backups
kamihack
  • 312
  • 1
  • 6