#!/bin/bash # # Author: Martin Matusiak # Licensed under the GNU Public License, version 2. # server setup hostname="matusiak.eu" username="" ssh_port="22" # local setup local_path="/local/path" # remote setup remote_path="~" locations="bin backups public_html" exclusions="cgi-bin *.swp *~" #.swp are vim swap files ## EDIT BELOW THIS LINE IF YOU KNOW WHAT YOU'RE DOING # rsync options rsync_options="--archive --verbose --stats --progress" # switch priority nice="nice -n 10" inc_list="" function inclusion_list() { for i in $exclusions; do inc_list="${inc_list}--filter='- $i' " done for i in $locations; do inc_list="${inc_list}--filter='+ /$i' " done inc_list="${inc_list} --filter='- /*'" } function shell() { ssh -C ${username}@${hostname} -p ${ssh_port} } function sync_up() { inclusion_list cmd="${nice} rsync ${rsync_options} -e \"ssh -p ${ssh_port}\" \ ${inc_list} \ ${local_path}/* \ ${username}@${hostname}:${remote_path} " echo "$cmd" sh -c "$cmd" } function sync_down() { inclusion_list mkdir -p ${local_path} cmd="${nice} rsync ${rsync_options} -e \"ssh -p ${ssh_port}\" \ ${inc_list} \ ${username}@${hostname}:${remote_path}/* \ ${local_path} " echo "$cmd" sh -c "$cmd" } if [ -z "$1" ]; then shell elif [ "$1" = "down" ]; then sync_down elif [ "$1" = "up" ]; then sync_up else echo "$0 [down|up]" fi