Re: rsync backup

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Aug 07, 2007 at 04:43:56AM -0600, Karl Larsen wrote:
>  	Here is the most basic use of rsync to perform backup of your computer. 
>  This is very easy to understand and that is why I did it. Below is a bash 
>  file that calls rsync with the -avg filters and it sets up the things to be 
>  backed up. I stopped backing up /sys because it has some things that do not 
>  want to be copied.
> 
>  # This is the rsync bash file for root
> 
>  rsync -avg /home/ /media/disk/

-g is already included with -a.

>  # rsync -avg /sys /media/disk/
/sys is dynamically created by the kernel, like /proc. Ignore it.

Attached I send the script that I use for backups. It uses the
--link-dest option of rsync to keep the last 15 backups.

-- 
lfr
0/0
#!/bin/bash

cd "${0%/*}" || exit 1

## get SSH_AUTH_SOCK
if [ -z "$SSH_AUTH_SOCK" ]; then
	for p in /tmp/ssh-*/agent.*; do
		if [ -e "$p" ] && [ -O "$p" ] && ps -p "${p##*.}" &> /dev/null
		then
			SSH_AUTH_SOCK="$p"
			export SSH_AUTH_SOCK
			break
		fi
	done
fi

## backups stored in directory_where_this_script_is/host/date_in_year_month_day
## only the last 15 days are stored, and the last 2 are used with
##  --link-dest of rsync (ie., check those directories and hard link if
##  match found instead of downloading)

## backup function
## bck <name> <source> [ <rsync options> .... ]

bck() {
	host="$1"
	from="$2"
	shift 2

	## check arguments: won't accept spaces
	if [ -z "${host%%* *}" -o -z "${from%%* *}" -o -z "${PWD%%* *}" ]
	then
		echo "arguments or backup directory contain spaces" 1>&2
		echo "this is not supported" 1>&2
		exit 1
	fi

	## reset arguments
	arg=

	## verbose, if writing to a tty
	tty -s && arg="-vP"

	## current date in year-month-day
	now=`date -I`

	mkdir -p $host/$now

	## n of current backups
	count=`ls $host/|wc -l`

	## reset link-dest arguments
	link=

	## check previous backups
	for d in `ls $host/`; do
		## skip if if directory is today's backup
		[ $d = $now ] && continue

		if [ $count -gt 15 ]; then
			## remove if more than 15
			rm -fr $host/$d
		elif [ $count -le 2 ]; then
			## add to link-dest if lower/eq than 2
			link="--link-dest=$PWD/$host/$d $link"
		fi
		((count--))
	done

	## do the backup
	rsync -aH --delete $arg $link "$@" $from/ $PWD/$host/$now/
}

bck server1 server1:/home/user \
	--exclude /downloads/ \
	--exclude /.ccache/ \
	--exclude /.beagle/ \
	--exclude /tmp/ \
	--exclude /rpms/ \
	--exclude .hc

bck this /home/user \
	--exclude /.ccache/ \
	--exclude /.beagle/ \
	--exclude /downloads/ \
	--exclude tmp \
	--exclude rpms \
	--exclude .hc \
	--exclude .bc

Attachment: pgpmeN5ZOZqER.pgp
Description: PGP signature


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux