读书人

Rsync容易备份

发布时间: 2012-06-26 10:04:13 作者: rapoo

Rsync简单备份

看到三种备份方案,完整、增量和差异。完整不用解释,增量就是每次备份是相对上次备份的内容传送变化,差异就是每次都相对于同一个完整备份传送变化。差异与增量的差别就是增量总是相对上一次备份的结果,其实二者没有多大区别。

Rsync可以实现这三种备份,就看脚本怎么写了。写了个脚本,实现了保留最近N个备份的增量备份。命名为bk

#!/bin/bash# NAME#   bk - Simple backup# USAGE#   src dst p [password_file]# DESCRIPTION#   This script makes $p backups of $src in $dst and $dst/current points to the latest backup.# ARGUMENTS#   src           - source, local or remote#   dst           - destination, local#   p             - number of backups to make#   password_file - password file path#SRC=$1DST=$2P=$3PASSWD=$4if [ -z "$SRC" -o -z "$DST" -o -z "$P" ]; thenecho 'USAGE: src dst p [password_file]';exit -1;fiOPTS="-a --force --ignore-errors --delete"if [ ! -z "$PASSWD" ]; thenOPTS="$OPTS --password-file=$PASSWD"fiNEW=`date +%Y-%m-%d.%H:%M:%S`DIR="$DST/$NEW"if [ -d $DST ]; thenN=`ls $DST | wc -l`N=`expr $N - 1`if [ "$N" -eq "$P" ]; thenC=`expr $N - $P`O=`ls $DST | head -n 1`mv $DST/$O $DIRelsemkdir -p $DIRfi[ -L $DST/current ] && OPTS="$OPTS --link-dest=../`readlink $DST/current`"elsemkdir -p $DSTfirsync $OPTS $SRC $DIR && ( [ ! -L $DST/current ] || rm $DST/current > /dev/null ) && ln -s $NEW $DST/current
?

读书人网 >操作系统

热点推荐