Skip to content

Instantly share code, notes, and snippets.

@tkmtmkt
Created October 27, 2013 16:35
Show Gist options
  • Save tkmtmkt/7184659 to your computer and use it in GitHub Desktop.
Save tkmtmkt/7184659 to your computer and use it in GitHub Desktop.
backup by rsync
#!/bin/bash
#
# target server
# /root/.ssh/authorized_keys
#
# backup server
# ssh-keygen -f .ssh/backup -C backup
# ssh-copy-id -i .ssh/backup.pub $TARGET
#
# /root/.ssh/config
# /root/.ssh/backup
# /root/.ssh/backup.pub
# /root/.ssh/known_hosts
#
# /home/backups/brown/doBackup
#
BASE=$(cd $(dirname $0);pwd)
TARGET=brown
LOGFILE="$BASE/rsync_${TARGET}_$(date +"%Y%m%d%H%M%S").log"
while read object
do
src="$TARGET:$object"
dst="$(dirname "$BASE$object")"
if [ ! -d "$dst" ] ; then
mkdir -p "$dst"
fi
rsync -avz --delete "$src" "$dst" 2>&1 | tee -a $LOGFILE
done <<EOS
/etc/network
/etc/hosts
/etc/ssh
/etc/environment
/home
EOS
# vim: set ts=2 sw=2 et:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment