Skip to content

Commit

Permalink
2006-12-29 Alexis Sukrieh <sukria@backup-manager.org>
Browse files Browse the repository at this point in the history
	* lib/sanitize.sh
	  + Make sure BM_ENCRYPTION_RECIPIENT is defined when BM_ENCRYPTION_METHOD
	  is set to gpg.
	* lib/backup-methods.sh
	  + Handle gently encryption when building meta commands.
	  (closes: #135)
	  + The code of the gzip and the bzip2 compressors have been merged.
	  Less code, less bugs Luke.




git-svn-id: svn://svn.backup-manager.org/backup-manager/trunk@526 2e458433-d701-0410-9826-f9b593394a3c
  • Loading branch information
sukria committed Dec 28, 2006
1 parent 8aebc12 commit 8fb9045
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 30 deletions.
12 changes: 12 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
2006-12-29 Alexis Sukrieh <sukria@backup-manager.org>

* lib/sanitize.sh
+ Make sure BM_ENCRYPTION_RECIPIENT is defined when BM_ENCRYPTION_METHOD
is set to gpg.
* lib/backup-methods.sh
+ Handle gently encryption when building meta commands.
(closes: #135)
+ The code of the gzip and the bzip2 compressors have been merged.
Less code, less bugs Luke.

2006-12-11 Alexis Sukrieh <sukria@backup-manager.org>

* lib/files.sh
+ change a call to mktemp so it's compliant with old versions (mktemp
<path>).
Expand Down
61 changes: 33 additions & 28 deletions lib/backup-methods.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function commit_archive()
debug "commit_archive ($file_to_create)"

# The archive is ok, we can drop the "pending" stuff
debug "rm -f ${bm_pending_incremental_list}.orig"
rm -f "${bm_pending_incremental_list}.orig"
bm_pending_incremental_list=""
bm_pending_archive=""
Expand Down Expand Up @@ -132,43 +133,38 @@ function __exec_meta_command()
logfile=$(mktemp /tmp/bm-command.XXXXXX)

case "$compress" in
"gzip"|"gz")
if [ -x $gzip ]; then

"gzip"|"gz"|"bzip"|"bzip2")
if [ "$compress" = "gzip" ] ||
[ "$compress" = "gz" ]; then
compress=$gzip
ext="gz"
fi
if [ "$compress" = "bzip2" ] ||
[ "$compress" = "bzip" ]; then
compress=$bzip
ext="bz2"
fi

if [ -x $compress ]; then
debug "$command 2>$logfile > $file_to_create"
tail_logfile "$logfile"
$command 2>$logfile > $file_to_create

if [ $? -gt 0 ]; then
warning "Unable to exec \$command; check \$logfile"
rm -f $file_to_create
if [ "$BM_ENCRYPTION_METHOD" = "gpg" ]; then
$command | $compress -f -q -9 | $gpg -r "$BM_ENCRYPTION_RECIPIENT" -e > $file_to_create.$ext.gpg 2> $logfile
debug "$command | $compress -f -q -9 | $gpg -r \"$BM_ENCRYPTION_RECIPIENT\" -e > $file_to_create.$ext.gpg 2> $logfile"
file_to_create="$file_to_create.$ext.gpg"
else
rm -f $logfile
$gzip -f -q -9 "$file_to_create"
file_to_create="$file_to_create.gz"
$command | $compress -f -q -9 > $file_to_create.$ext 2> $logfile
file_to_create="$file_to_create.$ext"
fi
else
error "Compressor \$compress requires \$gzip."
fi
;;
"bzip"|"bzip2")
if [ -x $bzip ]; then

# we cannot pipe the command to gzip here, or $? will _always_ be 0...
debug "$command 2>$logfile > $file_to_create"
tail_logfile "$logfile"
$command 2>$logfile > $file_to_create


if [ $? -gt 0 ]; then
warning "Unable to exec \$command; check \$logfile"
rm -f $file_to_create
else
rm -f $logfile
$bzip -f -q -9 "$file_to_create"
file_to_create="$file_to_create.bz2"
fi
else
error "Compressor \$compress requires \$bzip."
error "Compressor \$compress is needed."
fi
;;
""|"uncompressed"|"none")
Expand All @@ -178,7 +174,12 @@ function __exec_meta_command()

debug "$command 1> $file_to_create 2>$logfile"
tail_logfile "$logfile"
$command 1> $file_to_create 2>$logfile
if [ "$BM_ENCRYPTION_METHOD" = "gpg" ]; then
$command | $gpg -r "$BM_ENCRYPTION_RECIPIENT" -e > $file_to_create.gpg 2> $logfile
file_to_create="$file_to_create.gpg"
else
$command 1> $file_to_create 2>$logfile
fi

