Skip to content

Instantly share code, notes, and snippets.

@endreszabo
Created November 14, 2011 19:43
Show Gist options
  • Save endreszabo/1364916 to your computer and use it in GitHub Desktop.
Save endreszabo/1364916 to your computer and use it in GitHub Desktop.
backup script
#!/bin/bash
set -o nounset
DEST=/mnt/backup/l
INCLUDE=/etc/backup-include
EXCLUDE=/etc/backup-exclude
LOGPATH=/var/log
MAX=100m
#if ! mount | grep -q $DEST; then
# echo Nincs mountolva mentes;
# exit;
#fi
[ -d $DEST ] || exit
declare -a retval_map
retval_map=([23]=0 [24]=0);
retval_mapping() {
local retval=$?
test ${retval_map[$retval]+defined} && \
[ -n ${retval_map[$retval]} ] && retval=${retval_map[$retval]};
return $retval
}
DATE=`date "+%Y-%m-%d-%H%M%S"`
rsync \
--sparse \
--xattrs \
--delete \
--archive \
--progress \
--recursive \
--hard-links \
--numeric-ids \
--human-readable \
--one-file-system \
--max-size="${MAX}" \
--files-from="${INCLUDE}" \
--exclude-from="${EXCLUDE}" \
--link-dest="${DEST}/Latest" \
--log-file="${LOGPATH}/backup_${DATE}_log.txt" \
$@ \
/ "$DEST/${DATE}.inProgress"
retval_mapping && \
mv -v "${DEST}/${DATE}.inProgress" "${DEST}/${DATE}" && \
rm -vf "${DEST}/Latest" && \
ln -vs "${DATE}" "${DEST}/Latest"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment