Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixes for bug #82, BM_TARBALL_TARGETS[] replaces BM_TARBALL_DIRECTORIES
git-svn-id: svn://svn.backup-manager.org/backup-manager/trunk@412 2e458433-d701-0410-9826-f9b593394a3c
  • Loading branch information
sukria committed May 3, 2006
1 parent 3048551 commit 8666282
Show file tree
Hide file tree
Showing 33 changed files with 2,760 additions and 1,956 deletions.
16 changes: 12 additions & 4 deletions backup-manager.conf.tpl
Expand Up @@ -32,7 +32,8 @@ export BM_REPOSITORY_CHMOD="770"
# Archives - let's focus on the precious tarballs...
##############################################################

# Each archive generated will be chmoded for security reasons.
# Each archive generated will be chmoded for security reasons
# (BM_REPOSITORY_SECURE should be enabled for this).
export BM_ARCHIVE_CHMOD="660"

# Number of days we have to keep an archive (Time To Live)
Expand Down Expand Up @@ -76,16 +77,23 @@ export BM_TARBALL_FILETYPE="tar.gz"
# (BM_UPLOAD_SSH_HOSTS, BM_UPLOAD_SSH_USER, BM_UPLOAD_SSH_KEY).
# If this boolean is set to true, archive will be saved locally (in
# BM_REPOSITORY_ROOT but will be built by the remote host).
# Thus, BM_TARBALL_DIRECTORIES will be used for backip up remote directories.
# Thus, BM_TARBALL_DIRECTORIES will be used for backup remote directories.
# Those archive will be prefixed with the remote host name.
export BM_TARBALL_OVER_SSH="true"

# Do you want to dereference the files pointed by symlinks ?
# enter true or false (true can lead to huge archives, be careful).
export BM_TARBALL_DUMPSYMLINKS="false"

# Directories you want to backup as tarballs (separated by spaces)
export BM_TARBALL_DIRECTORIES="/etc /home"
# Directories you want to backup as tarballs.
# This is an array, take care to increment the index for
# each item.
declare -a BM_TARBALL_TARGETS

BM_TARBALL_TARGETS[0]="/etc"
BM_TARBALL_TARGETS[1]="/boot"

export BM_TARBALL_TARGETS

# Files to exclude when generating tarballs, you can put absolute
# or relative paths, Bash wildcards are possible.
Expand Down
37 changes: 34 additions & 3 deletions doc/user-guide.sgml
Expand Up @@ -413,11 +413,18 @@ In most of the cases, you should not use this feature.
<sect2 id="BM_TARBALL_DIRECTORIES"><tt>BM_TARBALL_DIRECTORIES</tt>

<p>
<em>Type: space-separated list, default: <tt>""</tt>.</em>
<em><strong>Deprecated</strong> - Type: space-separated list, default: <tt>null</tt>.</em>

<p>
You certainly want to backup something, don't you? So here is the place where
you put that precious list of locations.
Since version 0.7.3, this variable is still supported for backward compatibility.

<p>
If you want to backup some targets that have spaces in their name (eg
"Program Files"), you must not use this variable, but should use the array
BM_TARBALL_TARGETS[] instead.

<p>
For this reason this variable is deprecated, use BM_TARBALL_TARGETS instead.

<p>
Example:
Expand All @@ -426,6 +433,30 @@ Example:
export BM_TARBALL_DIRECTORIES="/etc /home /var/log/apache"
</example>

<sect2 id="BM_TARBALL_TARGETS"><tt>BM_TARBALL_TARGETS</tt>

<p>
<em>Type: array, default: <tt>"/etc", "/boot"</tt>.</em>

<p>
This variable holds every place you want to backup. This is the recommanded
variable to use for defining your backup targets (<tt>BM_TARBALL_DIRECTORIES</tt> is
deprecated since version 0.7.3).

<p>
You can safely put items that contain spaces (eg: "Program Files") whereas you
can't with <tt>BM_TARBALL_DIRECTORIES</tt>.

<p>
Example

<example>
BM_TARBALL_TARGETS[0]="/etc"
BM_TARBALL_TARGETS[1]="/home/*"
BM_TARBALL_TARGETS[2]="/boot"
BM_TARBALL_TARGETS[3]="/mnt/win/Program Files"
</example>

