X-Git-Url: http://gitweb.hugovil.com/?a=blobdiff_plain;f=stage2%2Fhv-utilities%2Fhv-backup;h=94ad6d86fb815cb42b9f03f77df994e00cb20c4f;hb=2c652ca09b0c4618e6b859728e838d6d095c7ffc;hp=38a74a8370e5ddf83d678e2599907782572f787b;hpb=16cc35ba4890382ee9368a176e4f5a7fa773b7a6;p=hvlinux.git diff --git a/stage2/hv-utilities/hv-backup b/stage2/hv-utilities/hv-backup index 38a74a8..94ad6d8 100755 --- a/stage2/hv-utilities/hv-backup +++ b/stage2/hv-utilities/hv-backup @@ -1,17 +1,74 @@ -#!/bin/sh +#!/bin/bash -# dvd-backup +# backup +# +# Creates a single compressed archive. -# Load configuration informations about device -. /etc/sysconfig/cdrecord - -export MEDIA_DEV="/dev/dvd" -export MEDIA_DIR="/media/dvd" +if [ ! -f /etc/backup.conf ]; then + echo "Error: missing /etc/backup.conf configuration file." + exit 1 +fi +# Read list of backup files/directories source /etc/backup.conf -export BKP_TMP_DIR +# Set default value if not specified +: ${BKP_DEST_DIR:="./"} + +# Default value +ARCHIVE_LABEL="backup-data-amd64-`date '+%Y-%m-%d'`" + +# Exclude files list +EXC_LIST="/tmp/exclude-sockets" + +print_usage() +{ + echo "$(basename $0) - Backup files/directories." + echo "Usage: $(basename $0) [-h] [--label "label"]" +} + +if [ ${#} -gt 0 ]; then + if [ "x${1}" = "x-h" ]; then + print_usage + exit 0 + fi + if [ "x${1}" = "x--label" ]; then + if [ $# -lt 2 ]; then + echo "Missing arguments for --label option" + print_usage + exit 1 + fi + + ARCHIVE_LABEL=${2} + shift + shift + + if [ $# = 0 ]; then + echo "No directory to backup specified" + print_usage + exit 1 + fi + else + echo "Unknown arguments: ${@}" + print_usage + exit 1 + fi +fi + +ARCHIVE_NAME=${BKP_DEST_DIR}/${ARCHIVE_LABEL}.tar.bz2 + +echo "ARCHIVE_LABEL=$ARCHIVE_LABEL" + +# Finding sockets +find ${DIRECTORIES} -type s > ${EXC_LIST} || exit 1 + +# Archiving +tar jcf ${ARCHIVE_NAME} ${BKP_FILES_LIST} \ + --ignore-failed-read \ + --label="${ARCHIVE_LABEL}" \ + --exclude="*.sock" --exclude="*.lock" --exclude-from=${EXC_LIST} \ + --absolute-names --totals -media-write ${BKP_FILES_LIST} +rm ${EXC_LIST} exit $?