From: Micah Anderson Date: Fri, 2 Nov 2007 19:32:51 +0000 (+0000) Subject: remove rsnap and rename rub handler to rsync, after consultation with rhatto X-Git-Tag: backupninja-0.9.5~23 X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=3a74d7d526b38b232b839c4e4b0bc1420ae664f8;p=matthijs%2Fupstream%2Fbackupninja.git remove rsnap and rename rub handler to rsync, after consultation with rhatto --- diff --git a/ChangeLog b/ChangeLog index 5aa1fd0..0dacc94 100644 --- a/ChangeLog +++ b/ChangeLog @@ -37,11 +37,14 @@ version 0.9.5 -- unreleased . Handle "keep = yes" to disable old backups removal (Closes: #424633) . Add configuration option to allow you to disable the version check as in some instances this may be an ok scenario (Closes: #424632) - rub + rub/rsync . Fixed typo in rub handler that caused it to not work . Changed to use lib/vserver code . Fixed fsck error . Fixed integer comparison (Closes: Trac#3) + . Renamed handler to 'rsync', replaces outdated rub handler + . updated examples/Makefile.am and handlers/Makefile.am to include + rsnap/rsync (Closes: #440554) sys: . Fixed typo breaking things for VServers. . Fix bug when vrootdir is on its own partition (Closes: #395928) @@ -55,8 +58,6 @@ version 0.9.5 -- unreleased . Force C locale for sfdisk to ensure english words are found in grep fixed 'make install' bug that failed if /etc/backup.d already existed changed spaces to tabs in Makefile.am - updated examples/Makefile.am and handlers/Makefile.am to include rsnap/rub - files (Closes: #440554) version 0.9.4 -- October 6th, 2006 diff --git a/examples/Makefile.am b/examples/Makefile.am index ca8999f..5dfb7c3 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -1,6 +1,6 @@ EXAMPLES = example.dup example.ldap example.makecd example.mysql \ - example.pgsql example.rdiff example.rsnap example.sh \ + example.pgsql example.rdiff example.sh \ example.svn example.sys example.trac EXTRA_DIST = $(EXAMPLES) diff --git a/examples/example.rsnap b/examples/example.rsnap deleted file mode 100644 index c1c50dd..0000000 --- a/examples/example.rsnap +++ /dev/null @@ -1,67 +0,0 @@ -## -## This is an example rsnap configuration file. -## The defaults are useful in most cases. -## - -## global options -[options] -options = - -## the nicelevel the backup and all the children should run at -## the higher nicelevel reduces the priority -nicelevel = 19 - -# how many days of data to keep -keep = 90 - -# the name of the directory created for the backup -label = systemname_domain_tld - -[source] - -# bandwidth limit to be used for rsync -bandwidthlimit = 1000 - -# remote_rsync can be used if your rsync is not in your PATH, or if you -# need a wrapper -#remote_rsync = /usr/local/bin/sudo_rsync - -# options like -P can be specified here -#sshoptions = - -# test the ssh connection before proceding? -testconnect = yes - -# don't translate owner+groupid's to local names -numericids = 1 - -# turn on rsync compression? (1 = on, 0 = off) -compress = 1 - -srchost = backupuser@hostname.domain.tld - -# files to include in the backup -# (supports globbing with '*'), by default / is included -include = /var -include = /usr/local -include = /home - -# files to exclude from the backup -# (supports globbing with '*') -exclude = /home/*/Maildir -exclude = /var/log -exclude = /proc -exclude = /srv -exclude = /sys -exclude = /*.gz - -[dest] - -# base directory where backup is made to -directory = /media/backup - -# only necessary if you hit a specifi 2.4 kernel bug -enable_mv_timestamp_bug = no - -# if you say no here, only one dir is kept, and 'keep' is irrelevant -incremental = yes diff --git a/handlers/Makefile.am b/handlers/Makefile.am index 710b25e..be8c7b5 100644 --- a/handlers/Makefile.am +++ b/handlers/Makefile.am @@ -1,7 +1,7 @@ HANDLERS = dup dup.helper ldap ldap.helper maildir makecd \ makecd.helper mysql mysql.helper pgsql pgsql.helper rdiff \ - rdiff.helper rsnap rub sh svn sys sys.helper trac + rdiff.helper rsync sh svn sys sys.helper trac CLEANFILES = $(HANDLERS) @@ -66,13 +66,9 @@ rdiff.helper: $(srcdir)/rdiff.helper.in rm -f rdiff.helper $(edit) $(srcdir)/rdiff.helper.in > rdiff.helper -rsnap: $(srcdir)/rsnap.in - rm -f rsnap - $(edit) $(srcdir)/rsnap.in > rsnap - -rub: $(srcdir)/rub.in - rm -f rub - $(edit) $(srcdir)/rub.in > rub +rsync: $(srcdir)/rsyn.in + rm -f rsync + $(edit) $(srcdir)/rsync.in > rsync sh: $(srcdir)/sh.in rm -f sh diff --git a/handlers/rsnap.in b/handlers/rsnap.in deleted file mode 100644 index 017a456..0000000 --- a/handlers/rsnap.in +++ /dev/null @@ -1,244 +0,0 @@ -# -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*- -# -# rsync backup handler for backupninja -# requires rsync and optional freedups -# -# freedups: -# http://www.stearns.org/freedups/ -# http://freshmeat.net/projects/freedups/ -# -# rsync: -# http://samba.anu.edu.au/rsync/ - -# exit on error -#set -e - -# System commands used by this script -# replace with absolute path's if neccecary -getconf rm rm -getconf cp cp -getconf touch touch -getconf mv mv -getconf ssh ssh -getconf tr tr -getconf rsync $RSYNC - -setsection options -getconf options -getconf label -getconf nicelevel 0 -getconf keep 60 - -setsection source -getconf testconnect no -getconf srchost localhost -getconf compress 1 -getconf sshoptions -getconf bandwidthlimit 1000 -getconf remote_rsync rsync -getconf numericids 1 -getconf include -getconf vsnames all -getconf vsinclude -getconf include -getconf exclude - -setsection dest -getconf directory -getconf enable_mv_timestamp_bug no -getconf freedups freedups -getconf enable_freedups no -getconf incremental yes - -# Apparently, a bug in some Linux kernels between 2.4.4 and 2.4.9 causes mv to update timestamps; -# this may result in inaccurate timestamps on the snapshot directories. -# Set enable_mv_timestamp_bug=1 to enable this workaround -if [ $enable_mv_timestamp_bug == "yes" ]; then - mv=my_mv -fi; - -function my_mv() { - ref=/tmp/makesnapshot-mymv-$$; - $touch -r $1 $ref; - $mv $1 $2; - $touch -r $ref $2; - $rm $ref; -} - -if [ $enable_freedups == "yes" ]; then - # $freedups - debug "Not implemented yet!" -fi; - - -[ "$directory" != "" ] || fatal "Destination directory not set" -[ "$include" != "" ] || fatal "No source includes specified" - -### vservers stuff ### - -# If vservers are configured, check that the ones listed in $vsnames do exist. -local usevserver=no -if [ $vservers_are_available = yes ]; then - if [ "$vsnames" = all ]; then - vsnames="$found_vservers" - else - if ! vservers_exist "$vsnames" ; then - fatal "At least one of the vservers listed in vsnames ($vsnames) does not exist." - fi - fi - if [ -n "$vsinclude" ]; then - info "Using vservers '$vsnames'" - usevserver=yes - fi -else - [ -z "$vsinclude" ] || warning 'vservers support disabled in backupninja.conf, vsincludes configuration lines will be ignored' - [ -z "$vsnames" ] || warning 'vservers support disabled in backupninja.conf, vsnames configuration line will be ignored' -fi - -### see if we can login ### - -if [ "$testconnect" == "yes" ]; then - debug "$ssh $sshoptions -o PasswordAuthentication=no $srchost 'echo -n 1'" - if [ ! $test ]; then - result=`ssh $sshoptions -o PasswordAuthentication=no $srchost 'echo -n 1'` - if [ "$result" != "1" ]; then - fatal "Can't connect to $srchost." - else - debug "Connected to $srchost successfully" - fi - fi -fi - -### COMMAND-LINE MANGLING ### - -[ "$bandwidthlimit" == 1000 ] || options="$options --bwlimit=$bandwidthlimit" -[ "$numericids" == 1 ] || options="$options --numeric-ids " -[ "$compress" == 1 ] || options="$options --compress " -[ "$remote_rsync" == "rsync" ] || options="$options --rsync-path=$remote_rsync" - -if [ "$nicelevel" -ne 0 ]; then - nice="nice -n $nicelevel" ; -else - nice=""; -fi - -execstr="$options --exclude '/' --delete-during --delete-excluded --archive $sshoptions " - -if [ "$incremental" == "no" ]; then - execstr="${execstr} --whole-file " -fi - -execstr_serverpart="$srchost:/" - - -### SOURCE ### - -set -o noglob - -# excludes -for i in $exclude; do - str="${i//__star__/*}" - #execstr="${execstr}--exclude '$str' " - execstr="${execstr}--exclude $str " -done - -# includes -for i in $include; do - str="${i//__star__/*}" - #execstr="${execstr}--include '$str' " - execstr="${execstr}--include $str " -done - -# vsincludes -if [ $usevserver = yes ]; then - for vserver in $vsnames; do - for vi in $vsinclude; do - str="${vi//__star__/*}" - execstr="${execstr}--include '$label/$vserver$str' " - done - done -fi - - -### SNAPSHOT ROTATION ### - -if [ "$incremental" == "yes" ]; then - debug "starting to rotate the old dirs" - # rotating snapshots - # delete the oldest snapshot, if it exists: - debug "does $directory/$label/$keep exist?" - if [ -d "$directory/$label/$keep" ] ; then - debug "$rm -rf $directory/$label/$keep" - if [ !$test ]; then - #$rm -rf "$directory/$label/$keep" ; - debug "$rm -rf $directory/$label/$keep"; - fi; - fi; - - # shift the snapshots(s) back by one, if they exist - for (( i=$keep; $i>=0; i--)) ; do - debug "does $directory/$label/$i exist?" - if [ -d "$directory/$label/$i" ] ; then - debug "$mv $directory/$label/$i $directory/$label/$(($i + 1))" - if [ !$test ]; then - $mv "$directory/$label/$i" "$directory/$label/$(($i + 1))" - fi; - fi; - done - - # make a hard-link-only (except for dirs) copy of - # assuming that exists, into the new dir - if [ -d "$directory/$label/1" ]; then - debug "$cp -al $directory/$label/1 $directory/$label/0" - if [ !$test ]; then - $cp -al $directory/$label/1 $directory/$label/0 ; - fi; - fi; - -fi - - -set +o noglob - -### EXECUTE ### - -# exclude everything else, start with root -#execstr="${execstr}--exclude '*' " - -# include client-part and server-part -#execstr="$execstr $execstr_serverpart" - -execstr=${execstr//\\*/\\\\\\*} - -if [ "$debug" == "1" ]; then - execstr=" --verbose $execstr"; - # execstr=" --verbose --dry-run $execstr"; -else - execstr=" --quiet $execstr"; -fi; - -debug "$rsync $execstr $execstr_serverpart $directory/$label/0" - - -# rsync from the system into the latest snapshot (notice that -# rsync behaves like cp --remove-destination by default, so the destination -# is unlinked first. If it were not so, this would copy over the other -# snapshot(s) too! -output=`$nice $rsync $execstr $execstr_serverpart $directory/$label/0 2>&1` -code=$? - -# update the mtime of the 0 dir to reflect the snapshot time -$touch $directory/$label/0 - -if [ $code -eq 0 ]; then - debug $output - info "rsync finished successfully."; -else - debug "returncode $code : $output " - #fatal "rsync failed."; - warning "rsync failed."; -fi; - - -return 0; - diff --git a/handlers/rsync.in b/handlers/rsync.in new file mode 100644 index 0000000..d3d704c --- /dev/null +++ b/handlers/rsync.in @@ -0,0 +1,348 @@ +# +# backupninja handler to do incremental backups using +# rsync and hardlinks, based on +# +# http://www.mikerubel.org/computers/rsync_snapshots/ +# +# feedback: rhatto at riseup.net | gpl +# lot of enhancements grabbed from "rsnap" handler by paulv at bikkel.org +# +# Config file options +# ------------------- +# +# [general] +# log = rsync log file +# partition = partition where the backup lives +# fscheck = set to 1 if fsck should run on $partition after the backup is made +# read_only = set to 1 if $partition is mounted read-only +# mountpoint = backup partition mountpoint or backup main folder +# backupdir = folder relative do $mountpoint where the backup should be stored +# days = number of backup increments (min = 5) +# lockfile = lockfile to be kept during backup execution +# enable_mv_timestamp_bug = set to "yes" if your system isnt handling timestamps correctly +# tmp = temp folder +# +# [source] +# from = local or remote +# testconnect = when "yes", test the connection for a remote source before backup +# include = include folder on backup +# exclude = exclude folder on backup +# ssh = ssh command line (remote only) +# rsync = rsync program +# rsync_options = rsync command options +# exclude_vserver = vserver-name (valid only if vservers = yes on backupninja.conf) +# numericids = when set to 1, use numeric ids instead of user/group mappings on rsync +# compress = if set to 1, compress data on rsync (remote source only) +# bandwidthlimit = set a badnwidth limit in kbps (remote source only) +# remote_rsync = remove rsync program (remote source only) +# +# [services] +# initscripts = absolute path where scripts are located +# service = script name to be stoped at the begining of the backup and started at its end +# +# You can also specify some system comands if you don't want the default system values: +# +# [system] +# rm = rm command +# cp = cp command +# touch = touch command +# mv = mv command +# fsck = fsck command +# +# You dont need to manually specify vservers using "include = /vservers". +# They are automatically backuped if vserver is set to "yes" on you backupninja.conf. +# + +# config file evaluation + +setsection system +getconf rm rm +getconf cp cp +getconf touch touch +getconf mv mv +getconf fsck fsck + +setsection general +getconf log /var/log/backupninja-rsync.log +getconf partition +getconf fscheck +getconf read_only +getconf mountpoint +getconf backupdir +getconf rotate +getconf days +getconf lockfile +getconf nicelevel 0 +getconf enable_mv_timestamp_bug no +getconf tmp /tmp + +setsection source +getconf from local +getconf testconnect no +getconf rsync $RSYNC +getconf rsync_options "-av --delete" +getconf ssh ssh +getconf user +getconf host +getconf include +getconf exclude +getconf exclude_vserver +getconf numericids 0 +getconf compress 0 +getconf bandwidthlimit +getconf remote_rsync rsync + +setsection services +getconf initscripts +getconf service + +# function definitions + +function rotate { + + if [[ "$2" -lt 4 ]]; then + error "Rotate: minimum of 4 rotations" + exit 1 + fi + + if [ -d $1.$2 ]; then + $nice $mv /$1.$2 /$1.tmp + fi + + for ((n=`echo "$2 - 1" | bc`; n >= 0; n--)); do + if [ -d $1.$n ]; then + dest=`echo "$n + 1" | bc` + $nice $mv /$1.$n /$1.$dest + $touch /$1.$dest + fi + done + + if [ -d $1.tmp ]; then + $nice $mv /$1.tmp /$1.0 + fi + + if [ -d $1.1 ]; then + $nice $cp -alf /$1.1/. /$1.0 + fi + +} + +function move_files { + + ref=$tmp/makesnapshot-mymv-$$; + $touch -r $1 $ref; + $mv $1 $2; + $touch -r $ref $2; + $rm $ref; + +} + +backupdir="$mountpoint/$backupdir" + +# does $backupdir exists? + +if [ ! -d "$backupdir" ]; then + error "Backupdir $backupdir does not exist" + exit 1 +fi + +# setup number of increments + +if [ -z "$days" ]; then + keep="4" +else + keep="`echo $days - 1 | bc -l`" +fi + +# lockfile setup + +if [ ! -z "$lockfile" ]; then + $touch $lockfile || warning "Could not create lockfile $lockfile" +fi + +# nicelevel setup + +if [ ! -z "$nicelevel" ]; then + nice="nice -n $nicelevel" +else + nice="" +fi + +# connection test + +if [ "$from" == "remote" ] && [ "$testconnect" == "yes" ]; then + debug "$ssh -o PasswordAuthentication=no $user@$host 'echo -n 1'" + result=`ssh -o PasswordAuthentication=no $user@$host 'echo -n 1'` + if [ "$result" != "1" ]; then + fatal "Can't connect to $host as $user." + else + debug "Connected to $srchost successfully" + fi +fi + +# rsync options for local sources + +if [ "$from" == "local" ]; then + + rsync_local_options="$rsync_options" + + if [ ! -z "$numericids" ]; then + rsync_local_options="$rsync_local_options --numeric-ids " + fi + +fi + +# rsync options for remote sources + +if [ "$from" == "remote" ]; then + + rsync_remote_options="$rsync_options --rsync-path=$remote_rsync" + + if [ "$compress" == "1" ]; then + rsync_remote_options="$rsync_remote_options --compress" + fi + + if [ ! -z "$bandwidthlimit" ]; then + rsync_remote_options="$rsync_remote_options --bwlimit=$bandwidthlimit" + fi + + if [ ! -z "$numericids" ]; then + rsync_remote_options="$rsync_remote_options --numeric-ids" + fi + +fi + +# set mv procedure + +if [ $enable_mv_timestamp_bug == "yes" ]; then + mv=move_files +fi + +# set excludes + +for path in $exclude; do + EXCLUDES="$EXCLUDES --exclude=$path" +done + +# stop services + +if [ ! -z "$service" ]; then + for daemon in $service; do + info "Stopping service $daemon..." + $initscripts/$daemon stop + done +fi + +echo "Starting backup at `date`" >> $log + +# mount backup destination folder as read-write + +if [ "$read_only" == "1" ] || [ "$read_only" == "yes" ]; then + if [ -d "$mountpoint" ]; then + mount -o remount,rw $mountpoint + if (($?)); then + error "Could not mount $mountpoint" + exit 1 + fi + fi +fi + +# add vservers to included folders + +if [ "$vservers_are_available" == "yes" ]; then + + # sane permission on backup + mkdir -p $backupdir/$VROOTDIR + chmod 000 $backupdir/$VROOTDIR + + for candidate in $found_vservers; do + candidate="`basename $candidate`" + found_excluded_vserver="0" + for excluded_vserver in $exclude_vserver; do + if [ "$excluded_vserver" == "$candidate" ]; then + found_excluded_vserver="1" + break + fi + done + if [ "$found_excluded_vserver" == "0" ]; then + include="$include $VROOTDIR/$candidate" + fi + done +fi + +# the backup procedure + +for SECTION in $include; do + + section="`basename $SECTION`" + + if [ ! -d "$backupdir/$SECTION/$section.0" ]; then + mkdir -p $backupdir/$SECTION/$section.0 + fi + + info "Rotating $backupdir/$SECTION/$section..." + echo "Rotating $backupdir/$SECTION/$section..." >> $log + rotate $backupdir/$SECTION/$section $keep + info "Syncing $SECTION on $backupdir/$SECTION/$section.0..." + + if [ "$from" == "local" ]; then + debug $rsync $rsync_local_options $EXCLUDES /$SECTION/ $backupdir/$SECTION/$section.0/ + $nice $rsync $rsync_local_options $EXCLUDES /$SECTION/ $backupdir/$SECTION/$section.0/ >> $log + if [ "$?" != "0" ]; then + warning "Rsync error when trying to transfer $SECTION" + fi + elif [ "$from" == "remote" ]; then + if [ -z "$user" ] || [ -z "$host" ]; then + error "Config file error: either user or host was not specified" + exit 1 + else + debug $nice $rsync $rsync_remote_options $EXCLUDES -e "$ssh" $user@$host:/$SECTION/ $backupdir/$SECTION/$section.0 + $nice $rsync $rsync_remote_options $EXCLUDES -e "$ssh" $user@$host:/$SECTION/ $backupdir/$SECTION/$section.0 >> $log + if [ "$?" != "0" ]; then + warning "Rsync error when trying to transfer $SECTION" + fi + fi + else + error "Invalid source $from" + exit 1 + fi + + $touch $backupdir/$SECTION/$section.0 + +done + +# remount backup destination as read-only + +if [ "$read_only" == "1" ] || [ "$read_only" == "yes" ]; then + mount -o remount,ro $mountpoint +fi + +# check partition for errors + +if [ "$fscheck" == "1" ] || [ "$fscheck" == "yes" ]; then + umount $mountpoint + if (($?)); then + warning "Could not umount $mountpoint to run fsck" + else + $nice $fsck -v -y $partition >> $log + mount $mountpoint + fi +fi + +# restart services + +if [ ! -z "$service" ]; then + for daemon in $service; do + info "Starting service $daemon..." + $initscripts/$daemon start + done +fi + +# removes the lockfile + +if [ ! -z "$lockfile" ]; then + $rm $lockfile || warning "Could not remove lockfile $lockfile" +fi + +echo "Finnishing backup at `date`" >> $log + diff --git a/handlers/rub.in b/handlers/rub.in deleted file mode 100644 index bdd6e99..0000000 --- a/handlers/rub.in +++ /dev/null @@ -1,348 +0,0 @@ -# -# backupninja handler to do incremental backups using -# rsync and hardlinks, based on -# -# http://www.mikerubel.org/computers/rsync_snapshots/ -# -# feedback: rhatto at riseup.net | gpl -# lot of enhancements grabbed from "rsnap" handler by paulv at bikkel.org -# -# Config file options -# ------------------- -# -# [general] -# log = rsync log file -# partition = partition where the backup lives -# fscheck = set to 1 if fsck should run on $partition after the backup is made -# read_only = set to 1 if $partition is mounted read-only -# mountpoint = backup partition mountpoint or backup main folder -# backupdir = folder relative do $mountpoint where the backup should be stored -# days = number of backup increments (min = 5) -# lockfile = lockfile to be kept during backup execution -# enable_mv_timestamp_bug = set to "yes" if your system isnt handling timestamps correctly -# tmp = temp folder -# -# [source] -# from = local or remote -# testconnect = when "yes", test the connection for a remote source before backup -# include = include folder on backup -# exclude = exclude folder on backup -# ssh = ssh command line (remote only) -# rsync = rsync program -# rsync_options = rsync command options -# exclude_vserver = vserver-name (valid only if vservers = yes on backupninja.conf) -# numericids = when set to 1, use numeric ids instead of user/group mappings on rsync -# compress = if set to 1, compress data on rsync (remote source only) -# bandwidthlimit = set a badnwidth limit in kbps (remote source only) -# remote_rsync = remove rsync program (remote source only) -# -# [services] -# initscripts = absolute path where scripts are located -# service = script name to be stoped at the begining of the backup and started at its end -# -# You can also specify some system comands if you don't want the default system values: -# -# [system] -# rm = rm command -# cp = cp command -# touch = touch command -# mv = mv command -# fsck = fsck command -# -# You dont need to manually specify vservers using "include = /vservers". -# They are automatically backuped if vserver is set to "yes" on you backupninja.conf. -# - -# config file evaluation - -setsection system -getconf rm rm -getconf cp cp -getconf touch touch -getconf mv mv -getconf fsck fsck - -setsection general -getconf log /var/log/backupninja-rub.log -getconf partition -getconf fscheck -getconf read_only -getconf mountpoint -getconf backupdir -getconf rotate -getconf days -getconf lockfile -getconf nicelevel 0 -getconf enable_mv_timestamp_bug no -getconf tmp /tmp - -setsection source -getconf from local -getconf testconnect no -getconf rsync $RSYNC -getconf rsync_options "-av --delete" -getconf ssh ssh -getconf user -getconf host -getconf include -getconf exclude -getconf exclude_vserver -getconf numericids 0 -getconf compress 0 -getconf bandwidthlimit -getconf remote_rsync rsync - -setsection services -getconf initscripts -getconf service - -# function definitions - -function rotate { - - if [[ "$2" -lt 4 ]]; then - error "Rotate: minimum of 4 rotations" - exit 1 - fi - - if [ -d $1.$2 ]; then - $nice $mv /$1.$2 /$1.tmp - fi - - for ((n=`echo "$2 - 1" | bc`; n >= 0; n--)); do - if [ -d $1.$n ]; then - dest=`echo "$n + 1" | bc` - $nice $mv /$1.$n /$1.$dest - $touch /$1.$dest - fi - done - - if [ -d $1.tmp ]; then - $nice $mv /$1.tmp /$1.0 - fi - - if [ -d $1.1 ]; then - $nice $cp -alf /$1.1/. /$1.0 - fi - -} - -function move_files { - - ref=$tmp/makesnapshot-mymv-$$; - $touch -r $1 $ref; - $mv $1 $2; - $touch -r $ref $2; - $rm $ref; - -} - -backupdir="$mountpoint/$backupdir" - -# does $backupdir exists? - -if [ ! -d "$backupdir" ]; then - error "Backupdir $backupdir does not exist" - exit 1 -fi - -# setup number of increments - -if [ -z "$days" ]; then - keep="4" -else - keep="`echo $days - 1 | bc -l`" -fi - -# lockfile setup - -if [ ! -z "$lockfile" ]; then - $touch $lockfile || warning "Could not create lockfile $lockfile" -fi - -# nicelevel setup - -if [ ! -z "$nicelevel" ]; then - nice="nice -n $nicelevel" -else - nice="" -fi - -# connection test - -if [ "$from" == "remote" ] && [ "$testconnect" == "yes" ]; then - debug "$ssh -o PasswordAuthentication=no $user@$host 'echo -n 1'" - result=`ssh -o PasswordAuthentication=no $user@$host 'echo -n 1'` - if [ "$result" != "1" ]; then - fatal "Can't connect to $host as $user." - else - debug "Connected to $srchost successfully" - fi -fi - -# rsync options for local sources - -if [ "$from" == "local" ]; then - - rsync_local_options="$rsync_options" - - if [ ! -z "$numericids" ]; then - rsync_local_options="$rsync_local_options --numeric-ids " - fi - -fi - -# rsync options for remote sources - -if [ "$from" == "remote" ]; then - - rsync_remote_options="$rsync_options --rsync-path=$remote_rsync" - - if [ "$compress" == "1" ]; then - rsync_remote_options="$rsync_remote_options --compress" - fi - - if [ ! -z "$bandwidthlimit" ]; then - rsync_remote_options="$rsync_remote_options --bwlimit=$bandwidthlimit" - fi - - if [ ! -z "$numericids" ]; then - rsync_remote_options="$rsync_remote_options --numeric-ids" - fi - -fi - -# set mv procedure - -if [ $enable_mv_timestamp_bug == "yes" ]; then - mv=move_files -fi - -# set excludes - -for path in $exclude; do - EXCLUDES="$EXCLUDES --exclude=$path" -done - -# stop services - -if [ ! -z "$service" ]; then - for daemon in $service; do - info "Stopping service $daemon..." - $initscripts/$daemon stop - done -fi - -echo "Starting backup at `date`" >> $log - -# mount backup destination folder as read-write - -if [ "$read_only" == "1" ] || [ "$read_only" == "yes" ]; then - if [ -d "$mountpoint" ]; then - mount -o remount,rw $mountpoint - if (($?)); then - error "Could not mount $mountpoint" - exit 1 - fi - fi -fi - -# add vservers to included folders - -if [ "$vservers_are_available" == "yes" ]; then - - # sane permission on backup - mkdir -p $backupdir/$VROOTDIR - chmod 000 $backupdir/$VROOTDIR - - for candidate in $found_vservers; do - candidate="`basename $candidate`" - found_excluded_vserver="0" - for excluded_vserver in $exclude_vserver; do - if [ "$excluded_vserver" == "$candidate" ]; then - found_excluded_vserver="1" - break - fi - done - if [ "$found_excluded_vserver" == "0" ]; then - include="$include $VROOTDIR/$candidate" - fi - done -fi - -# the backup procedure - -for SECTION in $include; do - - section="`basename $SECTION`" - - if [ ! -d "$backupdir/$SECTION/$section.0" ]; then - mkdir -p $backupdir/$SECTION/$section.0 - fi - - info "Rotating $backupdir/$SECTION/$section..." - echo "Rotating $backupdir/$SECTION/$section..." >> $log - rotate $backupdir/$SECTION/$section $keep - info "Syncing $SECTION on $backupdir/$SECTION/$section.0..." - - if [ "$from" == "local" ]; then - debug $rsync $rsync_local_options $EXCLUDES /$SECTION/ $backupdir/$SECTION/$section.0/ - $nice $rsync $rsync_local_options $EXCLUDES /$SECTION/ $backupdir/$SECTION/$section.0/ >> $log - if [ "$?" != "0" ]; then - warning "Rsync error when trying to transfer $SECTION" - fi - elif [ "$from" == "remote" ]; then - if [ -z "$user" ] || [ -z "$host" ]; then - error "Config file error: either user or host was not specified" - exit 1 - else - debug $nice $rsync $rsync_remote_options $EXCLUDES -e "$ssh" $user@$host:/$SECTION/ $backupdir/$SECTION/$section.0 - $nice $rsync $rsync_remote_options $EXCLUDES -e "$ssh" $user@$host:/$SECTION/ $backupdir/$SECTION/$section.0 >> $log - if [ "$?" != "0" ]; then - warning "Rsync error when trying to transfer $SECTION" - fi - fi - else - error "Invalid source $from" - exit 1 - fi - - $touch $backupdir/$SECTION/$section.0 - -done - -# remount backup destination as read-only - -if [ "$read_only" == "1" ] || [ "$read_only" == "yes" ]; then - mount -o remount,ro $mountpoint -fi - -# check partition for errors - -if [ "$fscheck" == "1" ] || [ "$fscheck" == "yes" ]; then - umount $mountpoint - if (($?)); then - warning "Could not umount $mountpoint to run fsck" - else - $nice $fsck -v -y $partition >> $log - mount $mountpoint - fi -fi - -# restart services - -if [ ! -z "$service" ]; then - for daemon in $service; do - info "Starting service $daemon..." - $initscripts/$daemon start - done -fi - -# removes the lockfile - -if [ ! -z "$lockfile" ]; then - $rm $lockfile || warning "Could not remove lockfile $lockfile" -fi - -echo "Finnishing backup at `date`" >> $log -