select compression

This commit is contained in:
Olaf Rempel 2010-03-13 16:43:02 +01:00
parent dc29e9d088
commit 0d2d7a16f4
1 changed files with 50 additions and 10 deletions

View File

@ -20,6 +20,9 @@ tmpdir=$(mktemp -d) || exit 1
exit 1
}
# defaults to gzip (none, lzop, gzip, bzip2 are allowed)
[ -n "$BACKUP_COMPRESS" ] || BACKUP_COMPRESS="gzip"
# log to stderr when debugging
[ -z "$DEBUG" ] && exec 2>${tmpdir}/msg
@ -33,21 +36,55 @@ filestat() {
stat -c "$format %N" $1 2>/dev/null
}
storage() {
storage_filename() {
FILENAME="$1"
COMPRESS="$2"
case "$COMPRESS" in
none) echo "$FILENAME"
;;
lzop) echo "${FILENAME}.lzo"
;;
bzip2) echo "${FILENAME}.bz2"
;;
*) echo "${FILENAME}.gz"
;;
esac
}
storage_put() {
FILENAME="$1"
COMPRESS="$2"
case "$COMPRESS" in
none) comp_bin="cat"
;;
lzop) comp_bin="lzop -c"
;;
bzip2) comp_bin="bzip2 -c"
;;
*) comp_bin="gzip -c"
;;
esac
# put file in local storage directory and copy it later to remote storage
if [ -n "$LOCAL_STORAGE_PATH" ]; then
cat > ${LOCAL_STORAGE_PATH}/${FILENAME}
$comp_bin > ${LOCAL_STORAGE_PATH}/${FILENAME}
echo "$FILENAME: ($(filesize ${LOCAL_STORAGE_PATH}/${FILENAME}))" >&2
# copy file only via ssh
elif [ "$REMOTE_STORAGE_TYPE" == "ssh" ]; then
ssh $REMOTE_STORAGE_HOST "cat > ${REMOTE_STORAGE_PATH}/${FILENAME}"
$comp_bin | ssh $REMOTE_STORAGE_HOST "cat > ${REMOTE_STORAGE_PATH}/${FILENAME}"
# copy file only via ftp
elif [ "$REMOTE_STORAGE_TYPE" == "ftp" ]; then
ncftpput $ftp_cred -U 0077 -V -c $REMOTE_STORAGE_HOST "${REMOTE_STORAGE_PATH}/${FILENAME}"
$comp_bin | ncftpput $ftp_cred -U 0077 -V -c $REMOTE_STORAGE_HOST "${REMOTE_STORAGE_PATH}/${FILENAME}"
fi
}
@ -108,6 +145,9 @@ esac
created_files=""
for name in $BACKUPS; do
eval type=\${BACKUP_${name}}
eval comp=\${BACKUP_${name}_COMPRESS}
[ -n "$comp" ] || comp="$BACKUP_COMPRESS"
echo -e "\nBACKUP_$name: (type: ${type})" >&2
@ -127,8 +167,8 @@ for name in $BACKUPS; do
excluded="${excluded} --exclude ${tmp}"
done
filename="${BACKUP_PREFIX}.${name}.tar.gz"
[ -n "$files" ] && tar --numeric-owner -C / -czf - $excluded $files | storage $filename
filename="$(storage_filename ${BACKUP_PREFIX}.${name}.tar $comp)"
[ -n "$files" ] && tar --numeric-owner -C / -cf - $excluded $files | storage_put $filename $comp
;;
mysql) # mysql dump of some/all tables
@ -155,13 +195,13 @@ for name in $BACKUPS; do
created_mysql_files="$created_mysql_files ${db}-schema.sql ${db}-data.sql"
done
filename="${BACKUP_PREFIX}.${name}.tar.gz"
[ -n "$created_mysql_files" ] && tar -C $tmpdir -czf - $created_mysql_files | storage $filename
filename="$(storage_filename ${BACKUP_PREFIX}.${name}.tar $comp)"
[ -n "$created_mysql_files" ] && tar -C $tmpdir -cf - $created_mysql_files | storage_put $filename $comp
;;
ldap) # slapcat of slapd database
filename="${BACKUP_PREFIX}.${name}.ldif.gz"
slapcat | gzip | storage $filename
filename="$(storage_filename ${BACKUP_PREFIX}.${name}.ldif $comp)"
slapcat | storage_put $filename $comp
;;
*) echo "Invalid backup type: <${type}>" >&2