#!/bin/bash # backup # # Creates a single compressed archive. 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 # 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 rm ${EXC_LIST} exit $?