2005-12-28 21:19:29 +01:00
# -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
2009-05-22 15:27:09 +02:00
# vim: set filetype=sh sw=3 sts=3 expandtab autoindent:
2005-12-28 21:19:29 +01:00
2005-11-29 11:08:41 +01:00
HELPERS="$HELPERS dup:incremental_encrypted_remote_filesystem_backup"
### Functions
do_dup_host_includes() {
set -o noglob
# choose the files to backup
REPLY=
while [ -z "$REPLY" ]; do
formBegin "$dup_title - host system: includes"
2005-11-29 11:11:25 +01:00
[ -z "$dup_includes" ] && dup_includes="$dup_default_includes"
for i in $dup_includes; do
2005-11-29 11:11:14 +01:00
formItem include "$i"
2009-05-22 14:50:52 +02:00
done
formItem include ""
formItem include ""
formItem include ""
2010-01-19 00:01:18 +01:00
formItem include ""
formItem include ""
formItem include ""
formItem include ""
formItem include ""
2009-05-22 14:50:52 +02:00
formDisplay
2005-11-29 11:08:41 +01:00
[ $? = 0 ] || return 1
2005-11-29 11:11:14 +01:00
dup_includes="$REPLY"
2005-11-29 11:08:41 +01:00
done
set +o noglob
}
do_dup_vserver() {
2005-11-29 11:10:53 +01:00
# choose the vservers to backup (into $selected_vservers)
choose_one_or_more_vservers "$dup_title"
2005-11-29 11:08:41 +01:00
[ $? = 0 ] || return 1
set -o noglob
# choose the files to backup
REPLY=
while [ -z "$REPLY" ]; do
2006-01-19 22:57:37 +01:00
formBegin "$dup_title - vservers: vsincludes (backup these directories from every selected vserver)"
2005-11-29 11:11:25 +01:00
[ -z "$dup_vsincludes" ] && dup_vsincludes="$dup_default_includes"
for i in $dup_vsincludes; do
2005-11-29 11:11:14 +01:00
formItem include "$i"
2009-05-22 14:50:52 +02:00
done
formItem include ""
formItem include ""
formItem include ""
2010-01-19 00:01:18 +01:00
formItem include ""
formItem include ""
formItem include ""
formItem include ""
formItem include ""
2005-11-29 11:08:41 +01:00
formDisplay
[ $? = 0 ] || return 1
2005-11-29 11:11:14 +01:00
dup_vsincludes="$REPLY"
2005-11-29 11:08:41 +01:00
done
set +o noglob
}
do_dup_excludes() {
set -o noglob
formBegin "$dup_title: excludes"
2005-11-29 11:11:25 +01:00
[ -z "$dup_excludes" ] && dup_excludes="$dup_default_excludes"
for i in $dup_excludes; do
2005-11-29 11:11:14 +01:00
formItem exclude "$i"
2005-11-29 11:08:41 +01:00
done
formItem exclude ""
formItem exclude ""
formItem exclude ""
2010-01-19 00:01:18 +01:00
formItem exclude ""
formItem exclude ""
formItem exclude ""
formItem exclude ""
formItem exclude ""
2005-11-29 11:08:41 +01:00
formDisplay
[ $? = 0 ] || return 1
2005-11-29 11:11:14 +01:00
dup_excludes="$REPLY"
2005-11-29 11:08:41 +01:00
set +o noglob
}
do_dup_src() {
2005-11-29 11:10:53 +01:00
choose_host_or_vservers_or_both "$dup_title"
2005-11-29 11:08:41 +01:00
[ $? = 0 ] || return 1
case $host_or_vservers in
'host')
2009-05-22 14:50:52 +02:00
do_dup_host_includes
[ $? = 0 ] || return 1
;;
2005-11-29 11:08:41 +01:00
'vservers')
2009-05-22 14:50:52 +02:00
do_dup_vserver
[ $? = 0 ] || return 1
;;
2005-11-29 11:08:41 +01:00
'both')
2009-05-22 14:50:52 +02:00
do_dup_host_includes
[ $? = 0 ] || return 1
do_dup_vserver
[ $? = 0 ] || return 1
;;
2005-11-29 11:08:41 +01:00
*)
2009-05-22 14:50:52 +02:00
return 1
;;
2005-11-29 11:08:41 +01:00
esac
do_dup_excludes
[ $? = 0 ] || return 1
2009-05-22 14:50:52 +02:00
2005-11-29 11:08:41 +01:00
_src_done="(DONE)"
setDefault dest
}
do_dup_dest() {
local replyconverted
local thereply
set -o noglob
REPLY=
while [ -z "$REPLY" -o -z "$dup_destdir" -o -z "$dup_desthost" -o -z "$dup_destuser" ]; do
2005-12-27 23:12:43 +01:00
formBegin "$dup_title - destination: first three items are compulsory"
2009-05-22 14:50:52 +02:00
formItem "desthost" "$dup_desthost"
formItem "destuser" "$dup_destuser"
formItem "destdir" "$dup_destdir"
formItem "keep" "$dup_keep"
2005-11-29 11:08:41 +01:00
formItem "incremental" "$dup_incremental"
2010-05-02 17:40:50 +02:00
formItem "increments" "$dup_increments"
2010-11-21 10:07:36 +01:00
formItem "keepincroffulls" "$dup_keepincroffulls"
2009-05-22 14:50:52 +02:00
formItem "bandwidthlimit" "$dup_bandwidth"
formItem "sshoptions" "$dup_sshoptions"
2005-11-29 11:08:41 +01:00
formDisplay
[ $? = 0 ] || return 1
IFS=$''
replyconverted=`echo $REPLY | tr '\n' :`
IFS=$':'
thereply=($replyconverted)
IFS=$' \t\n'
2009-05-22 14:50:52 +02:00
2005-11-29 11:08:41 +01:00
dup_desthost=${thereply[0]}
dup_destuser=${thereply[1]}
dup_destdir=${thereply[2]}
dup_keep=${thereply[3]}
dup_incremental=${thereply[4]}
2010-05-02 17:40:50 +02:00
dup_increments=${thereply[5]}
2010-11-21 10:07:36 +01:00
dup_keepincroffulls=${thereply[6]}
dup_bandwidth=${thereply[7]}
dup_sshoptions=${thereply[8]}
2005-11-29 11:08:41 +01:00
done
set +o noglob
_dest_done="(DONE)"
setDefault gpg
}
2005-12-28 20:13:10 +01:00
do_dup_gpg_encryptkey() {
2005-11-29 11:08:41 +01:00
REPLY=
while [ -z "$REPLY" -o -z "$dup_gpg_encryptkey" ]; do
2005-12-28 20:13:10 +01:00
inputBox "$dup_title - GnuPG" "Enter ID of the public GnuPG key to be used to encrypt the backups:" "$dup_gpg_encryptkey"
2005-11-29 11:08:41 +01:00
[ $? = 0 ] || return 1
dup_gpg_encryptkey="$REPLY"
done
2005-12-28 20:13:10 +01:00
}
do_dup_gpg_sign() {
# sign ?
booleanBox "$dup_title - GnuPG" "Sign the backups?" "$dup_gpg_sign"
if [ $? = 0 ]; then
dup_gpg_sign=yes
else
dup_gpg_sign=no
fi
}
do_dup_gpg_signkey() {
# one key pair ?
booleanBox "$dup_title - GnuPG" "Use the same GnuPG key pair for encryption and signing?" "$dup_gpg_onekeypair"
if [ $? = 0 ]; then
dup_gpg_onekeypair=yes
else
dup_gpg_onekeypair=no
fi
2005-11-29 11:08:41 +01:00
2010-12-13 11:24:21 +01:00
if [ "$dup_gpg_onekeypair" == "no" ]; then
2005-12-28 20:13:10 +01:00
# signkey ?
REPLY=
while [ -z "$REPLY" -o -z "$dup_gpg_signkey" ]; do
2009-05-22 14:50:52 +02:00
inputBox "$dup_title - GnuPG" "Enter the ID of the private GnuPG key to be used to sign the backups:" "$dup_gpg_signkey"
[ $? = 0 ] || return 1
dup_gpg_signkey="$REPLY"
2005-12-28 20:13:10 +01:00
done
fi
}
do_dup_gpg_passphrase() {
2006-05-30 05:40:34 +02:00
local question="Enter the passphrase needed to unlock the GnuPG key:"
2005-11-29 11:08:41 +01:00
REPLY=
while [ -z "$REPLY" -o -z "$dup_gpg_password" ]; do
2005-12-28 20:13:10 +01:00
passwordBox "$dup_title - GnuPG" "$question"
2005-11-29 11:08:41 +01:00
[ $? = 0 ] || return 1
dup_gpg_password="$REPLY"
done
2005-12-28 20:13:10 +01:00
}
2005-11-29 11:08:41 +01:00
2005-12-28 20:13:10 +01:00
do_dup_gpg() {
2009-05-22 14:50:52 +02:00
2005-12-28 20:13:10 +01:00
# symmetric or public key encryption ?
2006-04-22 23:22:24 +02:00
booleanBox "$dup_title - GnuPG" "Use public key encryption? Otherwise, symmetric encryption will be used, and data signing will be impossible." "$dup_gpg_asymmetric_encryption"
2005-11-29 11:08:41 +01:00
if [ $? = 0 ]; then
2005-12-28 20:13:10 +01:00
dup_gpg_asymmetric_encryption=yes
2005-11-29 11:08:41 +01:00
else
2005-12-28 20:13:10 +01:00
dup_gpg_asymmetric_encryption=no
fi
# when using public/private key pair encryption, ask for the keys to use
if [ "$dup_gpg_asymmetric_encryption" == yes ]; then
do_dup_gpg_encryptkey ; [ $? = 0 ] || return 1
do_dup_gpg_sign ; [ $? = 0 ] || return 1
if [ "$dup_gpg_sign" == yes ]; then
2009-05-22 14:50:52 +02:00
do_dup_gpg_signkey ; [ $? = 0 ] || return 1
2005-12-28 20:13:10 +01:00
fi
2006-10-07 02:40:58 +02:00
else
dup_gpg_sign=no
2005-12-28 20:13:10 +01:00
fi
2006-05-30 05:40:34 +02:00
# a passphrase is alway needed
do_dup_gpg_passphrase
2005-11-29 11:08:41 +01:00
_gpg_done="(DONE)"
2005-11-29 11:10:31 +01:00
setDefault adv
# TODO: replace the above line by the following when do_dup_conn is written
# setDefault conn
2005-11-29 11:08:41 +01:00
}
2005-11-29 11:10:31 +01:00
# TODO: share rdiff.helper code in some lib, and use it here
2005-11-29 11:08:41 +01:00
do_dup_conn() {
_con_done="(DONE)"
setDefault adv
}
do_dup_misc_options() {
set -o noglob
local replyconverted
local thereply
formBegin "$dup_title - misc. options"
formItem "nicelevel" "$dup_nicelevel"
formItem "testconnect" "$dup_testconnect"
formItem "options" "$dup_options"
formDisplay
[ $? = 0 ] || return 1
IFS=$''
replyconverted=`echo $REPLY | tr '\n' :`
IFS=$':'
thereply=($replyconverted)
IFS=$' \t\n'
dup_nicelevel=${thereply[0]}
dup_testconnect=${thereply[1]}
dup_options=${thereply[2]}
set +o noglob
}
# (rdiff.helper compatible interface... there could be some sode to share, hmmm.)
do_dup_adv() {
do_dup_misc_options
[ $? = 0 ] || return 1
_adv_done="(DONE)"
setDefault finish
}
do_dup_finish() {
get_next_filename $configdirectory/90.dup
cat > $next_filename <<EOF
# passed directly to duplicity
#options = --verbosity 8
options = $dup_options
# default is 0, but set to 19 if you want to lower the priority.
nicelevel = $dup_nicelevel
2010-05-06 19:47:54 +02:00
# default is yes. set to no to skip the test if the remote host is alive.
# if 'desturl' is set below, 'testconnect' must be set to 'no' for now.
2005-11-29 11:08:41 +01:00
testconnect = $dup_testconnect
######################################################
## gpg section
2006-04-23 00:02:43 +02:00
## (how to encrypt and optionally sign the backups)
2005-12-28 20:13:10 +01:00
##
2006-05-30 05:40:34 +02:00
## WARNING: old (pre-0.9.4) example.dup used to give wrong information about
2006-04-22 23:41:39 +02:00
## the way the following options are used. Please read the following
2005-12-28 20:13:10 +01:00
## carefully.
##
## If the encryptkey variable is set:
## - data is encrypted with the GnuPG public key specified by the encryptkey
## variable
2006-05-30 05:40:34 +02:00
## - if signing is enabled, data is signed with the GnuPG private
## key specified by the signkey variable
## - the password variable is used to unlock the GnuPG key(s) used
## for encryption and (optionnal) signing
##
2005-12-28 20:13:10 +01:00
## If the encryptkey option is not set:
## - data signing is not possible
## - the password variable is used to encrypt the data with symmetric
## encryption: no GnuPG key pair is needed
2005-11-29 11:08:41 +01:00
[gpg]
2006-04-22 23:41:39 +02:00
# when set to yes, encryptkey variable must be set below; if you want to use
2005-12-28 20:13:10 +01:00
# two different keys for encryption and signing, you must also set the signkey
2006-04-22 23:41:39 +02:00
# variable below.
# default is no, for backwards compatibility with backupninja <= 0.5.
2005-11-29 11:08:41 +01:00
sign = $dup_gpg_sign
2005-12-28 20:13:10 +01:00
# ID of the GnuPG public key used for data encryption.
# if not set, symmetric encryption is used, and data signing is not possible.
2005-11-29 11:08:41 +01:00
encryptkey = $dup_gpg_encryptkey
2005-12-28 20:13:10 +01:00
# ID of the GnuPG private key used for data signing.
# if not set, encryptkey will be used.
signkey = $dup_gpg_signkey
# password
2006-04-22 23:41:39 +02:00
# NB: neither quote this, nor should it include any quotes
2005-12-28 20:13:10 +01:00
password = $dup_gpg_password
2005-11-29 11:08:41 +01:00
######################################################
## source section
## (where the files to be backed up are coming from)
[source]
2006-10-07 02:40:58 +02:00
# A few notes about includes and excludes:
# 1. include, exclude and vsinclude statements support globbing with '*'
# 2. Symlinks are not dereferenced. Moreover, an include line whose path
# contains, at any level, a symlink to a directory, will only have the
# symlink backed-up, not the target directory's content. Yes, you have to
# dereference yourself the symlinks, or to use 'mount --bind' instead.
# Example: let's say /home is a symlink to /mnt/crypt/home ; the following
# line will only backup a "/home" symlink ; neither /home/user nor
# /home/user/Mail will be backed-up :
# include = /home/user/Mail
# A workaround is to 'mount --bind /mnt/crypt/home /home' ; another one is to
# write :
# include = /mnt/crypt/home/user/Mail
# 3. All the excludes come after all the includes. The order is not otherwise
# taken into account.
2006-06-04 02:30:03 +02:00
2005-11-29 11:08:41 +01:00
# files to include in the backup
EOF
2005-11-29 11:10:53 +01:00
if [ "$host_or_vservers" == host -o "$host_or_vservers" == both ]; then
2005-11-29 11:08:41 +01:00
set -o noglob
2005-11-29 11:11:14 +01:00
for i in $dup_includes; do
2009-05-22 14:50:52 +02:00
echo "include = $i" >> $next_filename
2005-11-29 11:08:41 +01:00
done
set +o noglob
fi
cat >> $next_filename <<EOF
# If vservers = yes in /etc/backupninja.conf then the following variables can
# be used:
# vsnames = all | <vserver1> <vserver2> ... (default = all)
# vsinclude = <path>
2006-01-19 22:57:37 +01:00
# vsinclude = <path>
# ...
2005-11-29 11:08:41 +01:00
# Any path specified in vsinclude is added to the include list for each vserver
2006-01-19 22:58:38 +01:00
# listed in vsnames (or all if vsnames = all, which is the default).
2006-01-19 22:57:37 +01:00
#
# For example, vsinclude = /home will backup the /home directory in every
# vserver listed in vsnames. If you have 'vsnames = foo bar baz', this
# vsinclude will add to the include list /vservers/foo/home, /vservers/bar/home
# and /vservers/baz/home.
2005-11-29 11:08:41 +01:00
# Vservers paths are derived from $VROOTDIR.
EOF
2005-11-29 11:10:53 +01:00
if [ "$host_or_vservers" == vservers -o "$host_or_vservers" == both ]; then
2005-11-29 11:08:41 +01:00
set -o noglob
2006-01-17 23:22:07 +01:00
echo -e "vsnames = $selected_vservers\n" >> $next_filename
2005-11-29 11:11:14 +01:00
for i in $dup_vsincludes; do
echo "vsinclude = $i" >> $next_filename
2005-11-29 11:08:41 +01:00
done
set +o noglob
fi
# excludes
cat >> $next_filename <<EOF
# files to exclude from the backup
EOF
set -o noglob
2005-11-29 11:11:14 +01:00
for i in $dup_excludes; do
echo "exclude = $i" >> $next_filename
2005-11-29 11:08:41 +01:00
done
set +o noglob
cat >> $next_filename <<EOF
######################################################
## destination section
## (where the files are copied to)
[dest]
# perform an incremental backup? (default = yes)
# if incremental = no, perform a full backup in order to start a new backup set
incremental = $dup_incremental
2010-05-06 18:49:18 +02:00
# how many days of incremental backups before doing a full backup again ;
# default is 30 days (one can also use the time format of duplicity).
# if increments = keep, never automatically perform a new full backup ;
# only perform incremental backups.
2010-05-02 17:40:50 +02:00
#increments = 30
#increments = keep
increments = $dup_increments
2010-11-14 14:58:15 +01:00
# how many days of data to keep ; default is 1 year.
2005-11-29 11:08:41 +01:00
# (you can also use the time format of duplicity)
# 'keep = yes' means : do not delete old data, the remote host will take care of this
2010-11-14 14:58:15 +01:00
#keep = 1Y
2005-11-29 11:08:41 +01:00
#keep = yes
keep = $dup_keep
2010-11-14 14:20:55 +01:00
# for how many full backups do we keep their later increments ;
# default is 6.
# increments for older full backups will be deleted : only the more
# recent ones will be kept
#keepincrofulls = 6
keepincrofulls = $dup_keepincroffulls
2010-11-21 10:07:36 +01:00
# for how many full backups do we keep their later increments ;
# default is all (keep all increments).
# increments for older full backups will be deleted : only the more
# recent ones (count provided) will be kept
#keepincrofulls = all
#keepincrofulls = 6
keepincrofulls = $dup_keepincroffulls
2008-06-24 15:32:34 +02:00
# full destination URL, in duplicity format; if set, desturl overrides
2008-06-24 16:11:22 +02:00
# sshoptions, destdir, desthost and destuser; it also disables testconnect and
# bandwithlimit. For details, see duplicity manpage, section "URL FORMAT".
2008-06-24 15:32:34 +02:00
#desturl = file:///usr/local/backup
#desturl = rsync://user@other.host//var/backup/bla
2010-01-09 23:14:17 +01:00
#desturl = s3+http://your_bucket
2010-05-06 20:05:20 +02:00
#desturl = ftp://myftpuser@ftp.example.org/remote/ftp/path
2010-01-09 23:14:17 +01:00
# Amazon Web Services Access Key ID and Secret Access Key, needed for backups
# to S3 buckets.
#awsaccesskeyid = YOUR_AWS_ACCESS_KEY_ID
#awssecretaccesskey = YOUR_AWS_SECRET_KEY
2008-06-24 15:32:34 +02:00
2010-05-06 20:05:20 +02:00
# FTP password, needed for backups using desturl = ftp://...
#ftp_password =
2005-11-29 11:08:41 +01:00
# bandwith limit, in kbit/s ; default is 0, i.e. no limit
2010-05-06 19:47:54 +02:00
# if using 'desturl' above, 'bandwidthlimit' must not be set
2011-02-16 08:22:10 +01:00
# an example setting of 128 Kbit/s would be:
2005-11-29 11:08:41 +01:00
#bandwidthlimit = 128
bandwidthlimit = $dup_bandwidth
2006-10-07 03:23:21 +02:00
# passed directly to ssh, scp (and sftp in duplicity >=0.4.2)
# warning: sftp does not support all scp options, especially -i; as
# a workaround, you can use "-o <SSHOPTION>"
2011-01-27 19:02:05 +01:00
#sshoptions = -o IdentityFile=/root/.ssh/id_rsa_duplicity
2005-11-29 11:08:41 +01:00
sshoptions = $dup_sshoptions
2010-05-06 19:47:54 +02:00
# put the backups under this destination directory
# if using 'desturl' above, this must not be set
# in all other cases, this must be set!
2005-11-29 11:08:41 +01:00
destdir = $dup_destdir
# the machine which will receive the backups
2010-05-06 19:47:54 +02:00
# if using 'desturl' above, this must not be set
# in all other cases, this must be set!
2005-11-29 11:08:41 +01:00
desthost = $dup_desthost
# make the files owned by this user
2010-05-06 19:47:54 +02:00
# if using 'desturl' above, this must not be set
# note: if using an SSH based transport and 'type' is set to 'remote', you must
# be able to 'ssh backupuser@backuphost' without specifying a password.
2005-11-29 11:08:41 +01:00
destuser = $dup_destuser
EOF
chmod 600 $next_filename
}
dup_main_menu() {
2009-05-22 14:50:52 +02:00
while true; do
srcitem="choose files to include & exclude $_src_done"
destitem="configure backup destination $_dest_done"
gpgitem="configure GnuPG encryption/signing $_gpg_done"
conitem="set up ssh keys and test remote connection $_con_done"
advitem="edit advanced settings $_adv_done"
# TODO: add the following to the menu when do_dup_conn is written
# conn "$conitem" \
menuBox "$dup_title" "choose a step:" \
src "$srcitem" \
dest "$destitem" \
gpg "$gpgitem" \
adv "$advitem" \
finish "finish and create config file"
[ $? = 0 ] || return 1
result="$REPLY"
case "$result" in
"src") do_dup_src;;
"dest") do_dup_dest;;
"gpg") do_dup_gpg;;
# TODO: enable the following when do_dup_conn is written
# "conn") do_dup_conn;;
"adv") do_dup_adv;;
"finish")
if [[ "$_dest_done$_gpg_done$_src_done" != "(DONE)(DONE)(DONE)" ]]; then
# TODO: replace the previous test by the following when do_dup_conn is written
# if [[ "$_con_done$_dest_done$_gpg_done$_src_done" != "(DONE)(DONE)(DONE)(DONE)" ]]; then
msgBox "$dup_title" "You cannot create the configuration file until the four first steps are completed."
else
do_dup_finish
break
fi
;;
esac
done
2005-11-29 11:08:41 +01:00
}
### Main function
dup_wizard() {
2009-05-22 14:50:52 +02:00
2005-11-29 11:08:41 +01:00
require_packages duplicity
# Global variables
dup_title="Duplicity action wizard"
_src_done=
_dest_done=
_con_done=
_gpg_done=
_adv_done=
2005-11-29 11:11:25 +01:00
dup_includes=
dup_excludes=
dup_vsincludes=
2005-11-29 11:08:41 +01:00
dup_incremental=yes
2010-05-02 17:40:50 +02:00
dup_increments=30
2005-11-29 11:08:41 +01:00
dup_keep=60
dup_bandwidth=
dup_sshoptions=
dup_destdir="/backups/`hostname`"
dup_desthost=
dup_destuser=
2005-12-28 20:13:10 +01:00
dup_gpg_asymmetric_encryption="yes"
2005-11-29 11:08:41 +01:00
dup_gpg_encryptkey=""
2005-12-28 20:13:10 +01:00
dup_gpg_sign="yes"
dup_gpg_onekeypair="yes"
dup_gpg_signkey=""
2005-11-29 11:08:41 +01:00
dup_gpg_password=""
dup_nicelevel=19
dup_testconnect=yes
dup_options=
# Global variables whose '*' shall not be expanded
set -o noglob
2005-11-29 11:11:14 +01:00
dup_default_includes="/var/spool/cron/crontabs /var/backups /etc /root /home /usr/local/*bin /var/lib/dpkg/status*"
2010-05-10 22:18:49 +02:00
dup_default_excludes="/home/*/.gnupg /home/*/.local/share/Trash /home/*/.Trash /home/*/.thumbnails /home/*/.beagle /home/*/.aMule /home/*/gtk-gnutella-downloads /var/cache/backupninja/duplicity"
2005-11-29 11:08:41 +01:00
set +o noglob
dup_main_menu
}