From 51b282d82d08b095a3826d44e444464bd2eeaf0a Mon Sep 17 00:00:00 2001 From: MegaBrutal Date: Wed, 2 Sep 2015 22:32:55 +0200 Subject: [PATCH] backup_diff.sh, backup_full.sh: Cleaned up for publication, added rsync transfer mode - Moved hard-coded data to separate config file. - Now it is configurable how to transfer backup files to a remote server: it is possible by scp or rsync, or to not transfer them at all. The backup directory may be mounted from a remote server by NFS or other method, in which case there is no need to transfer the files by scp or rsync. Note however, backup_full.sh purges the backup directory, because it is assumed that the files have already been transferred to a remote location. modified: fs/backup_diff.sh new file: fs/backup_fsdiff.conf modified: fs/backup_full.sh --- fs/backup_diff.sh | 19 +++++++++++++++---- fs/backup_fsdiff.conf | 9 +++++++++ fs/backup_full.sh | 21 +++++++++++++++++---- 3 files changed, 41 insertions(+), 8 deletions(-) mode change 100644 => 100755 fs/backup_diff.sh create mode 100644 fs/backup_fsdiff.conf mode change 100644 => 100755 fs/backup_full.sh diff --git a/fs/backup_diff.sh b/fs/backup_diff.sh old mode 100644 new mode 100755 index 404b5e3..01145bd --- a/fs/backup_diff.sh +++ b/fs/backup_diff.sh @@ -1,4 +1,15 @@ -# PLACEHOLDER FILE! -# This script is not yet ready for publication, as it contains environment-specific and/or hard-coded sensitive data. -# This file is here to annoy myself to make an update. -# ~ MegaBrutal +#!/bin/sh +. $1 +FILENAME=${DIFFNAME}${APPEND} +cd ${STORAGE} +dar --verbose --alter=atime --empty-dir --fs-root / --noconf --create ${STORAGE}${FILENAME} --ref $(ls --sort=t ${STORAGE}*.dar | head -n 1 | cut -d. -f1) -y9 -an --exclude-from-file ${EXCLUDE} +md5sum -b *.dar > $(ls --sort=t ${FULLNAME}*.md5 | head -n 1) + +case "${XFER_METHOD}" in + scp) + su - ${XFER_USER} -c "scp -p ${STORAGE}${FILENAME}* $(ls --sort=t ${STORAGE}${FULLNAME}*.md5 | head -n 1) ${XFER_TARGET}" + ;; + rsync) + su - ${XFER_USER} -c "rsync -auv ${STORAGE} ${XFER_TARGET}" + ;; +esac diff --git a/fs/backup_fsdiff.conf b/fs/backup_fsdiff.conf new file mode 100644 index 0000000..3a3da89 --- /dev/null +++ b/fs/backup_fsdiff.conf @@ -0,0 +1,9 @@ +FULLNAME=filesys_$(hostname -s)_full +DIFFNAME=filesys_$(hostname -s)_diff +APPEND=$(date +%Y%m%d) +STORAGE=/var/backups/fs/data/ +EXCLUDE=/var/backups/fs/exclude.lst + +XFER_METHOD=scp +XFER_USER=backup +XFER_TARGET= diff --git a/fs/backup_full.sh b/fs/backup_full.sh old mode 100644 new mode 100755 index 404b5e3..2967c12 --- a/fs/backup_full.sh +++ b/fs/backup_full.sh @@ -1,4 +1,17 @@ -# PLACEHOLDER FILE! -# This script is not yet ready for publication, as it contains environment-specific and/or hard-coded sensitive data. -# This file is here to annoy myself to make an update. -# ~ MegaBrutal +#!/bin/sh +. $1 +FILENAME=${FULLNAME}${APPEND} +cd ${STORAGE} +rm * +dar --verbose --alter=atime --empty-dir --fs-root / --noconf --create ${STORAGE}${FILENAME} -y9 -an --exclude-from-file ${EXCLUDE} +md5sum -b ${FILENAME}* > ${FILENAME}.md5 +chown ${XFER_USER} ${FILENAME}.md5 + +case "${XFER_METHOD}" in + scp) + su - ${XFER_USER} -c "scp -p ${STORAGE}${FILENAME}* ${XFER_TARGET}" + ;; + rsync) + su - ${XFER_USER} -c "rsync -auv ${STORAGE} ${XFER_TARGET}" + ;; +esac -- 2.34.1