Yet another rsync incremental thread

macuserfr macuserfr at free.fr
Wed Jul 30 13:08:22 GMT 2008


OK, so here I'm giving you the "final" version of the script  
timestamp.sh working for me:
-----------------------------------------------------------------
#!/bin/tcsh
#Turn on debug info
set DEBUG = 1

#Name of the backup mount (partition)
set MOUNTNAME = data

#Name of the backup directory
set BACKUP = backup

if( $DEBUG ) then
	echo "Starting script at `date +"%Y-%m-%d-%H%M%S"`"
endif

#Check if we have the good arg number
if( $# > 0 ) then
	if( $DEBUG ) then
		echo "There are arguments"
	endif
	if( $# < 2 ) then
		if( $DEBUG ) then
			echo "There is one argument, setting it as host name"
		endif
		set RSYNC_HOST_NAME = $1
	else
		echo "Too many arguments.\
Usage:	$0 <name_of_backuped_host> or\
	$0 - without arguments, in which case\
RSYNC_HOST_NAME environment variable must indicate a host name."
		exit
	endif
else if( ! $?RSYNC_HOST_NAME ) then
	echo "No RSYNC_HOST_NAME detected.\
Usage:	$0 <name_of_backuped_host> or\
	$0 - without arguments, in which case RSYNC_HOST_NAME\
	environment variable must indicate a host name."
	exit
endif

if( $DEBUG ) then
	echo "RSYNC_HOST_NAME = $RSYNC_HOST_NAME"
endif

#Change to working directory
cd /mnt/$MOUNTNAME/$RSYNC_HOST_NAME

if( $status ) then
	echo "Directory /mnt/$MOUNTNAME/$RSYNC_HOST_NAME does not exist"
	exit
endif

#Check if the backup directory exists
if( ! ( -e $BACKUP ) ) then
         echo "Directory $BACKUP is missing in $PWD"
	exit
endif

#Set up useful variables
set DATE = `date +"%Y-%m-%d-%H%M%S"`
set AVAIL = `df | grep $MOUNTNAME | awk -F' ' '{print $4}'`
set SIZE = `du -s $BACKUP | awk -F' ' '{print $1}'`

if ( $DEBUG ) then
	echo "DATE = $DATE \
AVAIL = $AVAIL \
SIZE = $SIZE"
endif

if( ! ( -e lastest ) ) then
	if( $DEBUG) then
		echo "Moving backup and creating lastest."
	endif
	mv -f $BACKUP $DATE
	ln -sf $DATE lastest
else
	if( $DEBUG ) then
		echo "Moving backup and lastest."
	endif
         mv -f $BACKUP $DATE
	rm -f lastest
	ln -sf $DATE lastest
endif
while ( $AVAIL < $SIZE )
	if ( $DEBUG ) then
		echo "Removing older backup."
	endif
	rm -Rf `ls -1 | grep $1 | head -n 1`
end
unset *
echo "Rotation successful."
-----------------------------------------------------------------

with this rsync.conf:
-----------------------------------------------------------------
syslog facility = local4
list = no
port = 873
pid file = /var/run/rsyncd.pid
uid = rsync

[serveuranm]
comment = Sauvegarde du serveur ANM
path = /mnt/data/serveuranm.domaineanm.fr/
list = true
max connections = 0
read only = false
uid = serveuranm
gid = rsync
post-xfer exec = /mnt/data/timestamp.sh > /mnt/data/timestamp.log 2>&1
-----------------------------------------------------------------

I've putted final into quotes because this is working for my initial  
server, but I already have in mind some changes:
- Convert the script to sh for better portability and also because  
tcsh scripting seems odd ( http://www.grymoire.com/Unix/CshTop10.txt )
- Make the script more generic
- Make the script multi-modules (mainly for deleting content)

I'm not sure if here's the right place to share it. Feel free to  
comment my work and please let me know if you use it as is or as a  
base for another script.

Best regards,

Vitorio


More information about the rsync mailing list