2

Hie all 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

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

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.
./hetznerbkup.sh: line 28: warning: here-document at line 21 delimited by end-of-file (wanted `EOF')
(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? thankyou

3

Please avoid storing and transmitting credentials/passwords in plain text.

Instead setup SSH with public key only authorization and use scp or rsync for file transfer. Also let the postgres user himself do the backup via a cronjob (which is the answer to your last question from there), see Ubuntuusers.de Wiki on cron.

Example for a postgres crontab:

# Shell variable for cron
SHELL=/bin/bash

# PATH variable for cron
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# Backup some database from sunday to friday, compress with xz, hash with md5, delete obsolete backups after 40 days
0 3 * * SUN-FRI dump="some-database-$(date +\%Y\%m\%d-\%H\%M)-daily.sql"; cd /var/backups/postgres; pg_dump -Fc -Z0 some-database | xz -6 > ${dump}.xz; md5deep -kl ${dump}.xz > ${dump}.xz.md5; find -name "some-database*daily.sql.xz*" -mtime +40 -delete

Backing up files with tar as your Openbravo ERP or www-data user should be as easy as the above.

Edit: I recommend trying zstd instead of xz as a compressor, it has about 20 levels and is almost as good as the highest xz level on its highest level and still significantly faster.

  • 0 3 * * SUN-FRI dump="some-database-$(date +\%Y\%m\%d-\%H\%M)-daily.sql"; cd /var/backups/postgres; pg_dump -Fc -Z0 some-database | xz -6 > ${dump}.xz; md5deep -kl ${dump}.xz > ${dump}.xz.md5; find -name "some-database*daily.sql.xz*" -mtime +40 -delete can u brief me a little on this command plz.. im confused with that – Mani Deep Nov 25 '13 at 4:41
  • 1
1

You will need to put an EOF at the end of your script.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.