linux下tar做文件系统增量备份

  想给项目的CVS做个自动备份的脚本,一看目录大小,已经有近20个G。天天做完整备份太费资源了,增量备份是一个解决方案了。计划每周末做一次完整备份,然后每天做增量备份。

  Linux做增量备份还是很容易的,tar命令就可以。

  在cron里设置,每周日晚执行(每周日全备份,其余时间增量备份)。下面是从网上找了两个示例的脚本。

  示例一:(http://www.cnblogs.com/coffee_cn/archive/2010/03/26/1697038.html)

#!/bin/bash

# define

dayofweek=`date "+%u"`

today=`date "+%Y%m%d"`

source=/data/

backup=/backup/

# action

cd $backup

if [ $dayofweek -eq 1 ]; then

  if [ ! -f "full$today.tar.gz" ]; then

    rm -rf snapshot

    tar -g snapshot -zcf "full$today.tar.gz" $source --exclude $sourceserver.log

  fi

else

  if [ ! -f "inc$today.tar.gz" ]; then

    tar -g snapshot -zcf "inc$today.tar.gz" $source --exclude $sourceserver.log

  fi

fi

示例二:(http://www.futuremedia.pl/pub/projekty/backup/backup)

#!/bin/bash

# simple backup script. intended to run daily from crontab

# called "biedacula" after "bieda", which is Polish word for "poor".

# implements poor man's GFS scheme, hence the name:)

# requires GNU tar, GNU gzip and ncftp

# these files must contain file/dir paths (one a line)

PATHFILE=/etc/backup-defs

SKIPFILE=/etc/backup-excludes

# this is a snapshot file auto-created by GNU tar

SNAPSHOT=/etc/backup-snapshot

# FTP host to send backups ( must allow anonymous RW access for me )

FTPHOST=192.168.2.2

FTPPORT=21

# when to do full, monthly/weekly backups

FULL_MONTHDAY=1 # 1st day of month

FULL_WEEKDAY=7 # Sunday

# how many "tapes" for monthly backups

KEEP_MONTHLY=3

# how many "tapes" for weekly backups

KEEP_WEEKLY=4

# in total you will have ( KEEP_MONTHLY + KEEP_WEEKLY + 6 ) "tapes"

function biedump {

local TYPE=$1

local LABEL=$2

local start=`date +%Y%m%d%H%M`

echo "$start: Starting $TYPE dump to label $LABEL"

if [ "x$TYPE" == "xfull" ] ; then

rm -rf $SNAPSHOT

fi

tar -c -T$PATHFILE -X$SKIPFILE -g$SNAPSHOT -P -f -

| gzip

| ncftpput -c -S.tmp -P $FTPPORT $FTPHOST $LABEL

local res=$?

local end=`date +%Y%m%d%H%M`

if [ $res -eq 0 ]; then

评论

Popular Posts

随身WiFi折腾指南: 解锁、刷机与DIY

Cromite - 极度注重隐私的Chromium浏览器

《赤い涙 》灼眼的夏娜剧场版插曲

求职面试时常被问到的65个问题与技巧性回答

伤不起的盖茨比——那些年,我们没逆袭到的女神

人类的十个有趣心理效应

电话销售技巧8:如何绕过前台

Alexa互联网信息公司中文官方网站

拒绝道德绑架,这才是真正的公益广告

感情的瓶颈期或者说磨合期该怎么度过?