shellftpbackupubuntu-12.04

ubuntu FTP script - hetzner


I am trying to backup of my application directory, database backup and then sending it to my ftp server at hetzner by using the following script and I get few errors

My server details: ubuntu12-04 (in hetzner) database: postgresql8.4 my ftp server: hetzner Trying to take backup at ubuntu12.04 server and copying in ftp my server got a sample script at following link

bakupscript.sh

site=ftp://u***.your-backup.de
username=u***
passwd=*******************
backupdir=/opt/openbravo-erp
filenameob="openbravo-erp.tar.gz"

echo "Creating a ob backup file $filenameob of $backupdir."

# Make a tar gzipped backup file
tar -cvzf /home/hetznerftp/"$filenameob" "$backupdir"

echo "creating a db backup file $filenamedb of ob database."
export PGPASSWORD="*my db password*"
backup_dir="/home/manideep/hetzner/"
#String to append to the name of the backup files
pg_dump -h localhost -U tad openbravo -Fc $i > $backup_dir$i\rajedb.backup

#login into ftp server
ftp -in <<EOF
open $ftp_site
user $username $passwd
bin
put /home/manideep/hetzner$filenameob 
put /home/manideep/hetznerftp/pgdump.backup
close 
bye
EOF

When I try executing that script through command ./backupscript.sh

I get following error

Creating a backup file openbravo-erp.tar.gz of /opt/openbravo-erp.
creating a db backup file  of ob database.
(to) usage: open host-name [port]
Not connected.
Not connected.
Not connected.
Not connected.

How do I send those files through script?

And will this replace the existing files while I use command put in ftp in ftp server if not, how do I do it?


Solution

  • I second the suggestion by petrus4, lftp is way better suited to scripting than ftp.

    The ...usage open host-name... error and what follows is because you use the variable $site_ftp which is empty. The variable you set is $site. And if you do it with the open command, you must remove the ftp:// prefix.

    The warning about line 21 is because you use a here document with <<EOF which means "use everything what follows as input until you find a line which reads EOF". But you don't have a line which reads EOF.

    By the way, sshfs works very nicely with hetzner backup space. With sshfs, you can mount the backup space as if it was a partition. VERY easy to use.