From ee3ac2f8ec197f15b302773e4ad99e2e74679b88 Mon Sep 17 00:00:00 2001 From: aborn Date: Tue, 21 Jan 2014 20:32:41 +0800 Subject: [PATCH] add rsync module --- .gitignore | 1 + README.md | 12 ++++++- rsync/README.md | 39 ++++++++++++++++++++++ rsync/client.conf | 15 +++++++++ rsync/rsync | 41 +++++++++++++++++++++++ rsync/rsyncclient.sh | 77 ++++++++++++++++++++++++++++++++++++++++++++ rsync/rsyncd.conf | 17 ++++++++++ rsync/rsyncd.scrt | 2 ++ 8 files changed, 203 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 rsync/README.md create mode 100644 rsync/client.conf create mode 100644 rsync/rsync create mode 100755 rsync/rsyncclient.sh create mode 100644 rsync/rsyncd.conf create mode 100644 rsync/rsyncd.scrt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e4e5f6c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*~ \ No newline at end of file diff --git a/README.md b/README.md index a2286df..6b240e8 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,14 @@ configure ========= -This repo includes lots of configure scripts, which can be used in server and desktop. +## INTRO +This repo includes lots of configure scripts, which can be used in +server and desktop. + +## AUTHOR +Aborn Jiang (aborn.jiang@gmail.com) + +## VERSION +* 2014-01-21 v0.1 (add rsync configure files) + + diff --git a/rsync/README.md b/rsync/README.md new file mode 100644 index 0000000..8c397b1 --- /dev/null +++ b/rsync/README.md @@ -0,0 +1,39 @@ +rsync +========= + +## INTRO +Rsync is a very common and useful backup tool, this subrepo aims to +configure rsync server and client. *SHELL-SCRIPT* + +## FILE-SERVER +* rsync in server path /etc/default/rsync. +* rsyncd.conf in server path /etc/rsyncd.conf. +* rsyncd.scrt secret file in server /etc/rsyncd.scrt, chmod 600 + rsyncd.scrt (other usrs cannot read, write and excute). + +## FILE-CLIENT +* rsyncd.scrt as rsyncd.scrt in FILE-SERVER. +* rsyncclient.sh client backup script. +* client.conf clinet configure files. + +## HOW-TO-INSTALL +1. in server: configure /etc/default/rsync with ./rsync +2. in server: configure /etc/rsyncd.conf and choose backup directory +3. in server: running rsync as daemon process: sudo /etc/init.d/rsync + start +4. in client: configure ./client.conf +5. in client: configure ./rsyncclient.sh + +## REFS +* link + [office website](http://rsync.samba.org/ftp/rsync/rsyncd.conf.html + "rsync manual.") + +## CRONTAL +* crontab setting: */30 * * * * /home/aborn/backup/rsyncclient.sh >> /home/aborn/backup/client.log 2>&1 + +## AUTHOR +Aborn Jiang (aborn.jiang@gmail.com) + +## VERSION +2014-01-21 v0.1 diff --git a/rsync/client.conf b/rsync/client.conf new file mode 100644 index 0000000..68a6a47 --- /dev/null +++ b/rsync/client.conf @@ -0,0 +1,15 @@ +# this is a configure file for client backup machine +# NOTE: +# OPTIONS="-vazu --progreess --delete" +# client will backup all same files at server +# when server delete a specific file, client also delete it. +# and OPTIONS="-vazu --progress" +# client will keep server deleted files +# MODULE responding to [modules] in server, seperated by space +# BACKUPPATH client backup path + +BACKUPPATH="/home/aborn/backup/"; +SERVERIP="10.141.247.12" +MODULE="appbackup databackup" +#OPTIONS="-vazu --progress --delete" +OPTIONS="-vazu --progress" diff --git a/rsync/rsync b/rsync/rsync new file mode 100644 index 0000000..3f8ab26 --- /dev/null +++ b/rsync/rsync @@ -0,0 +1,41 @@ +# defaults file for rsync daemon mode + +# start rsync in daemon mode from init.d script? +# only allowed values are "true", "false", and "inetd" +# Use "inetd" if you want to start the rsyncd from inetd, +# all this does is prevent the init.d script from printing a message +# about not starting rsyncd (you still need to modify inetd's config yourself). +RSYNC_ENABLE=true + +# which file should be used as the configuration file for rsync. +# This file is used instead of the default /etc/rsyncd.conf +# Warning: This option has no effect if the daemon is accessed +# using a remote shell. When using a different file for +# rsync you might want to symlink /etc/rsyncd.conf to +# that file. +# RSYNC_CONFIG_FILE= + +# what extra options to give rsync --daemon? +# that excludes the --daemon; that's always done in the init.d script +# Possibilities are: +# --address=123.45.67.89 (bind to a specific IP address) +# --port=8730 (bind to specified port; default 873) +RSYNC_OPTS='' + +# run rsyncd at a nice level? +# the rsync daemon can impact performance due to much I/O and CPU usage, +# so you may want to run it at a nicer priority than the default priority. +# Allowed values are 0 - 19 inclusive; 10 is a reasonable value. +RSYNC_NICE='' + +# run rsyncd with ionice? +# "ionice" does for IO load what "nice" does for CPU load. +# As rsync is often used for backups which aren't all that time-critical, +# reducing the rsync IO priority will benefit the rest of the system. +# See the manpage for ionice for allowed options. +# -c3 is recommended, this will run rsync IO at "idle" priority. Uncomment +# the next line to activate this. +# RSYNC_IONICE='-c3' + +# Don't forget to create an appropriate config file, +# else the daemon will not start. diff --git a/rsync/rsyncclient.sh b/rsync/rsyncclient.sh new file mode 100755 index 0000000..05ac915 --- /dev/null +++ b/rsync/rsyncclient.sh @@ -0,0 +1,77 @@ +#!/bin/bash +################################################################## +# NAME +# rsyncclient.sh ---- running in client machine, which +# is used to backup data in client machine +# +# USAGE +# ./rsyncclient.sh +# +# AUTHOR +# Aborn Jiang (aborn.jiang@gmail.com) +# +# NOTE +# pls configure the file client.conf and rsyncd.scrt +# +################################################################## +ABSPATH=$(dirname $0) +source ${ABSPATH}/client.conf + +function get-user-pwd() +{ +# obtain usrname and password + iUSR=$(cat ${ABSPATH}/rsyncd.scrt|tr -d ' ' |grep -v "^$" | \ + grep -v "^#"|head -n 1|awk -F : '{print $1}') + iPWD=$(cat ${ABSPATH}/rsyncd.scrt|tr -d ' ' |grep -v "^$" | \ + grep -v "^#"|head -n 1|awk -F : '{print $2}') + if [ -z ${iUSR} ] || [ -z ${iPWD} ];then + echo "iUSR=$iUSR iPWD=$iPWD" + echo "rsyncd.scrt format illegal, please check!"; + exit -1; + fi + +# produce password file + echo "$iPWD" > ${ABSPATH}/.pass + chmod 600 ${ABSPATH}/.pass + [ ! -d $BACKUPPATH ] && mkdir -p ${BACKUPPATH} +} + + +function backup-module() +{ +# print key information + iModule=$1 + echo + echo "---------------------------------------------------" + echo "---- backup module ${iModule}@${SERVERIP} begin " + echo "---- TIME=`date`----" + echo "ABSPATH=${ABSPATH}" + echo "BACKUPPATH=${BACKUPPATH}" + echo "iUSR=$iUSR iPWD=$iPWD" + echo "OPTIONS=${OPTIONS}" + iModuleBackpath=${BACKUPPATH}/${iModule}; + [ ! -d ${iModuleBackpath} ] && mkdir -p ${iModuleBackpath} + +# begin backup + rsync ${OPTIONS} ${iUSR}@${SERVERIP}::${iModule} ${iModuleBackpath} \ + --password-file=${ABSPATH}/.pass + if [ $? != 0 ];then + echo "---- backup module ${iModule}@${SERVERIP} failed." + else + echo "---- backup module ${iModule}@${SERVERIP} succuess. " + fi + echo "---- TIME=`date`----" + echo "---------------------------------------------------" + echo +} + +function __main__() +{ + get-user-pwd + for md in $MODULE + do + backup-module $md + done +} + +__main__ \ No newline at end of file diff --git a/rsync/rsyncd.conf b/rsync/rsyncd.conf new file mode 100644 index 0000000..28a51f1 --- /dev/null +++ b/rsync/rsyncd.conf @@ -0,0 +1,17 @@ +#[globale] +strict modes = yes +#rsync default port +port = 873 +logfile = /var/log/rsyncd.log +pidfile = /var/run/rsyncd.pid +max connections = 4 +auth users = backup, user +secrets file = /etc/rsyncd.scrt + +#[modules] each path responding to a module +[appbackup] +path = /home/aborn/backup +#hosts allow=9.4.122.24 + +[databackup] +path = /home/data diff --git a/rsync/rsyncd.scrt b/rsync/rsyncd.scrt new file mode 100644 index 0000000..5cbc45d --- /dev/null +++ b/rsync/rsyncd.scrt @@ -0,0 +1,2 @@ +backup:configurebackup@#$^&*()google +user:passwordpassword