<sect2 id="BM_TARBALL_BLACKLIST"><tt>BM_TARBALL_BLACKLIST</tt>

<p>
Expand Down
44 changes: 38 additions & 6 deletions doc/user-guide.txt
Expand Up @@ -183,11 +183,17 @@ Contents
to `yes', then update `BM_REPOSITORY_USER' and `BM_REPOSITORY_GROUP'
to your needs.

You can also change the permission of the repository and the archives,
that is possible with two configuration variables:
`BM_REPOSITORY_CHMOD' and `BM_ARCHIVE_CHMOD'.

Example:

export BM_REPOSITORY_SECURE="true"
export BM_REPOSITORY_USER="root"
export BM_REPOSITORY_GROUP="root"
export BM_REPOSITORY_CHMOD="770"
export BM_ARCHIVE_CHMOD="660"

2.1.2. Archives
---------------
Expand Down Expand Up @@ -390,16 +396,42 @@ Contents
2.2.1.7. `BM_TARBALL_DIRECTORIES'
---------------------------------

_Type: space-separated list, default: `""'._
__Deprecated_ - Type: space-separated list, default: `null'._

Since version 0.7.3, this variable is still supported for backward
compatibility.

If you want to backup some targets that have spaces in their name (eg
"Program Files"), you must not use this variable, but should use the
array BM_TARBALL_TARGETS[] instead.

You certainly want to backup something, don't you? So here is the
place where you put that precious list of locations.
For this reason this variable is deprecated, use BM_TARBALL_TARGETS
instead.

Example:

export BM_TARBALL_DIRECTORIES="/etc /home /var/log/apache"

2.2.1.8. `BM_TARBALL_BLACKLIST'
2.2.1.8. `BM_TARBALL_TARGETS'
-----------------------------

_Type: array, default: `"/etc", "/boot"'._

