Mise à jour script de backup pour archiver correctement avec tar.
authorgobo72 <gobo72@364a67c3-989e-7be9-548d-dae8560ea662>
Fri, 23 Sep 2011 01:23:51 +0000 (01:23 +0000)
committergobo72 <gobo72@364a67c3-989e-7be9-548d-dae8560ea662>
Fri, 23 Sep 2011 01:23:51 +0000 (01:23 +0000)
stage2/hv-utilities/backup.conf [new file with mode: 0755]
stage2/hv-utilities/hv-backup
stage2/install-hv-utilities

diff --git a/stage2/hv-utilities/backup.conf b/stage2/hv-utilities/backup.conf
new file mode 100755 (executable)
index 0000000..6fab501
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+# List of files/directories to backup
+BKP_FILES_LIST="/etc /root /srv /usr/local/bin"
+
+# Where to put backup
+BKP_DEST_DIR="/mnt/nas/backup"
index 38a74a8..94ad6d8 100755 (executable)
@@ -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 $?
index bd6a3d3..7aefa4f 100755 (executable)
@@ -6,6 +6,7 @@ SRCDIR="./hv-utilities"
 PREFIX="/usr/local"
 BINDIR="${PREFIX}/bin"
 SYSBINDIR="${PREFIX}/sbin"
+SYSCONFDIR="/etc"
 BIN_UTILITIES="camera-download cd-erase cd-copy cgrep pstopdf distro-backup \
                dos2unix dvd-ram-format fix-avi gztobz2 hv-backup hv-video-dvd \
                mail-files mail-if-fail mail-statistics media-write pstopdf \
@@ -16,6 +17,8 @@ for program in ${BIN_UTILITIES}; do
     install -v ${SRCDIR}/${program} ${BINDIR}
 done
 
+install -v -m 644 ${SRCDIR}/backup.conf ${SYSCONFDIR}
+
 # Install fcrontab for rotatelogs
 echo "# Rotate logs every day at 00:05" > /etc/fcron/fcron.d/rotatelogs
 echo "&mail(false) 05 00 * * * ${BINDIR}/rotatelogs" >> /etc/fcron/fcron.d/rotatelogs