From 9584e5d415d180d8a5123b33775354d946192e58 Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Thu, 19 Nov 2009 15:09:46 +0100 Subject: [PATCH] initial revision: basic packaging code import from Mike Rubel's page (see copyright) --- .bzrignore | 3 ++ debian/changelog | 5 +++ debian/compat | 1 + debian/control | 13 +++++++ debian/copyright | 39 +++++++++++++++++++++ debian/dirs | 2 ++ debian/docs | 0 debian/rules | 91 ++++++++++++++++++++++++++++++++++++++++++++++++ remote-backup | 88 ++++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 242 insertions(+) create mode 100644 .bzrignore create mode 100644 debian/changelog create mode 100644 debian/compat create mode 100644 debian/control create mode 100644 debian/copyright create mode 100644 debian/dirs create mode 100644 debian/docs create mode 100755 debian/rules create mode 100644 remote-backup diff --git a/.bzrignore b/.bzrignore new file mode 100644 index 0000000..0d22da2 --- /dev/null +++ b/.bzrignore @@ -0,0 +1,3 @@ +*.ex +*.EX +.bzr-builddeb diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..ba670de --- /dev/null +++ b/debian/changelog @@ -0,0 +1,5 @@ +remote-backup (1.0) unstable; urgency=low + + * Initial Release. + + -- Vincent Riquer Thu, 19 Nov 2009 14:48:17 +0100 diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..7f8f011 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +7 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..0439d11 --- /dev/null +++ b/debian/control @@ -0,0 +1,13 @@ +Source: remote-backup +Section: unknown +Priority: extra +Maintainer: Vincent Riquer +Build-Depends: debhelper (>= 7) +Standards-Version: 3.7.3 +Homepage: + +Package: remote-backup +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends} +Description: + diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..21a3367 --- /dev/null +++ b/debian/copyright @@ -0,0 +1,39 @@ +This package was debianized by Vincent Riquer on +Thu, 19 Nov 2009 14:48:17 +0100. + +It was downloaded from http://www.mikerubel.org/computers/rsync_snapshots/ + +Upstream Author: + + Mike Rubel + +Copyright: + + Copyright (C) 2004 Mike Rubel + Copyright (C) 2009 Vincent Riquer + +License: + + This package is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This package is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this package; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +On Debian systems, the complete text of the GNU General +Public License can be found in `/usr/share/common-licenses/GPL'. + +The Debian packaging is (C) 2009, Vincent Riquer and +is licensed under the GPL, see above. + + +# Please also look if there are files or directories which have a +# different copyright/license attached and list them here. diff --git a/debian/dirs b/debian/dirs new file mode 100644 index 0000000..ca882bb --- /dev/null +++ b/debian/dirs @@ -0,0 +1,2 @@ +usr/bin +usr/sbin diff --git a/debian/docs b/debian/docs new file mode 100644 index 0000000..e69de29 diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..4faef5a --- /dev/null +++ b/debian/rules @@ -0,0 +1,91 @@ +#!/usr/bin/make -f +# -*- makefile -*- +# Sample debian/rules that uses debhelper. +# This file was originally written by Joey Hess and Craig Small. +# As a special exception, when this file is copied by dh-make into a +# dh-make output file, you may use that output file without restriction. +# This special exception was added by Craig Small in version 0.37 of dh-make. + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + + + + + +configure: configure-stamp +configure-stamp: + dh_testdir + # Add here commands to configure the package. + + touch configure-stamp + + +build: build-stamp + +build-stamp: configure-stamp + dh_testdir + + # Add here commands to compile the package. + $(MAKE) + #docbook-to-man debian/remote-backup.sgml > remote-backup.1 + + touch $@ + +clean: + dh_testdir + dh_testroot + rm -f build-stamp configure-stamp + + # Add here commands to clean up after the build process. + $(MAKE) clean + + dh_clean + +install: build + dh_testdir + dh_testroot + dh_clean -k + dh_installdirs + + # Add here commands to install the package into debian/remote-backup. + $(MAKE) DESTDIR=$(CURDIR)/debian/remote-backup install + + +# Build architecture-independent files here. +binary-indep: build install +# We have nothing to do by default. + +# Build architecture-dependent files here. +binary-arch: build install + dh_testdir + dh_testroot + dh_installchangelogs + dh_installdocs + dh_installexamples +# dh_install +# dh_installmenu +# dh_installdebconf +# dh_installlogrotate +# dh_installemacsen +# dh_installpam +# dh_installmime +# dh_python +# dh_installinit +# dh_installcron +# dh_installinfo + dh_installman + dh_link + dh_strip + dh_compress + dh_fixperms +# dh_perl +# dh_makeshlibs + dh_installdeb + dh_shlibdeps + dh_gencontrol + dh_md5sums + dh_builddeb + +binary: binary-indep binary-arch +.PHONY: build clean binary-indep binary-arch binary install configure diff --git a/remote-backup b/remote-backup new file mode 100644 index 0000000..f06985f --- /dev/null +++ b/remote-backup @@ -0,0 +1,88 @@ +#!/bin/bash +# ---------------------------------------------------------------------- +# mikes handy rotating-filesystem-snapshot utility +# ---------------------------------------------------------------------- +# this needs to be a lot more general, but the basic idea is it makes +# rotating backup-snapshots of /home whenever called +# ---------------------------------------------------------------------- + +unset PATH # suggestion from H. Milz: avoid accidental use of $PATH + +# ------------- system commands used by this script -------------------- +ID=/usr/bin/id; +ECHO=/bin/echo; + +MOUNT=/bin/mount; +RM=/bin/rm; +MV=/bin/mv; +CP=/bin/cp; +TOUCH=/bin/touch; + +RSYNC=/usr/bin/rsync; + + +# ------------- file locations ----------------------------------------- + +MOUNT_DEVICE=/dev/hdb1; +SNAPSHOT_RW=/root/snapshot; +EXCLUDES=/usr/local/etc/backup_exclude; + + +# ------------- the script itself -------------------------------------- + +# make sure we're running as root +if (( `$ID -u` != 0 )); then { $ECHO "Sorry, must be root. Exiting..."; exit; } fi + +# attempt to remount the RW mount point as RW; else abort +$MOUNT -o remount,rw $MOUNT_DEVICE $SNAPSHOT_RW ; +if (( $? )); then +{ + $ECHO "snapshot: could not remount $SNAPSHOT_RW readwrite"; + exit; +} +fi; + + +# rotating snapshots of /home (fixme: this should be more general) + +# step 1: delete the oldest snapshot, if it exists: +if [ -d $SNAPSHOT_RW/home/hourly.3 ] ; then \ +$RM -rf $SNAPSHOT_RW/home/hourly.3 ; \ +fi ; + +# step 2: shift the middle snapshots(s) back by one, if they exist +if [ -d $SNAPSHOT_RW/home/hourly.2 ] ; then \ +$MV $SNAPSHOT_RW/home/hourly.2 $SNAPSHOT_RW/home/hourly.3 ; \ +fi; +if [ -d $SNAPSHOT_RW/home/hourly.1 ] ; then \ +$MV $SNAPSHOT_RW/home/hourly.1 $SNAPSHOT_RW/home/hourly.2 ; \ +fi; + +# step 3: make a hard-link-only (except for dirs) copy of the latest snapshot, +# if that exists +if [ -d $SNAPSHOT_RW/home/hourly.0 ] ; then \ +$CP -al $SNAPSHOT_RW/home/hourly.0 $SNAPSHOT_RW/home/hourly.1 ; \ +fi; + +# step 4: 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! +$RSYNC \ + -va --delete --delete-excluded \ + --exclude-from="$EXCLUDES" \ + /home/ $SNAPSHOT_RW/home/hourly.0 ; + +# step 5: update the mtime of hourly.0 to reflect the snapshot time +$TOUCH $SNAPSHOT_RW/home/hourly.0 ; + +# and thats it for home. + +# now remount the RW snapshot mountpoint as readonly + +$MOUNT -o remount,ro $MOUNT_DEVICE $SNAPSHOT_RW ; +if (( $? )); then +{ + $ECHO "snapshot: could not remount $SNAPSHOT_RW readonly"; + exit; +} fi;