aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore25
-rw-r--r--AUTHORS1
-rw-r--r--Make.rules6
-rw-r--r--Makefile.am34
-rw-r--r--NEWS0
-rw-r--r--THANKS0
-rw-r--r--backup.conf112
-rw-r--r--backup.in110
-rw-r--r--configure.ac15
-rw-r--r--doc/.gitignore3
-rw-r--r--doc/Makefile.am7
-rw-r--r--doc/backup.1in208
-rw-r--r--doc/backup.conf.5in237
-rw-r--r--doc/restore.1in134
-rw-r--r--examples/Makefile.am1
-rw-r--r--examples/backup.conf.s3136
-rw-r--r--lib/Makefile.am1
-rw-r--r--lib/backup/.gitignore1
-rw-r--r--lib/backup/Makefile.am11
-rw-r--r--lib/backup/common.in86
-rwxr-xr-xlib/backup/fs.sh92
-rwxr-xr-xlib/backup/postgres.sh72
-rw-r--r--restore.in167
23 files changed, 1459 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..95cde12
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,25 @@
+*~
+.deps
+.emacs*
+.libs
+ABOUT-NLS
+COPYING
+ChangeLog
+INSTALL
+Makefile
+Makefile.in
+TAGS
+aclocal.m4
+autom4te.cache
+build-aux
+config.h
+config.h.in
+config.log
+config.status
+configure
+core
+backup.sh
+restore.sh
+build.sed
+*.tar.*
+tmp
diff --git a/AUTHORS b/AUTHORS
new file mode 100644
index 0000000..db7f07f
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1 @@
+Sergey Poznyakoff <gray@gnu.org.ua>
diff --git a/Make.rules b/Make.rules
new file mode 100644
index 0000000..013402b
--- /dev/null
+++ b/Make.rules
@@ -0,0 +1,6 @@
+.in.sh:
+ $(AM_V_GEN)sed -f $(top_builddir)/build.sed $< > $@
+.1in.1:
+ $(AM_V_GEN)sed -f $(top_builddir)/build.sed $< > $@
+.5in.5:
+ $(AM_V_GEN)sed -f $(top_builddir)/build.sed $< > $@
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..7702ede
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,34 @@
+SUBDIRS=. lib examples doc
+noinst_SCRIPTS=build.sed backup.sh restore.sh
+CLEANFILES=backup.sh restore.sh
+install-exec-hook:
+ for file in backup restore; \
+ do \
+ test -z "$(DESTDIR)$(bindir)" || \
+ $(mkdir_p) "$(DESTDIR)$(bindir)"; \
+ ${INSTALL} $(top_builddir)/$$file.sh \
+ $(DESTDIR)$(bindir)/$$file; \
+ done
+install-data-hook:
+ test -z "$(DESTDIR)$(sysconfdir)" || \
+ $(mkdir_p) "$(DESTDIR)$(sysconfdir)"; \
+ if test -f $(DESTDIR)$(sysconfdir)/backup.conf; then :; else \
+ ${INSTALL} -m 644 $(top_srcdir)/backup.conf $(DESTDIR)$(sysconfdir);\
+ fi
+uninstall-hook:
+ for file in backup restore; \
+ do \
+ rm -f "$(DESTDIR)$(bindir)/$$file"; \
+ done
+backup.sh restore.sh: build.sed
+EXTRA_DIST=backup.in restore.in backup.conf
+distuninstallcheck_listfiles=find $(DESTDIR)$(prefix) -type f -not -wholename '$(DESTDIR)$(sysconfdir)/backup.conf'
+
+$(top_builddir)/build.sed: Makefile
+ $(AM_V_GEN){ \
+ echo 's|@''SYSCONFDIR''@|${sysconfdir}|g';\
+ echo 's|@''LIBDIR''@|${libdir}|g'; \
+ echo 's|@''BINDIR''@|${bindir}|g'; \
+ } > $(top_builddir)/build.sed
+DISTCLEANFILES=build.sed backup.sh restore.sh
+include $(top_srcdir)/Make.rules
diff --git a/NEWS b/NEWS
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/NEWS
diff --git a/THANKS b/THANKS
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/THANKS
diff --git a/backup.conf b/backup.conf
new file mode 100644
index 0000000..297024f
--- /dev/null
+++ b/backup.conf
@@ -0,0 +1,112 @@
+# -*- shell-script -*-
+# This is a sample config file for the backup system. Tailor it to your
+# needs and remove the line below:
+echo >&2 "$0: WARNING: using default configuration boilerplate"
+
+# This file is essentially a shell script defining variables used by
+# the backup scripts. For a detailed information about it see backup.conf(5)
+# To debug the configuration, run "backup --dry-run" and "restore --dry-run".
+# For a detailed descriptions of these commands, see backup(1).
+
+# When set, the prologue hook is called right before starting backup or
+# restore. Similarly, the epilogue_hook is called immediately after
+# finishing all operations.
+# Use these hooks to perform any preliminary and/or cleanup jobs that
+# might be necessary in your setup.
+# When set, these variables must point to shell functions taking no
+# arguments. The best place to define such functions is perhaps in this
+# configuration file as well.
+#
+# By default, both variables are empty, i.e. no hooks are executed.
+
+prologue_hook=
+epilogue_hook=
+
+##########################################################################
+# Tar setup.
+#
+# Tar setup variables configure invocation of tar.
+#
+##########################################################################
+
+# Any additional options to pass to tar. Do not place tar operation
+# switches (as -c, -t, etc.) here! These will be added automatically
+# by appropriate scripts, depending on the operation being performed.
+#
+# By default this variable is empty (no additional options).
+#
+# In this example it is used to request bzip2 compression:
+backup_tar_options="-j"
+
+# Suffix for archive files.
+# Default is "tar"
+#
+backup_suffix="tar.bz2"
+
+# Directory where archive files are to be located. It's OK to specify
+# a remote directory here, e.g. 10.10.0.1:/export/backup
+#
+# This variable must be set. Whatever directory it points to must already
+# exist, the backup script won't create it.
+backup_archive_dir=/var/run
+
+# Directory where to store snapshot files. The files will be named as
+# their archive counterparts, with the suffix ".db".
+#
+# This variable must be set
+backup_snapshot_dir=/var/run
+
+# Set this variable to a non-empty value if you wish backup procedures to
+# be verbose.
+backup_verbose=
+
+##########################################################################
+# Backup items.
+#
+# Backup items are symbolic names that identify abstract objects that
+# need to be backed up (or restored). These must be valid shell variable
+# names. For each backup item <name>, this configuration file defines a
+# set of variables which determine what files to backup and what methods
+# to use for that. Each such variable is named <name>_<variable>, where
+# <name> is the item name, and <variable> is the variable name. The set
+# of variables needed depends on the type of each particular item.
+#
+##########################################################################
+
+# The following are sample entries. Be sure to edit them
+
+# Define the list of items to back up.
+# This variable must be set.
+backup_items="dbdump system"
+
+# For each item in $backup_items, at least its type (variable <item>_type)
+# must be declared. The item type determines the mechanism used to backup
+# and restore it. Valid item types are:
+#
+# fs back up a file system
+# postgres back up a postgres database
+#
+# You may define additional types, if you need. To do so, create an executable
+# file named <type>.sh in the directory @LIBDIR@/backup. See backup_type(5),
+# for a detailed description.
+#
+
+# Dump Postgres database "mydb".
+# The <item>_database is the only variable required by type "postgres".
+dbdump_type=postgres
+dbdump_database="mydb"
+
+# Back up directories in the file system.
+# The "fs" type requires at least to variables:
+#
+# <item>_dir specifies the directory (usually, but not necessarily a mount
+# point), under which the directories and files to be backed up are located.
+#
+# <item>_files specifies a list of directories and/or files in that directory.
+
+system_type=fs
+system_dir="/"
+system_files="etc var/spool"
+
+
+
diff --git a/backup.in b/backup.in
new file mode 100644
index 0000000..f14850f
--- /dev/null
+++ b/backup.in
@@ -0,0 +1,110 @@
+#! /bin/bash
+# This script creates a backup of this system. For usage instructions,
+# run `backup --help'. For a detailed description of the backup and
+# restore procedures, see /export/backup/snapshot/README.
+
+libdir=@LIBDIR@/backup
+set -e
+. $libdir/common.sh
+set +e
+ts=`date +%Y%m%d`;
+week=`date +%U`
+
+# Add version-specific tar options
+tar_version_options() {
+ set -- $(tar --version | awk 'NR==1 {gsub(/\./, " ",$NF); print $NF}')
+ if [ $# -ge 2 ]; then
+ v=$((1 * 1000 + $2))
+ if [ $v -gt 1025 ]; then
+ taroptions="$taroptions --level=$level"
+ fi
+ fi
+}
+
+load_config
+taroptions="-Hpax $backup_tar_options $backup_rsh_command"
+
+###########################################################
+# Global variables
+###########################################################
+
+# Set it to "-v" to make script verbose
+if [ -n "$backup_verbose" ]; then
+ verbose=-v
+else
+ verbose=
+fi
+# Set it to "echo" to initiate dry-run mode.
+dry_run=
+
+# Number of tar errors detected during the run
+tarerror=0
+
+level=0
+round=0
+
+###########################################################
+# Utility functions
+###########################################################
+
+help() {
+ cat <<EOF
+usage: $0 [OPTIONS]
+makes incremental backup of that system
+
+OPTIONS:
+
+ -v, --verbose increase verbosity
+ -l, --logfile FILE log to FILE (default $backup_logfile)
+ -n, --dry-run do nothing, print what would have been done
+ -N, --no-logfile log to stderr
+ -L, --level N create incremental dump level N
+ -R, --round N mark archives with incremental round N
+ --week N force using week number N instead of the current one
+ -h, --help produce this help list
+EOF
+ exit 0
+}
+
+###########################################################
+# Main
+###########################################################
+
+while [ $# -ne 0 ]
+do
+ case $1 in
+ -v|--verbose) verbose="$verbose -v";;
+ -l|--logfile) shift; backup_logfile=$1;;
+ -n|--dry-run) dry_run=echo;;
+ -N|--no-logfile) backup_logfile=;;
+ -h|--help) help;;
+ -L|--level) shift; level=$1;;
+ -R|--round) shift; round=$1;;
+ --week) shift; week=$1;;
+ *) echo >&2 "$0: unrecognized option $1"; exit 1;;
+ esac
+ shift
+done
+
+tar_version_options
+
+if [ -n "$backup_logfile" ]; then
+ exec >>$backup_logfile
+ exec 2>&1
+fi
+logit "started"
+
+$prologue_hook
+
+for item in $backup_items
+do
+ eval type=\$${item}_type
+ ${type}_backup $item
+done
+
+$epilogue_hook
+
+logit "finished"
+
+# finis coronat opus
+
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..b58cc91
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,15 @@
+AC_PREREQ(2.63)
+
+AC_INIT(backup, 1.0, gray@gnu.org.ua)
+AC_CONFIG_SRCDIR(backup.in)
+AC_CONFIG_AUX_DIR([build-aux])
+AM_INIT_AUTOMAKE([1.11 tar-ustar silent-rules])
+
+# Enable silent rules by default:
+AM_SILENT_RULES([yes])
+
+AC_OUTPUT(Makefile
+ lib/Makefile
+ lib/backup/Makefile
+ examples/Makefile
+ doc/Makefile)
diff --git a/doc/.gitignore b/doc/.gitignore
new file mode 100644
index 0000000..a3c168a
--- /dev/null
+++ b/doc/.gitignore
@@ -0,0 +1,3 @@
+backup.1
+restore.1
+backup.conf.5
diff --git a/doc/Makefile.am b/doc/Makefile.am
new file mode 100644
index 0000000..c7d6d3b
--- /dev/null
+++ b/doc/Makefile.am
@@ -0,0 +1,7 @@
+man_MANS = backup.conf.5 backup.1 restore.1
+backup.1: backup.1in Makefile
+backup.conf.5: backup.conf.5in Makefile
+restore.1: restore.1in Makefile
+EXTRA_DIST=backup.1in restore.1in backup.conf.5in
+DISTCLEANFILES=backup.conf.5 backup.1 restore.1
+include $(top_srcdir)/Make.rules
diff --git a/doc/backup.1in b/doc/backup.1in
new file mode 100644
index 0000000..b6087b5
--- /dev/null
+++ b/doc/backup.1in
@@ -0,0 +1,208 @@
+.\" This file is part of backup -*- nroff -*-
+.\" Copyright (C) 2012 Sergey Poznyakoff
+.\"
+.\" Backup 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 3, or (at your option)
+.\" any later version.
+.\"
+.\" Backup 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 backup. If not, see <http://www.gnu.org/licenses/>.
+.\"
+.TH BACKUP 1 "May 17, 2012" "BACKUP" "Backup User Reference"
+.SH NAME
+backup \- create a back up.
+.SH SYNOPSIS
+.B backup
+[\fB\-h\fR] [\fB\-\-help\fR]
+
+.B backup
+[\fB\-vnN\fR] [\fB\-\-verbose\fR] [\fB\-l\fR \fIFILE\fR]\
+ [\fB\-\-logfile\fR \fIFILE\fR]\
+ [\fB\-\-dry\-run\fR]
+ [\fB\-L\fR \fIN\fR] [\fB\-\-level\fR \fIN\fR]
+ [\fB\-R\fR \fIN\fR] [\fB\-\-round\fR \fIN\fR] [\fB\-\-week\fR \fIN\fR]
+.SH DESCRIPTION
+The
+.B backup
+script creates full or incremental backups of file systems and other
+objects described in its configuration file
+.BR backup.conf .
+The configuration file by default is searched in
+.BR @SYSCONFDIR@ .
+Another location can be specified by setting the environment variable
+.B BACKUP_CONFIG
+to the full pathname of the configuration file.
+.PP
+After loading the configuration file, the script examines its command
+line for options that modify its behavior. These are described in
+detail in the section
+.BR OPTIONS ,
+below.
+.PP
+The script uses
+.BR tar (1)
+to produce incremental backups. The produced archives are named using
+the following pattern:
+.sp
+.nf
+.in +2
+.BR ITEM - WEEK - ROUND - LEVEL . SUFFIX
+.in
+.fi
+.sp
+where:
+.TP
+.B ITEM
+The name of the backup item. Backup items are defined in the
+configuration variable \fBbackup_items\fR and identify file systems
+(or other objects, such as PostgreSQL databases) to backup. See the
+section
+.B BACKUP ITEMS
+in
+.BR backup.conf (5),
+for a detailed description.
+.TP
+.B WEEK
+The number of week when this backup was taken. This is a number of
+week in year, formatted as a two-digit decimal number in the range 01
+to 53. Weeks are numbered starting with the first Sunday as the first
+day of week 01. For more details, see
+.BR strftime (3)
+conversion
+.BR %U .
+.TP
+.B ROUND
+The \fBround number\fR of this backup. This number identifies a
+particular series of incremental backups (starting at level 1), taken
+with respect to the same full backup.
+
+Consider for example the following backup schedule. A full backup is
+taken each Sunday. Then, during the week, incremental backups are
+taken daily: level one backup on Monday, level two backup on Tuesday,
+then again level one on Wednesday, and so on. In this scheme you get
+three rounds of backups each week. See the
+.B EXAMPLES
+section for an example of this schedule.
+.TP
+.B LEVEL
+Incremental level number.
+.TP
+.B SUFFIX
+The value of \fBbackup_suffix\fR configuration variable. If not set,
+.B tar
+is assumed.
+.PP
+The archives are stored in the directory specified by the
+.B backup_archive_dir
+configuration variable. This directory can be a local as well as a
+remote one. To use a remote location, set this variable to
+.sp
+.nf
+.in +2
+.BR HOST : DIR
+.in
+.fi
+.sp
+where
+.B HOST
+is the IP address or hostname of the remote machine, and
+.B DIR
+is the pathname on its file system. See the \fBThe GNU Tar Manual\fR,
+section 9.2 \fBRemote Tape Server\fR for more information on the subject.
+.PP
+The corresponding snapshots are stored in the directory specified by
+the \fBbackup_snapshot_dir\fR configuration variable and follow the
+same scheme as the archives, except that
+.B db
+is used as their suffix.
+.SH OPTIONS
+.TP
+\fB\-v\fR, \fB\-\-verbose\fR
+Increase verbosity. This overrides the \fBbackup_verbose\fR
+configuration variable.
+.TP
+\fB\-l\fR, \fB\-\-logfile\fR \fIFILE\fB
+Log to FILE. This overrides the \fBbackup_logfile\fR configuration
+variable.
+.TP
+\fB\-n\fR, \fB\-\-dry\-run
+Do nothing, print what would have been done. Use this to debug your
+configuration.
+.TP
+\fB\-N\fR, \fB\-\-no\-logfile
+Do not use \fBbackup_logfile\fR variable, log to standard error
+instead.
+.TP
+\fB\-L\fR, \fB\-\-level \fIN\fR
+Create incremental dump level \fIN\fR.
+.TP
+\fB-R\fR, \fB\-\-round \fIN\fR
+Mark archives with incremental round number \fIN\fR.
+.TP
+\fB\-\-week \fIN\fR
+Force using week number \fIN\fR. By default, the current week number
+(as returned by
+.BR strftime (3)
+conversion
+.BR %U )
+is used.
+.TP
+\fB\-h\fR, \fB\-\-help\fR
+Display a short help summary.
+.SH EXAMPLES
+Usually \fBbackup\fR is started as a cron job. The following
+example shows a root crontab designed so as to create full (level 0)
+backups on Sundays, level 1 backups on Mondays, Wednesdays and Fridays
+and level 2 backups on Tuesdays, Thursdays and Saturdays.
+.sp
+.nf
+.in +2
+# Create one full backup weekly.
+0 3 * * sun backup --round 0 --level 0
+# Create incremental backups daily.
+0 3 * * mon backup --round 0 --level 1
+0 3 * * tue backup --round 0 --level 2
+0 3 * * wed backup --round 1 --level 1
+0 3 * * thu backup --round 1 --level 2
+0 3 * * fri backup --round 2 --level 1
+0 3 * * sat backup --round 2 --level 2
+.in
+.fi
+.sp
+.SH FILES
+.TP
+.BR @SYSCONFDIR@/backup.conf
+Default configuration file.
+.TP
+.BR @LIBDIR@/backup
+Backup module directory. Whenever a backup item of type \fBT\fR is
+requested, \fBbackup\fR will attempt to load from this directory a
+file named \fBT.sh\fR. This file provides methods and definitions
+necessary to handle that particular item type.
+.TP
+.BR @LIBDIR@/backup/common.sh
+Settings and definitions shared between
+.BR backup
+and
+.BR restore (1).
+.SH "SEE ALSO"
+.BR restore (1),
+.BR backup.conf (5).
+.SH AUTHORS
+Sergey Poznyakoff
+.SH "BUG REPORTS"
+Report bugs to <gray@gnu.org.ua>.
+.\" Local variables:
+.\" eval: (add-hook 'write-file-hooks 'time-stamp)
+.\" time-stamp-start: ".TH [A-Z_][A-Z0-9_]* [0-9] \""
+.\" time-stamp-format: "%:B %:d, %:y"
+.\" time-stamp-end: "\""
+.\" time-stamp-line-limit: 20
+.\" end:
+
diff --git a/doc/backup.conf.5in b/doc/backup.conf.5in
new file mode 100644
index 0000000..aa0bfe8
--- /dev/null
+++ b/doc/backup.conf.5in
@@ -0,0 +1,237 @@
+.\" This file is part of backup -*- nroff -*-
+.\" Copyright (C) 2012 Sergey Poznyakoff
+.\"
+.\" Backup 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 3, or (at your option)
+.\" any later version.
+.\"
+.\" Backup 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 backup. If not, see <http://www.gnu.org/licenses/>.
+.\"
+.TH BACKUP.CONF 1 "May 16, 2012" "BACKUP.CONF" "Backup User Reference"
+.SH NAME
+backup.conf \- configuration file for backup system
+.SH DESCRIPTION
+The \fBbackup.conf\fR configuration file defines what files are to be
+included in the backup, what backup methods to use and where to store
+the resulting archives. The
+.BR backup (1)
+and
+.BR restore (1)
+utilities expect to find it in the
+.B @SYSCONFDIR@
+directory.
+.SH SYNTAX
+The file is essentially a shell script that defines variables
+controlling backup and restore procedures. The names of the variables
+used by the backup scripts begin with
+.BR backup_ .
+.SH GENERAL SETUP
+.TP
+.B backup_logfile
+If set, redirect standard error and standard output to that file. The
+file will be created if it does not exist. Otherwise, the output will be
+appended to it.
+.TP
+.B backup_rsh_command
+Use this command to access remote archives. Unless set, the backup
+utilities will first look for an executable file named
+.BR @BINDIR@/speedssh .
+If not found, they will fall back to using \fB/usr/bin/ssh\fR. It is
+the responsibility of the administrator to provide for authentication
+on the remote system, e.g. by using shared-key authentication.
+.SH TAR SETUP
+Tar setup variables control additional options and arguments passed to
+.BR tar (1).
+.TP
+.B backup_tar_options
+Use this variable to pass additional options to tar. Do not place tar
+operation switches (such as \fB-c\fR, \fB-t\fR, etc.) here! These
+will be added automatically by appropriate scripts, depending on the
+operation being performed
+
+By default this variable is empty (no additional options passed to tar).
+.TP
+.B backup_suffix
+This variable supplies suffix for created archive names. The default
+is
+.B tar .
+The dot is inserted between the file name and its suffix.
+
+This variable is useful if you request compression and want archive
+file names to reflect it. For example:
+.sp
+.nf
+.in +2
+backup_tar_options="-j"
+backup_suffix="tar.bz2"
+.in
+.fi
+.sp
+.TP
+.B backup_archive_dir
+Directory where archive files are located. It's OK to specify
+a remote directory here, e.g.
+.sp
+.nf
+.in +2
+backup_archive_dir="10.10.0.1:/export/backup"
+.in
+.fi
+.sp
+This variable must be defined and whatever directory it points to must
+already exist.
+.TP
+.B backup_snapshot_dir
+Directory for incremental snapshot files. These files are be named after
+their archive counterparts, by appending the
+.B .db
+suffix.
+.TP
+.B backup_verbose
+Set this variable to any non-empty value to request additional
+verbosity. The effect of this setting depends on backup methods being
+used. For example, the
+.B fs
+method adds a
+.B \-v
+option to each invocation of
+.BR tar (1).
+.SH BACKUP ITEMS
+A
+.B backup item
+identifies information that needs to be backed up. Syntactically,
+items follow the same rules as shell variable names. Backup items
+are introduced using the following variable:
+.TP
+.B backup_items
+A whitespace-separated list of backup items.
+.PP
+For each backup item
+.B name
+the configuration file must provide a set of variables describing
+where to obtain this information and how to store it to the archive.
+These variables follow the same naming convention:
+.sp
+.nf
+.in +2
+\fBname\fR_\fBvar\fR
+.in
+.fi
+.sp
+where \fBname\fR is the item name and \fIvar\fR is a valid shell
+identifier.
+
+The
+.B \fBname\fR_type
+variable must always be defined. It identifies the backup method
+to be applied to that item. Currently two backup methods are
+implemented:
+.TP
+.B fs
+A file system backup.
+.TP
+.B postgres
+Backup of a PostgreSQL database.
+.SH FS BACKUP TYPE
+This is the basic backup type, which means incremental backups of a
+specified file system. For each item of this type, the following
+variables must be defined:
+.TP
+.B \fIitem\fB_dir
+The absolute path to the file system being backed up.
+.TP
+.B \fIitem\fB_files
+A whitespace-separated list of directories and/or files in the
+.B \fIitem\fB_dir
+directory.
+.PP
+For example:
+.sp
+.nf
+.in +2
+backup_items="system"
+
+system_type=fs
+system_dir="/"
+system_files="etc var/spool"
+.in
+.fi
+.sp
+This configuration requests incremental backups of everything found in
+the directories \fB/etc\fR and \fB/var/spool\fR.
+.SH POSTGRES BACKUP TYPE
+The
+.B postgres
+type creates a dump of a PostgreSQL database and archives it using
+.BR tar (1).
+The following variables must be defined for items of this type:
+.TP
+.B \fIitem\fB_database
+The database name.
+.SH HOOKS
+Two special variables, called hooks, allow you to supply arbitrary
+procedures to be run before and after backup.
+.TP
+.B prologue_hook
+This variable contains the name of a shell procedure or external
+program to be called before starting backup (or restore). The hook is
+called without arguments. By default, this variable is empty.
+.TP
+.B epilogue_hook
+This variable contains the name of a shell procedure or external
+program to be called after backup (or restore) is finished. The hook
+is called without arguments. By default, this variable is empty.
+.SH EXAMPLES
+A simple configuration file for backing up the contents of
+.BR /etc,
+.BR /home ,
+and the PostreSQL database
+.BR savane :
+.sp
+.nf
+.in +2
+# Request bzip2 compression:
+backup_tar_options="-j"
+# Modify file name suffix accordingly
+backup_suffix="tar.bz2"
+# Write data to \fB/dev/rmt1\fR on a remote machine:
+backup_archive_dir=192.168.0.1:/dev/rmt1
+# Keep snapshots in this directory:
+backup_snapshot_dir=/var/snapshots
+
+# Two backup items are defined:
+backup_items="dbdump system"
+
+# The \fBdbdump\fR item dumps the database:
+dbdump_type=postgres
+dbdump_database=savane
+
+# The \fBsystem\fR item backs up the file system:
+system_type=fs
+system_dir="/"
+system_files="etc home"
+.in
+.fi
+.sp
+.SH "SEE ALSO"
+.BR restore (1),
+.BR backup (1).
+.SH AUTHORS
+Sergey Poznyakoff
+.SH "BUG REPORTS"
+Report bugs to <gray@gnu.org.ua>.
+.\" Local variables:
+.\" eval: (add-hook 'write-file-hooks 'time-stamp)
+.\" time-stamp-start: ".TH [A-Z_][A-Z0-9_]* [0-9] \""
+.\" time-stamp-format: "%:B %:d, %:y"
+.\" time-stamp-end: "\""
+.\" time-stamp-line-limit: 20
+.\" end:
+
diff --git a/doc/restore.1in b/doc/restore.1in
new file mode 100644
index 0000000..ee88781
--- /dev/null
+++ b/doc/restore.1in
@@ -0,0 +1,134 @@
+.\" This file is part of backup -*- nroff -*-
+.\" Copyright (C) 2012 Sergey Poznyakoff
+.\"
+.\" Backup 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 3, or (at your option)
+.\" any later version.
+.\"
+.\" Backup 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 backup. If not, see <http://www.gnu.org/licenses/>.
+.\"
+.TH RESTORE 1 "May 17, 2012" "RESTORE" "Backup User Reference"
+.SH NAME
+restore \- restore file system from a backup.
+.SH SYNOPSIS
+.B restore
+[\fB\-h\fR] [\fB\-\-help\fR]
+
+.B restore
+[\fB\-cntv\fR] [\fB\-\-confirm\fR] [\fB\-C\fR \fIDIR\fR]\
+ [\fB\-\-directory\fR \fIDIR\fR] [\fB\-\-verbose\fR]
+ [\fB\-\-dry\-run\fR] [\fB\-\-list\fR] [\fB\-\-logfile\fR \fIFILE\fR]\
+ [\fB\-L\fR \fIN\fR] [\fB\-\-level\fR \fIN\fR]
+ [\fB\-R\fR \fIN\fR] [\fB\-\-round\fR \fIN\fR] [\fB\-\-week\fR \fIN\fR]
+ [\fBITEM\fR [\fBITEM\fR...]]
+.SH DESCRIPTION
+The
+.B restore
+utility restores the file system from incremental backups created
+using
+.BR backup (1).
+.PP
+The program reads its configuration from the file
+.B backup.conf
+located in the
+.B @SYSCONFDIR@
+directory, or from the file named in the environment variable
+.BR BACKUP_CONFIG .
+The configuration file must exist.
+.PP
+After loading the configuration file, the program examines its command
+line for options that modify its behavior. These are described in
+detail in the section
+.BR OPTIONS ,
+below.
+.PP
+Once the configuration loaded, the
+.B restore
+utility determines which backup archives to use for restoring. Unless
+being requested otherwise by the command line options, the utility
+selects the most recent set of backup files.
+.PP
+Before starting the restore, the utility displays the backup files it
+has selected and asks the user if he wishes to proceed. Empty line
+(the \fBCR\fR alone) or any word beginning with \fBY\fR
+(case-insensitive) is taken as affirmative. Otherwise, a negative
+answer is assumed and program terminates.
+.PP
+The program restores file systems and other backup items in the
+order they are listed in the \fBbackup_items\fR configuration
+variable. The \fBITEM\fR arguments override this default. If they
+are present, the program will restore only those items that are listed
+in the command line and exactly in the order they appear.
+.SH OPTIONS
+.TP
+\fB\-c\fR, \fB\-\-confirm\fR
+Do not ask for confirmation; run straight into restoring.
+.TP
+\fB\-C\fR, \fB\-\-directory\fR \fIDIR\fR
+Restore into directory \fIDIR\fR instead of \fB/\fR.
+.TP
+\fB\-v\fR, \fB\-\-verbose\fR
+Increase verbosity.
+.TP
+\fB\-n\fR, \fB\-\-dry\-run\fR
+Do nothing, but print what would have been done.
+.TP
+\fB\-t\fR, \fB\-\-list\fR
+List archive files, instead of extracting from them.
+.TP
+\fB\-l\fR, \fB\-\-logfile\fR \fIFILE\fB
+Log to \fIFILE\fR instead of the standard error. This option implies
+\fB\-\-confirm\R. Note also, that due to its specific nature
+.B restore
+ignores the \fBbackup_logfile\fR configuration setting.
+.TP
+\fB\-L\fR, \fB\-\-level\fR \fIN\fN
+Set incremental dump level to stop at.
+.TP
+\fB\-R\fR, \fB\-\-round\fR \fIN\fR
+Use archives from incremental round \fIN\fR.
+.TP
+\fB\-W\fR, \fB\-\-week\fR \fIN\fR
+Use archives from week \fIN\fR.
+.TP
+\fB\-h\fR, \fB\-\-help\fR
+Display a short help summary.
+.SH EXAMPLES
+.SH FILES
+.TP
+.BR @SYSCONFDIR@/backup.conf
+Default configuration file.
+.TP
+.BR @LIBDIR@/backup
+Backup module directory. Whenever a backup item of type \fBT\fR is
+requested, \fBrestore\fR will attempt to load from this directory a
+file named \fBT.sh\fR. This file provides methods and definitions
+necessary to handle that particular item type.
+.TP
+.BR @LIBDIR@/backup/common.sh
+Settings and definitions shared between
+.BR backup (1)
+and
+.BR restore.
+.SH "SEE ALSO"
+.BR backup (1),
+.BR backup.conf (5)
+.SH AUTHORS
+Sergey Poznyakoff
+.SH "BUG REPORTS"
+Report bugs to <gray@gnu.org.ua>.
+.\" Local variables:
+.\" eval: (add-hook 'write-file-hooks 'time-stamp)
+.\" time-stamp-start: ".TH [A-Z_][A-Z0-9_]* [0-9] \""
+.\" time-stamp-format: "%:B %:d, %:y"
+.\" time-stamp-end: "\""
+.\" time-stamp-line-limit: 20
+.\" end:
+
diff --git a/examples/Makefile.am b/examples/Makefile.am
new file mode 100644
index 0000000..c5a0a76
--- /dev/null
+++ b/examples/Makefile.am
@@ -0,0 +1 @@
+EXTRA_DIST=backup.conf.s3
diff --git a/examples/backup.conf.s3 b/examples/backup.conf.s3
new file mode 100644
index 0000000..07b3d68
--- /dev/null
+++ b/examples/backup.conf.s3
@@ -0,0 +1,136 @@
+# -*- shell-script -*-
+# This is an example configuration for backing up to an s3 mount.
+# It uses s3backer to mount the s3 bucket.
+#
+# Search for strings matching @.*@ and follow the comments to replace
+# them with your actual values.
+#
+# For a detailed information about backup.conf format, see backup.conf(5)
+# To debug the configuration, run "backup --dry-run" and "restore --dry-run".
+# For a detailed descriptions of these commands, see backup(1).
+
+# Set your s3 bucket name here
+backup_bucket_name=@YOUR-BUCKET-NAME@
+
+# Raw bucket is mounted to /mnt/s3backer
+mp_s3backer=/mnt/s3backer
+# The actual file system is mountet to /mnt/s3
+mp_s3=/mnt/s3
+
+# Make sure both mountpoints exist
+test -d $mp_s3backer || mkdir mp_s3backer
+test -d $mp_s3 || mkdir mp_s3backer
+
+# This variable is populated by prologue and is used by epilogue to unmount
+# s3-backed file system.
+umount_list=""
+
+# Prologue function is responsible for mounting the s3-backed fs.
+prologue() {
+# Sample mount output, split into several lines:
+# http://finox-backup-fs.s3.amazonaws.com/ on /mnt/s3backer type fuse.s3backer
+# (rw,nosuid,nodev,allow_other,default_permissions)
+ set -- $(mount -tfuse.s3backer |
+ awk '/https?:\/\/'$backup_bucket_name'/ { print $3 }')
+ if test -z "$1"; then
+ $dry_run s3backer --accessFile=/root/.s3backer_passwd --vhost \
+ $backup_bucket_name $mp_s3backer ||
+ abend 1 "unable to mount $backup_bucket_name"
+ umount_list="$mp_s3backer"
+ else
+ mp_s3backer=$1
+ fi
+ set -- $(mount | grep "^${mp_s3backer}/file" | awk '{ print $3 }')
+ if test -z "$1"; then
+ case $(basename $0) in
+ restore) mountopt=",ro";;
+ backup) mountopt=",rw,data=writeback";;
+ *) error "called as $0: assuming default mount options"
+ esac
+ # NOTE: For ext4 add the journal_async_commit option.
+ $dry_run mount -oloop$mountopt $mp_s3backer/file $mp_s3 ||
+ abend 1 "unable to mount $mp_s3backer/file"
+ umount_list="$mp_s3 $umount_list"
+ else
+ mp_s3=$1
+ fi
+}
+
+# Epilogue function unmounts all fs mounted so far.
+epilogue() {
+ for mp in $umount_list
+ do
+ $dry_run umount $mp
+ done
+}
+
+# Initialize hooks.
+prologue_hook=prologue
+epilogue_hook=epilogue
+
+##########################################################################
+# Tar setup.
+#
+# Tar setup variables configure invocation of tar.
+#
+##########################################################################
+
+# Any additional options to pass to tar. Do not place tar operation
+# switches (as -c, -t, etc.) here! These will be added automatically
+# by appropriate scripts, depending on the operation being performed.
+#
+# By default this variable is empty (no additional options).
+#
+# In this example it is used to request bzip2 compression:
+backup_tar_options="-b1000 -j"
+
+# Suffix for archive files.
+# Default is "tar"
+#
+backup_suffix="tar.bz2"
+
+# Directory where archive files are to be located. It's OK to specify
+# a remote directory here, e.g. 10.10.0.1:/export/backup
+#
+# This variable must be set. Whatever directory it points to must already
+# exist, the backup script won't create it.
+backup_archive_dir=$mp_s3
+
+# Directory where to store snapshot files. The files will be named as
+# their archive counterparts, with the suffix ".db".
+#
+# This variable must be set
+backup_snapshot_dir=@YOUR-SNAPSHOT-DIR@
+
+# Set this variable to a non-empty value if you wish backup procedures to
+# be verbose.
+backup_verbose=
+
+##########################################################################
+# Backup items.
+#
+# Backup items are symbolic names that identify abstract objects that
+# need to be backed up (or restored). These must be valid shell variable
+# names. For each backup item <name>, this configuration file defines a
+# set of variables which determine what files to backup and what methods
+# to use for that. Each such variable is named <name>_<variable>, where
+# <name> is the item name, and <variable> is the variable name. The set
+# of variables needed depends on the type of each particular item.
+#
+##########################################################################
+
+backup_items="dbdump index repo"
+
+dbdump_type=postgres
+dbdump_database="alfresco"
+
+index_type=fs
+index_dir="/export/data/alfresco"
+index_files="backup-lucene-indexes"
+
+repo_type=fs
+repo_dir="/export/data/alfresco"
+repo_files="contentstore oouser contentstore.deleted"
+
+
+
diff --git a/lib/Makefile.am b/lib/Makefile.am
new file mode 100644
index 0000000..b26ee9a
--- /dev/null
+++ b/lib/Makefile.am
@@ -0,0 +1 @@
+SUBDIRS=backup \ No newline at end of file
diff --git a/lib/backup/.gitignore b/lib/backup/.gitignore
new file mode 100644
index 0000000..5621a6e
--- /dev/null
+++ b/lib/backup/.gitignore
@@ -0,0 +1 @@
+common.sh
diff --git a/lib/backup/Makefile.am b/lib/backup/Makefile.am
new file mode 100644
index 0000000..ec4cb91
--- /dev/null
+++ b/lib/backup/Makefile.am
@@ -0,0 +1,11 @@
+libbackupdir=$(libdir)/backup
+libbackup_SCRIPTS=\
+ common.sh\
+ fs.sh\
+ postgres.sh
+EXTRA_DIST=\
+ common.in\
+ fs.sh\
+ postgres.sh
+DISTCLEANFILES=common.sh
+include $(top_srcdir)/Make.rules
diff --git a/lib/backup/common.in b/lib/backup/common.in
new file mode 100644
index 0000000..ab80204
--- /dev/null
+++ b/lib/backup/common.in
@@ -0,0 +1,86 @@
+#! /bin/bash
+
+# Force C locale
+LC_ALL=C
+export LC_ALL
+
+prologue_hook=
+epilogue_hook=
+
+# User configuration variables
+backup_tar_options=
+backup_suffix=
+backup_archive_dir=
+backup_snapshot_dir=
+backup_verbose=
+backup_logfile="/var/log/backup"
+
+error() {
+ echo >&2 $0: $*
+}
+
+logit() {
+ echo `date`: $*
+}
+
+abend() {
+ ec=$1
+ shift
+ error $@
+ exit $ec
+}
+
+tarcode() {
+ case $1 in
+ 0) echo "`date`: success";;
+ 1) echo "`date`: some files changed while being archived";;
+ 2) echo "`date`: fatal error occurred, but trying to continue anyway"
+ tarerror=$((tarerror + 1));;
+ *) echo "`date`: unexpected error code $1"
+ tarerror=$((tarerror + 1));
+ esac
+}
+
+load_config() {
+ local delayed_exit
+
+ test -z "$BACKUP_CONFIG" && BACKUP_CONFIG=@SYSCONFDIR@/backup.conf
+ if [ -r $BACKUP_CONFIG ]; then
+ . $BACKUP_CONFIG
+ else
+ abend 1 "configuration file $BACKUP_CONFIG does not exist or is unreadable"
+ fi
+
+ if [ -z "$backup_items" ]; then
+ abend 1 "backup_items not specified"
+ fi
+
+ delayed_exit=
+ loaded_types=
+ for item in $backup_items
+ do
+ eval type=\$${item}_type
+ if [ -z "$type" ]; then
+ error "${item}_type not set"
+ delayed_exit=1
+ continue
+ fi
+
+ if echo "$loaded_types" | grep -wq $type; then
+ :
+ elif [ -x $libdir/${type}.sh ]; then
+ . $libdir/${type}.sh || delayed_exit=1
+ loaded_types="$loaded_files
+$type"
+ else
+ error "$libdir/${type}.sh not found"
+ delayed_exit=1
+ fi
+
+ ${type}_check $item || delayed_exit=1
+ done
+
+ test -n "$delayed_exit" && abend 1 "aborting"
+
+ tar_suffix=${backup_suffix:-.tar}
+}
diff --git a/lib/backup/fs.sh b/lib/backup/fs.sh
new file mode 100755
index 0000000..3950e37
--- /dev/null
+++ b/lib/backup/fs.sh
@@ -0,0 +1,92 @@
+#! /bin/bash
+
+# initdb item
+# Initializes snapshot for the given basename.
+initdb() {
+ local filename
+
+ if [ -n "$dry_run" ]; then
+ logit "initializing snapshot for $1"
+ return
+ fi
+
+ if [ $level -eq 0 ]; then
+ filename=$backup_snapshot_dir/$1-$week-$round-$level.db
+ test -r $filename && rm $filename
+ else
+ if [ $level -eq 1 ]; then
+ filename=$backup_snapshot_dir/$1-$week-0-0.db
+ else
+ filename=$backup_snapshot_dir/$1-$week-$round-$((level - 1)).db
+ fi
+ if [ -r $filename ]; then
+ cp $filename $backup_snapshot_dir/$1-$week-$round-$level.db
+ else
+ abend 1 "previous snapshot file $filename not found; cannot backup at level $level"
+ exit 1
+ fi
+ fi
+}
+
+# fs_check item
+fs_check() {
+ local rc=0
+
+ eval root=\$${1}_dir
+ eval files=\$${1}_files
+
+ test -z "$root" && rc=1 && error "${1}_dir not set"
+ test -z "$files" && rc=1 && error "${1}_files not set"
+ return $rc
+}
+
+# fs_backup item
+fs_backup() {
+ local basename text root files
+
+ basename=$1-$week-$round-$level
+ eval text=\$${1}_text
+ eval root=\$${1}_dir
+ eval files=\$${1}_files
+
+ test -z "$root" && abend 1 "${1}_dir not set"
+ test -z "$files" && abend 1 "${1}_files not set"
+ test -z "$text" && text="$1"
+ initdb $1
+ logit "backing up $text ($basename.$tar_suffix)"
+ $dry_run tar $verbose $taroptions \
+ -c -f $backup_archive_dir/$basename.$tar_suffix \
+ --listed=$backup_snapshot_dir/$basename.db \
+ -C $root $files
+ tarcode $?
+}
+
+# fs_restore item
+fs_restore() {
+ local i text root files tarcommand
+
+ eval text=\$${1}_text
+ eval root=\$${1}_dir
+ eval files=\$${1}_files
+
+ test -z "$root" && abend 1 "${1}_dir not set"
+ test -z "$files" && abend 1 "${1}_files not set"
+ test -z "$text" && text="$1"
+
+ tarcommand="tar $verbose $taroptions -C $root --listed-incremental=/dev/null -f"
+
+ logit "restoring $text"
+ logit "restoring from level 0 backup"
+
+ $dry_run $tarcommand $backup_archive_dir/$1-$week-0-0.$tar_suffix
+ tarcode $?
+
+ for i in $(seq 1 $level)
+ do
+ logit "restoring from the $round/$i backup"
+ $dry_run $tarcommand $backup_archive_dir/$1-$week-$round-$i.tar.bz2
+ tarcode $?
+ done
+ logit "finished restoring $text"
+}
+
diff --git a/lib/backup/postgres.sh b/lib/backup/postgres.sh
new file mode 100755
index 0000000..953c467
--- /dev/null
+++ b/lib/backup/postgres.sh
@@ -0,0 +1,72 @@
+#! /bin/bash
+
+# postgres_check item
+postgres_check() {
+ eval database=\$${1}_database
+ test -z "$database" && error "${1}_database not set" && return 1
+ return 0
+}
+
+# postgres_backup item
+postgres_backup() {
+ local database
+
+ logit "backing up PostgreSQL $1"
+ eval database=\$${1}_database
+ test -z "$database" && abend 1 "${1}_database not set"
+ if [ -z "$dry_run" ]; then
+ su postgres -c "pg_dump $verbose $database" > $backup_snapshot_dir/$1-$week-$round-$level
+ else
+ echo "su postgres -c \"pg_dump $verbose $database\" > $backup_snapshot_dir/$1-$week-$round-$level"
+ fi
+
+ if [ $? -ne 0 ]; then
+ tarerror=$((tarerror + 1))
+ echo >&2 "`date`: failed"
+ else
+ echo "`date`: creating $1-$week-$round-$level.$tar_suffix"
+ $dry_run tar $verbose $taroptions \
+ -f $backup_archive_dir/$1-$week-$round-$level.$tar_suffix \
+ -C $backup_snapshot_dir $1-$week-$round-$level
+ tarcode $?
+ $dry_run rm $snapshotdir/dbdump-$week-$round-$level
+ fi
+}
+
+postgres_restore() {
+ local u database
+
+ eval database=\$${1}_database
+ logit "restoring PostgreSQL database $database"
+ u=$(umask)
+ trap "umask $u" 1 2 3 13 15
+ umask 077
+ $dry_run tar $verbose $taroptions \
+ -f $backup_archive_dir/$1-$week-$round-$level.$tar_suffix
+ e=$?
+ tarcode $e
+ if [ $e -eq 0 ]; then
+ logit "restoring database from the dump"
+ if [ -n "$dry_run" ]; then
+ cat <<-EOT
+ su postgres -c "dropdb $database"
+ su postgres -c "createdb $database"
+ su postgres -c "psql -d $database -f $1-$week-$round-$level"
+ rm $1-$week-$round-$level
+EOT
+ elif [ -r $1-$week-$round-$level ]; then
+ su postgres -c "dropdb $database"
+ su postgres -c "createdb $database"
+ su postgres -c "psql -d $database -f $1-$week-$round-$level" > db-$1.log
+ if grep ERROR db-$1.log >/dev/null; then
+ error "errors occurred during restore; see db-$1.log for details"
+ error "dump preserved in file $1-$week-$round-$level"
+ tarerror=$((tarerror + 1))
+ else
+ rm $1-$week-$round-$level
+ fi
+ fi
+ fi
+ umask $u
+ trap - 1 2 3 13 15
+}
diff --git a/restore.in b/restore.in
new file mode 100644
index 0000000..c112cb6
--- /dev/null
+++ b/restore.in
@@ -0,0 +1,167 @@
+#! /bin/bash
+
+libdir=@LIBDIR@/backup
+set -e
+. $libdir/common.sh
+set +e
+
+load_config
+taroptions="$backup_tar_options $backup_rsh_command"
+
+# Options
+root=/
+verbose=
+logfile=
+dry_run=
+listonly=
+confirm=1
+
+guess_round() {
+ case $1 in
+ Sun|Mon|Tue)
+ round=0;;
+ Wed|Thu)
+ round=1;;
+ Fri|Sat)
+ round=2;;
+ *)
+ echo >&2 "$0: invalid day of week ($1)"
+ exit 1
+ esac
+}
+
+guess_level() {
+ case $1 in
+ Sun)
+ level=0;;
+ Mon|Wed|Fri)
+ level=1;;
+ Tue|Thu|Sat)
+ level=2;;
+ *)
+ echo >&2 "$0: invalid day of week ($1)"
+ exit 1
+ esac
+}
+
+getyn() {
+ echo -n "$0:" $* " [Y/n]? "
+ read
+ case $REPLY in
+ ''|y*|Y*) REPLY=y;;
+ *) REPLY=n;;
+ esac
+}
+
+help() {
+ cat <<EOT
+usage: restore [OPTIONS] [ITEM [ITEM...]]
+restores this system from a backup
+
+OPTIONS:
+ -c, --confirm do not ask for confirmation; run straight into restoring
+ -C, --directory DIR restore into directory DIR instead of $root
+ -v, --verbose increase verbosity
+ -n, --dry-run do nothing, print what would have been done
+ -t, --list list archives, instead of extracting
+ -l, --logfile FILE log to FILE
+ -L, --level N set incremental dump level to stop at
+ -R, --round N use archives from incremental round N
+ -W, --week N use archives from week N
+ -h, --help produce this help list
+
+Valid ITEMs are: $backup_items
+EOT
+ exit 0
+}
+
+while [ $# -ne 0 ]
+do
+ case $1 in
+ -C|--directory) shift; root=$1;;
+ -c|--confirm) confirm=0;;
+ -v|--verbose) verbose="$verbose -v";;
+ -t|--list) listonly=1;;
+ -l|--logfile) shift; logfile=$1; confirm=0;;
+ -n|--dry-run) dry_run=echo;;
+ -h|--help) help;;
+ -L|--level) shift; level=$1;;
+ -R|--round) shift; round=$1;;
+ -W|--week) shift; week=$1;;
+ --) shift; break;;
+ -*) echo >&2 "$0: unrecognized option $1"; exit 1;;
+ *) break;;
+ esac
+ shift
+done
+
+if [ -z "$listonly" ]; then
+ taroptions="$taroptions -x"
+else
+ taroptions="$taroptions -t"
+fi
+
+# Collect items to be restored.
+items=$*
+
+test -z "$items" && items="$backup_items"
+
+if [ -n "$logfile" ]; then
+ confirm=0
+ exec >>$logfile
+ exec 2>&1
+fi
+
+# Verify option consistency, guess missing values
+hour=$(date +%H)
+if [ $hour -gt 6 ]; then
+ thisweek=$(date +%U)
+ yestreen=$(date +%a)
+else
+ thisweek=$(date -d yesterday +%U)
+ yestreen=$(date -d yesterday +%a)
+fi
+
+if [ -z "$week" ]; then
+ week=$thisweek
+fi
+if [ -z "$round" ]; then
+ if [ $week = $thisweek ]; then
+ guess_round $yestreen
+ else
+ round=2
+ fi
+fi
+if [ -z "$level" ]; then
+ if [ $week = $thisweek ]; then
+ guess_level $yestreen
+ else
+ # FIXME: A better guess?
+ level=2
+ fi
+fi
+
+echo "$0: target root directory $root"
+echo "$0: items to be restored: $items"
+echo "$0: restoring from week $week, round $round, level $level"
+
+if [ $confirm -ne 0 ]; then
+ getyn "Do you wish to proceed"
+ test $REPLY = "n" && exit 0
+fi
+
+$prologue_hook
+
+logit "started"
+
+for item in $items
+do
+ eval type=\$${item}_type
+ ${type}_restore $item
+done
+
+$epilogue_hook
+
+logit "finished"
+
+

Return to:

Send suggestions and report system problems to the System administrator.