#!/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/hv-backup-exclude-list" 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" cat > ${EXC_LIST} << "EOF" /media/* /proc/* /dev/* /sys/* /tmp/* *.sock *.lock */.gvfs* EOF # Finding sockets, and listing them in the exclude file. # Errors and warnings must be discarded because of .gvfs directory for example. # Even when using -prune option, find exits with a non-zero status when resding # .gvfs find ${BKP_FILES_LIST} -type s >> ${EXC_LIST} 2> /dev/null # Archiving tar jcf ${ARCHIVE_NAME} ${BKP_FILES_LIST} \ --label="${ARCHIVE_LABEL}" \ --ignore-failed-read \ --exclude-backups \ --exclude-caches \ --exclude-from=${EXC_LIST} \ --absolute-names \ --totals rm ${EXC_LIST} exit $?