#!/bin/bash #a simple backup script that uses rsync #arg 1: source path: the path to backup. #arg 2 (optional): destination path: absolute path on host to put src #arg 3: rsync args #if no destination given, src will be pushed to the given src inside of path described by ${HB_BACKUP_DIR} env var, if it exists, otherwise it will be inside of remote user's home dir d=`date +%Y-%m-%d_%H:%M:%S` if [[ -z $1 ]]; then echo 'you must at least provide a source dir' exit 0 fi src_path="$1" #dest='hb:/var/stor/personal/backup/' dest_host="hb" if [[ $HB_BACKUP_DIR ]]; then dest_path=$HB_BACKUP_DIR"/"${src_path} else dest_path="~/"${src_path} fi rsargs='' if [[ $2 ]]; then echo 'using destination '${2} dest_path=${2} fi if [[ $3 ]]; then shift 2 rsargs=${@} fi dest=$dest_host":"$dest_path if [[ ${dest_path: -1} == "/" ]]; then ssh hb mkdir -p ${dest_path} else dest_parent_dir=`echo $dest_path | rev | cut -d'/' -f2- | rev` ssh hb mkdir -p ${dest_parent_dir} fi echo "NEW BACKUP $d ${src_path} -> ${dest}" >> /var/log/datasync.log rsync -arvzP --protect-args -e ssh --update ${src_path} ${dest} ${rsargs} >> /var/log/datasync.log echo "" >> /var/log/datasync.log #if [[ TODO "%"` ]]; then # echo "Complete." #else # echo "!! ${src} not uploaded. Server version is newer." #fi