select compression
This commit is contained in:
parent
dc29e9d088
commit
0d2d7a16f4
@ -20,6 +20,9 @@ tmpdir=$(mktemp -d) || exit 1
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# defaults to gzip (none, lzop, gzip, bzip2 are allowed)
|
||||||
|
[ -n "$BACKUP_COMPRESS" ] || BACKUP_COMPRESS="gzip"
|
||||||
|
|
||||||
# log to stderr when debugging
|
# log to stderr when debugging
|
||||||
[ -z "$DEBUG" ] && exec 2>${tmpdir}/msg
|
[ -z "$DEBUG" ] && exec 2>${tmpdir}/msg
|
||||||
|
|
||||||
@ -33,21 +36,55 @@ filestat() {
|
|||||||
stat -c "$format %N" $1 2>/dev/null
|
stat -c "$format %N" $1 2>/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
storage() {
|
storage_filename() {
|
||||||
FILENAME="$1"
|
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
|
# put file in local storage directory and copy it later to remote storage
|
||||||
if [ -n "$LOCAL_STORAGE_PATH" ]; then
|
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
|
echo "$FILENAME: ($(filesize ${LOCAL_STORAGE_PATH}/${FILENAME}))" >&2
|
||||||
|
|
||||||
# copy file only via ssh
|
# copy file only via ssh
|
||||||
elif [ "$REMOTE_STORAGE_TYPE" == "ssh" ]; then
|
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
|
# copy file only via ftp
|
||||||
elif [ "$REMOTE_STORAGE_TYPE" == "ftp" ]; then
|
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
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,6 +145,9 @@ esac
|
|||||||
created_files=""
|
created_files=""
|
||||||
for name in $BACKUPS; do
|
for name in $BACKUPS; do
|
||||||
eval type=\${BACKUP_${name}}
|
eval type=\${BACKUP_${name}}
|
||||||
|
eval comp=\${BACKUP_${name}_COMPRESS}
|
||||||
|
|
||||||
|
[ -n "$comp" ] || comp="$BACKUP_COMPRESS"
|
||||||
|
|
||||||
echo -e "\nBACKUP_$name: (type: ${type})" >&2
|
echo -e "\nBACKUP_$name: (type: ${type})" >&2
|
||||||
|
|
||||||
@ -127,8 +167,8 @@ for name in $BACKUPS; do
|
|||||||
excluded="${excluded} --exclude ${tmp}"
|
excluded="${excluded} --exclude ${tmp}"
|
||||||
done
|
done
|
||||||
|
|
||||||
filename="${BACKUP_PREFIX}.${name}.tar.gz"
|
filename="$(storage_filename ${BACKUP_PREFIX}.${name}.tar $comp)"
|
||||||
[ -n "$files" ] && tar --numeric-owner -C / -czf - $excluded $files | storage $filename
|
[ -n "$files" ] && tar --numeric-owner -C / -cf - $excluded $files | storage_put $filename $comp
|
||||||
;;
|
;;
|
||||||
|
|
||||||
mysql) # mysql dump of some/all tables
|
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"
|
created_mysql_files="$created_mysql_files ${db}-schema.sql ${db}-data.sql"
|
||||||
done
|
done
|
||||||
|
|
||||||
filename="${BACKUP_PREFIX}.${name}.tar.gz"
|
filename="$(storage_filename ${BACKUP_PREFIX}.${name}.tar $comp)"
|
||||||
[ -n "$created_mysql_files" ] && tar -C $tmpdir -czf - $created_mysql_files | storage $filename
|
[ -n "$created_mysql_files" ] && tar -C $tmpdir -cf - $created_mysql_files | storage_put $filename $comp
|
||||||
;;
|
;;
|
||||||
|
|
||||||
ldap) # slapcat of slapd database
|
ldap) # slapcat of slapd database
|
||||||
filename="${BACKUP_PREFIX}.${name}.ldif.gz"
|
filename="$(storage_filename ${BACKUP_PREFIX}.${name}.ldif $comp)"
|
||||||
slapcat | gzip | storage $filename
|
slapcat | storage_put $filename $comp
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*) echo "Invalid backup type: <${type}>" >&2
|
*) echo "Invalid backup type: <${type}>" >&2
|
||||||
|
Loading…
Reference in New Issue
Block a user