Tar over SSH (backup script)

Go Back
Braindump Index
Braindump Home

I use the following script to send a tar backup over ssh to a remote machine that works as a backup server.
#!/bin/bash
# Use the parameter incr or full to specify the backup type
 
PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin
export PATH

# Backup the following paths - / is assumed 
list="etc var/spool/mail"
 
cd /

(
for file in $list
do
  filename=`echo ${file} | sed -e 's/\//_/g'`
  datafile="/.${filename}-incremental_gtar.info"

  if [ "$1" \!= "incr" ]
  then
    rm $datafile
    type=Full
  else
    type=`date +%A`
  fi

  file2=`hostname`.${filename}-${type}.tgz
  echo "Backing up ${file} as ${file2}"
  gtar -cz --listed-incremental=${datafile} --totals ${file}/* | ssh -i ~root/.ssh/identity backup@backuphost.MrZesty.net "split -b1998m  - /u2/${file2}."
  status=$?
  if [ $status -eq 0 ]
  then
    echo -e "** Backup of $file seems successful\n"
  else
    echo -e "** Backup not successful! Status: $status\n"
  fi

done
) 2>&1 | mail -s "Backup for `hostname` on `date +%D`" backupadmin@MrZesty.net
Note: you will need to set up shared RSA/DSA keys, to allow your local user (root) to connect to the backup role account on the remote server.

Last modified: Wednesday, December 31 1969 @ 19:00 EST
Google
WWW braindump.MrZesty.net
© Ian Samuel, 2010
http://braindump.MrZesty.net