This variable holds every place you want to backup. This is the
recommanded variable to use for defining your backup targets
(`BM_TARBALL_DIRECTORIES' is deprecated since version 0.7.3).

You can safely put items that contain spaces (eg: "Program Files")
whereas you can't with `BM_TARBALL_DIRECTORIES'.

Example

BM_TARBALL_TARGETS[0]="/etc"
BM_TARBALL_TARGETS[1]="/home/*"
BM_TARBALL_TARGETS[2]="/boot"
BM_TARBALL_TARGETS[3]="/mnt/win/Program Files"

2.2.1.9. `BM_TARBALL_BLACKLIST'
-------------------------------

_Type: space-separated list, default: `"/proc /dev /sys /tmp"'._
Expand All @@ -417,8 +449,8 @@ Contents

export BM_TARBALL_BLACKLIST="/tmp /dev /proc *.mp3 *.mpg"

2.2.1.9. `BM_TARBALL_OVER_SSH'
------------------------------
2.2.1.10. `BM_TARBALL_OVER_SSH'
-------------------------------

_Type: boolean, default: `false'._

Expand Down
39 changes: 23 additions & 16 deletions lib/backup-methods.sh
Expand Up @@ -73,7 +73,7 @@ function handle_tarball_error()
target="$1"
logfile="$2"

warning "Unable to create \$target, check \$logfile"
warning "Unable to create \"\$target\", check \$logfile"
nb_err=$(($nb_err + 1))
}

Expand Down Expand Up @@ -239,7 +239,7 @@ function __get_flags_tar_dump_symlinks()
function __get_file_to_create()
{
target="$1"
dir_name=$(get_dir_name $target $BM_TARBALL_NAMEFORMAT)
dir_name=$(get_dir_name "$target" $BM_TARBALL_NAMEFORMAT)
file_to_create="$BM_REPOSITORY_ROOT/$BM_ARCHIVE_PREFIX$dir_name.$TODAY${master}.$BM_TARBALL_FILETYPE"

# dar appends itself the ".dar" extension
Expand All @@ -254,7 +254,7 @@ function __get_file_to_create_remote()
target="$1"
host="$2"

dir_name=$(get_dir_name $target $BM_TARBALL_NAMEFORMAT)
dir_name=$(get_dir_name "$target" $BM_TARBALL_NAMEFORMAT)
file_to_create="$BM_REPOSITORY_ROOT/${host}${dir_name}.$TODAY${master}.$BM_TARBALL_FILETYPE"

echo "$file_to_create"
Expand Down Expand Up @@ -391,26 +391,26 @@ function __get_backup_tarball_command()
case $BM_TARBALL_FILETYPE in
tar)
__get_flags_tar_blacklist "$target"
command="$tar $incremental $blacklist $dumpsymlinks $BM_TARBALL_EXTRA_OPTIONS -p -c -f "$file_to_create" "$target""
command="$tar $incremental $blacklist $dumpsymlinks $BM_TARBALL_EXTRA_OPTIONS -p -c -f $file_to_create"
;;
tar.gz)
__get_flags_tar_blacklist "$target"
command="$tar $incremental $blacklist $dumpsymlinks $BM_TARBALL_EXTRA_OPTIONS -p -c -z -v -f "$file_to_create" "$target""
command="$tar $incremental $blacklist $dumpsymlinks $BM_TARBALL_EXTRA_OPTIONS -p -c -z -v -f $file_to_create"
;;
tar.bz2|tar.bz)
__get_flags_tar_blacklist "$target"
command="$tar $incremental $blacklist $dumpsymlinks $BM_TARBALL_EXTRA_OPTIONS -p -c -j -f "$file_to_create" "$target""
command="$tar $incremental $blacklist $dumpsymlinks $BM_TARBALL_EXTRA_OPTIONS -p -c -j -f $file_to_create"
;;
zip)
command="$zip $dumpsymlinks $BM_TARBALL_EXTRA_OPTIONS -r "$file_to_create" "$target""
command="$zip $dumpsymlinks $BM_TARBALL_EXTRA_OPTIONS -r $file_to_create"
;;
dar)
__get_flags_dar_blacklist "$target"
command="$dar $incremental $blacklist $maxsize $overwrite $BM_TARBALL_EXTRA_OPTIONS -z9 -Q -c "$file_to_create" -R "$target""
command="$dar $incremental $blacklist $maxsize $overwrite $BM_TARBALL_EXTRA_OPTIONS -z9 -Q -c $file_to_create -R"
;;
7z)
__get_flags_7z_blacklist "$target"
command="$_7z a -t7z -m0=lzma -mx=9 $blacklist $dumpsymlinks $BM_TARBALL_EXTRA_OPTIONS "$file_to_create" "$target""
command="$_7z a -t7z -m0=lzma -mx=9 $blacklist $dumpsymlinks $BM_TARBALL_EXTRA_OPTIONS $file_to_create"
;;
*)
error "The archive type \"\$BM_TARBALL_FILETYPE\" is not supported."
Expand All @@ -427,7 +427,8 @@ function __build_local_archive()
dir_name="$2"

file_to_create=$(__get_file_to_create "$target")
command=$(__get_backup_tarball_command) ||

command="$(__get_backup_tarball_command)" ||
error "The archive type \"\$BM_TARBALL_FILETYPE\" is not supported."

# dar is not like tar, we have to manually check for existing .1.dar files
Expand All @@ -441,7 +442,7 @@ function __build_local_archive()
if [ ! -e $file_to_check ] || [ $force = true ]; then
logfile=$(mktemp /tmp/bm-tarball.log.XXXXXX)
# __debug "$command"
if ! $command > $logfile 2>&1 ; then
if ! `$command "$target"> $logfile 2>&1`; then
handle_tarball_error "$file_to_create" "$logfile"
else
rm -f $logfile
Expand Down Expand Up @@ -495,11 +496,17 @@ function __build_remote_archive()
function __make_tarball_archives()
{
nb_err=0
for target in $BM_TARBALL_DIRECTORIES
do
# BM_TARBALL_DIRECTORIES=$(echo "$BM_TARBALL_DIRECTORIES" | sed -e 's/"\(.*\)"//g')
# for target in $BM_TARBALL_DIRECTORIES
for target in ${BM_TARBALL_TARGETS[*]}
do
if [ -z "$target" ]; then
continue
fi

# first be sure the target exists
if [ ! -e $target ] || [ ! -r $target ]; then
warning "Target \$target does not exist, skipping."
if [ ! -e "$target" ] || [ ! -r "$target" ]; then
warning "Target \"\$target\" does not exist, skipping."
nb_err=$(($nb_err + 1))
continue
fi
Expand All @@ -518,7 +525,7 @@ function __make_tarball_archives()
then
case "$BM_TARBALL_FILETYPE" in
"dar")
__get_flags_dar_incremental $dir_name
__get_flags_dar_incremental "$dir_name"
;;
"tar"|"tar.gz"|"tar.bz2")
__get_flags_tar_incremental "$dir_name"
Expand Down
12 changes: 9 additions & 3 deletions lib/files.sh
Expand Up @@ -39,10 +39,12 @@ get_dir_name()
if [ "$format" = "long" ]
then
# first remove the trailing slash
base=$(echo $base | sed -e 's|/$||')
base=${base%/}

# then substitue every / by a -
dirname=`echo "$base" | sed 's/\//-/g'`
# every space by a _
dirname=$(echo "$base" | sed 's/\s/_/g')
# every / by a -
dirname=$(echo "$dirname" | sed 's/\//-/g')

elif [ "$format" = "short" ]
then
Expand Down Expand Up @@ -365,6 +367,10 @@ purge_duplicate_archives()
# we'll parse all the files of the same source
date_of_file=$(get_date_from_file $file_to_create) ||
error "Unable to get date from file."
if [ -z "$date_of_file" ]; then
error "Unable to get date from file."
fi

file_pattern=$(echo $file_to_create | sed -e "s/$date_of_file/\*/") ||
error "Unable to find the pattern of the file."

Expand Down
29 changes: 21 additions & 8 deletions lib/sanitize.sh
Expand Up @@ -146,18 +146,31 @@ fi

if [ "$BM_ARCHIVE_METHOD" = "tarball" ] ||
[ "$BM_ARCHIVE_METHOD" = "tarball-incremental" ] ; then

confkey_handle_deprecated "BM_FILETYPE" "BM_TARBALL_FILETYPE"
confkey_require "BM_TARBALL_FILETYPE" "tar.gz"

confkey_handle_deprecated "BM_NAME_FORMAT" "BM_TARBALL_NAMEFORMAT"
confkey_require "BM_TARBALL_NAMEFORMAT" "long"

confkey_handle_deprecated "BM_DUMP_SYMLINKS" "BM_TARBALL_DUMPSYMLINKS"
confkey_require "BM_TARBALL_DUMPSYMLINKS" "false"
fi

confkey_handle_deprecated "BM_FILETYPE" "BM_TARBALL_FILETYPE"
confkey_handle_deprecated "BM_NAME_FORMAT" "BM_TARBALL_NAMEFORMAT"
confkey_handle_deprecated "BM_DIRECTORIES_BLACKLIST" "BM_TARBALL_BLACKLIST"
confkey_handle_deprecated "BM_DUMP_SYMLINKS" "BM_TARBALL_DUMPSYMLINKS"

confkey_handle_deprecated "BM_DIRECTORIES" "BM_TARBALL_DIRECTORIES"
confkey_handle_deprecated "BM_DIRECTORIES_BLACKLIST" "BM_TARBALL_BLACKLIST"
# We handle there the case of BM_TARBALL_DIRECTORIES which is now replaced
# by an array in order to support paths with spaces in their name
# see bug #86 for details.
if [ -n "$BM_DIRECTORIES" ]; then
BM_TARBALL_DIRECTORIES="$BM_DIRECTORIES"
fi
if [ -n "$BM_TARBALL_DIRECTORIES" ]; then
declare -a BM_TARBALL_TARGETS
index=0
for target in $BM_TARBALL_DIRECTORIES
do
# __debug "$index : $target"
BM_TARBALL_TARGETS[$index]="$target"
index=$(($index + 1))
done
fi

if [ "$BM_UPLOAD_METHOD" = "rsync" ]; then
Expand Down

0 comments on commit 8666282

Please sign in to comment.