if [ $? -gt 0 ]; then
warning "Unable to exec \$command; check \$logfile"
Expand Down Expand Up @@ -354,6 +355,7 @@ function __get_flags_tar_incremental()
incremental_list="$BM_REPOSITORY_ROOT/$BM_ARCHIVE_PREFIX$dir_name.incremental.bin"
bm_pending_incremental_list="$incremental_list"
if [ -e "${incremental_list}" ]; then
debug "cp $incremental_list ${incremental_list}.orig"
cp $incremental_list "${incremental_list}.orig"
fi

Expand Down Expand Up @@ -627,20 +629,23 @@ function __build_local_archive()
file_to_check="$file_to_check.gpg"
fi

bm_pending_archive="${file_to_check}"

# let's exec the command
if [ ! -e "$file_to_check" ] || [ "$force" = "true" ]; then
if [ "$BM_ENCRYPTION_METHOD" = "gpg" ]; then
if [ ! -x $gpg ]; then
error "The program \"\$gpg\" is needed."
fi
bm_pending_archive="${file_to_check}"
build_encrypted_archive
else
bm_pending_archive="${file_to_check}"
build_clear_archive
fi
else
warning "File \$file_to_check already exists, skipping."
debug "rm -f ${bm_pending_incremental_list}.orig"
rm -f "${bm_pending_incremental_list}.orig"
continue
fi
}
Expand Down
7 changes: 7 additions & 0 deletions lib/sanitize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ 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"

# encryption stuff goes here
if [ "$BM_ENCRYPTION_METHOD" = "gpg" ]; then
if [ -z "$BM_ENCRYPTION_RECIPIENT" ]; then
confkey_error "BM_ENCRYPTION_RECIPIENT" "BM_ENCRYPTION_METHOD"
fi
fi

# The TARBALL_OVER_SSH thing
if [ "$BM_TARBALL_OVER_SSH" = "true" ]; then
if [ -z "$BM_UPLOAD_SSH_HOSTS" ]; then
Expand Down
4 changes: 2 additions & 2 deletions t/t11-pipe-method.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
set -e

source testlib.sh
# verbose="true"
# warnings="true"
verbose="true"
warnings="true"

source confs/base.conf

Expand Down
64 changes: 64 additions & 0 deletions t/t11.2-pipe-encrypted.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/sh

set -e

source testlib.sh
verbose="true"
warnings="true"

source confs/base.conf

# taken verbatim from file attached to bug #4
# http://bugzilla.backup-manager.org/cgi-bin/attachment.cgi?id=1&action=view
export BM_REPOSITORY_ROOT="$PWD/repository"
export BM_ARCHIVE_METHOD="pipe"
export BM_ENCRYPTION_METHOD="gpg"
export BM_ENCRYPTION_RECIPIENT="0x1EE5DD34"

source $locallib/sanitize.sh
bm_init_env
bm_init_today

BM_PIPE_COMMAND[0]="cat /etc/passwd"
BM_PIPE_NAME[0]="passwd"
BM_PIPE_FILETYPE[0]="txt"
BM_PIPE_COMPRESS[0]="gzip"
files[0]="$BM_REPOSITORY_ROOT/$BM_ARCHIVE_PREFIX-passwd.$TODAY.txt.gz.gpg"

BM_PIPE_COMMAND[1]="echo 'sukria' ; date "
BM_PIPE_NAME[1]="sukria"
BM_PIPE_FILETYPE[1]="txt"
BM_PIPE_COMPRESS[1]="bzip2"
files[1]="$BM_REPOSITORY_ROOT/$BM_ARCHIVE_PREFIX-sukria.$TODAY.txt.bz2.gpg"

BM_PIPE_COMMAND[2]="ls -lh /"
BM_PIPE_NAME[2]="ls-root"
BM_PIPE_FILETYPE[2]="txt"
BM_PIPE_COMPRESS[2]=""
files[2]="$BM_REPOSITORY_ROOT/$BM_ARCHIVE_PREFIX-ls-root.$TODAY.txt.gpg"

# BM_PIPE_COMMAND[3]="/usr/bin/tototot"
# BM_PIPE_NAME[3]="failure"
# BM_PIPE_FILETYPE[3]="txt"
# BM_PIPE_COMPRESS[3]=""

# clean
if [ -e $PWD/repository ]; then
rm -rf $PWD/repository
fi

# BM actions
create_directories
make_archives

# test of success/failure
for file in $files
do
if [ ! -e $file ]; then
warning "file $file does not exist"
rm -rf $BM_ARCHIVE_ROOT
exit 10
fi
done
rm -rf $BM_ARCHIVE_ROOT
exit 0

0 comments on commit 8fb9045

Please sign in to comment.