Hetzner: automysqlbackup + automongobackup + duplicity + sshfs + rsync + cron v.1.0.6

Below is code of script :


#!/bin/bash
# v.0.1.6

# rsync all important system files

WHERE=/backup
COUNT=3

# Creating full file archives with duplicity

function make_archive(){
   if [ ! -d $2 ]; then
      mkdir -p $2
   fi
   echo "################ $1"
   duplicity full --verbosity 4 --volsize 100 --no-encryption $1 file://$2
   duplicity remove-all-but-n-full ${COUNT} --force --verbosity 4 --no-encryption file://$2
}

################################################################
################################################################

make_archive /home/user          $WHERE/files/user
make_archive /root               $WHERE/files/root
make_archive /etc                $WHERE/files/etc
make_archive /var/log            $WHERE/files/var.log
make_archive /usr/share/zabbix   $WHERE/files/usr.share.zabbix
make_archive /usr/share/redmine  $WHERE/files/usr.share.redmine

################################################################
################################################################



# Creating mount directory

TARGETDIR='h2-32/101'
MOUNTDIR='/tmp/u54398.your-backup.de.mount'
SERVER='u54398.your-backup.de'

##################################


if [ ! -d ${MOUNTDIR} ]; then
   mkdir -p ${MOUNTDIR}
fi

# Mounting and actions of rsync

verify=`cat /proc/mounts |grep ${SERVER}:${TARGETDIR} | cut -d ' ' -f 1`
 
if [ "$verify" != "${SERVER}:$TARGETDIR" ]; then
  if sshfs ${SERVER}:${TARGETDIR} ${MOUNTDIR} ; then
    echo $?
    rsync -rlpt -v --delete-before $WHERE ${MOUNTDIR}
    ls -l ${MOUNTDIR}
    fusermount -u ${MOUNTDIR}
  else
    echo "$? - not mounted. sshfs failure."
    exit
  fi
else
    echo "$? - already mounted. sshfs failure."
    exit
fi

echo "df -h ."| sftp -b - ${SERVER}


## ChangeLog

## 0.1.6

# - was changed option of rsync
#   --delete-after -> --delete-before
#   at time backup on remote server
# - was added variable COUNT

## 0.1.5
# first release

Scroll to top